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@

LIBEXECDIR = $(DESTDIR)$(libexecdir)

VPATH = $(top_srcdir)/tool/mlimgloader

OBJ = @MLIMGLOADER_LIB@.o

LKIK = @LKIK@
LKIK_DEB = -lkik_deb

CFLAGS1 = $(CFLAGS_LOCAL) @KIK_CFLAGS@ @DEB_CFLAGS@ @GUI_CFLAGS@ @CFLAGS@ @CPPFLAGS@ -I/usr/local/include

CFLAGS2_gdk-pixbuf = @GDK_PIXBUF_CFLAGS@ @X_CFLAGS@

CFLAGS = $(CFLAGS1) $(CFLAGS2_@MLIMGLOADER_LIB@) -DLIBEXECDIR=\"$(libexecdir)\" \
	-DBINDIR=\"$(bindir)\"

LIBS1 = $(LIBS_LOCAL) $(LKIK) -L/usr/local/lib -R/usr/local/lib

LIBS2_xlib_gdk-pixbuf = @X_LIBS@ -lX11 @X_EXTRA_LIBS@ @GDK_PIXBUF_LIBS@
LIBS2_xlib_gdiplus = $(LIBS2_win32_gdiplus)
LIBS2_fb_gdk-pixbuf = $(LIBS2_xlib_gdk-pixbuf)
LIBS2_console_gdk-pixbuf = $(LIBS2_xlib_gdk-pixbuf)

# Segfault in cygwin without them.
LIBS2_win32_gdk-pixbuf = -mwindows @GDK_PIXBUF_LIBS@
LIBS2_win32_gdiplus = -mwindows -lgdiplus -lstdc++ -lole32
LIBS2_win32_none = -mwindows

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

PROG = mlimgloader

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

all: $(PROG)

$(PROG): $(OBJ)
	$(LIBTOOL_LINK) $(CFLAGS) -o $(PROG) $(OBJ:.o=.lo) $(LIBS)

.SUFFIXES: .c .o

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

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

$(LIBEXECDIR)/mlterm:
	mkdir -p $(LIBEXECDIR)/mlterm

install: $(LIBEXECDIR)/mlterm
	$(LIBTOOL_INSTALL) $(PROG) $(LIBEXECDIR)/mlterm

uninstall:
	rm -f $(LIBEXECDIR)/mlterm/$(PROG)

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

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

distclean: clean
	rm -f Makefile
