top_builddir = ..
top_srcdir = @top_srcdir@
prefix = @prefix@
sysconfdir = @sysconfdir@
exec_prefix = @exec_prefix@
datadir = @datadir@
bindir = @bindir@
libdir = @libdir@
libexecdir = @libexecdir@

CC = @CC@
LIBTOOL = @LIBTOOL@
INSTALL = @INSTALL@

BINDIR = $(DESTDIR)$(bindir)

VPATH = $(top_srcdir)/main

OBJ = daemon.o main_loop.o main.o

LKIK = @LKIK@
LMKF = @LMKF@
LMLTERM = ../mlterm/libmlterm.a ../mlterm/@LMLTERM_CORE@
LXWINDOW = ../xwindow/libxwindow.a
LKIK_DEB = -lkik_deb
LMKF_DEB = -lmkf_deb

# XDATADIR is to avoid conflicting with DATADIR structure in w32api/objidl.h.
CFLAGS = $(CFLAGS_LOCAL) @KIK_CFLAGS@ @MKF_CFLAGS@ @DEB_CFLAGS@ \
	@X_CFLAGS@ @GUI_CFLAGS@ @SSH2_CFLAGS@ @TYPE_CFLAGS@ @CFLAGS@ @CPPFLAGS@ \
	-DSYSCONFDIR=\"$(sysconfdir)\" -I$(top_srcdir)/mlterm \
	-I${top_srcdir}/xwindow -I${top_builddir}/main -I/usr/local/include

LIBS1 = $(LIBS_LOCAL) $(LXWINDOW) $(LMLTERM) $(LMKF) $(LKIK) \
	-L/usr/local/lib -R/usr/local/lib @SSH2_LIBS_FOR_PROG@ @PTHREAD_LIB@

LIBS2_xlib = @IMAGELIB_LIBS@ @DL_LIBS_IM@ @DL_LIBS_SB@ @MATH_LIBS@ @TYPE_LIBS_FOR_PROG@ \
	@X_LIBS@ -lX11 @X_EXTRA_LIBS@
#	@X_LIBS@ @X_PRE_LIBS@ -lX11 @X_EXTRA_LIBS@

LIBS2_fb = @MATH_LIBS@ @DL_LIBS_SB@

LIBS2_win32 = -mwindows -limm32 @SUBSYSTEM@ ../xwindow/winrs.o

LIBS = $(LIBS1) $(LIBS2_@GUI@)

PROG_xlib = mlterm
PROG_win32 = mlterm
PROG_fb = mlterm-fb

INSTALL_OPT = @INSTALL_OPT@

LIBTOOL_CC = $(LIBTOOL) --mode=compile $(CC) $(CFLAGS)
LIBTOOL_LINK = $(LIBTOOL) --mode=link $(CC) @LDFLAGS@
LIBTOOL_INSTALL = $(LIBTOOL) --mode=install $(INSTALL)

all: $(PROG_@GUI@)

debug:
	$(MAKE) LKIK="$(LKIK_DEB)" LMKF="$(LMKF_DEB)" all

$(PROG_@GUI@): $(OBJ) $(LMLTERM) $(LXWINDOW)
	$(LIBTOOL_LINK) -o $(PROG_@GUI@) $(OBJ@XWINDOW_OBJ_SUFFIX@) \
		@DEXPORT@ $(LIBS) @CTL_LIBS_FOR_PROG@

.SUFFIXES: .c .o

.c.o:
	$(LIBTOOL_CC) -c $<

$(BINDIR):
	mkdir -p $(BINDIR)

install : $(BINDIR)
	$(LIBTOOL_INSTALL) $(INSTALL_OPT) $(PROG_@GUI@) $(BINDIR)

uninstall :
	rm -f $(BINDIR)/$(PROG_@GUI@)

wc :
	find . -name "*.[ch]" -a \! -name "test_*" | xargs wc -l

clean:
	rm -rf $(PROG_@GUI@) $(PROG_@GUI@).exe *core $(OBJ) $(OBJ:.o=.lo) .libs

distclean: clean
	rm -f Makefile version.h
