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)/mlterm
LIBEXECDIR_win32 = $(DESTDIR)$(bindir)

VPATH = $(top_srcdir)/tool/mlimgloader

OBJ = @MLIMGLOADER_LIB@.o

LPOBL = @LPOBL@
LPOBL_DEB = -lpobl_deb

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

CFLAGS2_gdk-pixbuf = @GDK_PIXBUF_CFLAGS@ @X_CFLAGS@ @X_CFLAGS_AUX@ @EMOJI_CFLAGS@
CFLAGS2_libpng = @LIBPNG_CFLAGS@ @X_CFLAGS@ @X_CFLAGS_AUX@ @EMOJI_CFLAGS@

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

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

LIBS2_xlib_gdk-pixbuf = @X_LIBS@ @X_EXTRA_LIBS@ @GDK_PIXBUF_LIBS@ @EMOJI_LIBS@
LIBS2_xlib_libpng = @X_LIBS@ @X_EXTRA_LIBS@ @LIBPNG_LIBS@ @EMOJI_LIBS@
LIBS2_xlib_gdiplus = $(LIBS2_win32_gdiplus)
LIBS2_fb_gdk-pixbuf = $(LIBS2_xlib_gdk-pixbuf)
LIBS2_fb_libpng = $(LIBS2_xlib_libpng)
LIBS2_console_gdk-pixbuf = $(LIBS2_xlib_gdk-pixbuf)
LIBS2_console_libpng = $(LIBS2_xlib_libpng)
LIBS2_wayland_gdk-pixbuf = $(LIBS2_xlib_gdk-pixbuf)
LIBS2_wayland_libpng = $(LIBS2_xlib_libpng)
LIBS2_sdl2_gdiplus = $(LIBS2_win32_gdiplus)
LIBS2_sdl2_libpng = $(LIBS2_xlib_libpng)
LIBS2_sdl2_gdk-pixbuf = $(LIBS2_xlib_gdk-pixbuf)
LIBS2_beos_gdk-pixbuf = $(LIBS2_xlib_gdk-pixbuf)
LIBS2_beos_libpng = $(LIBS2_xlib_libpng)
LIBS2_quartz_gdk-pixbuf = $(LIBS2_xlib_gdk-pixbuf)
LIBS2_quartz_libpng = $(LIBS2_xlib_libpng)

# 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)

png: libpng.o
	$(LIBTOOL_LINK) $(CFLAGS) -o $(PROG) libpng.lo $(LIBS1) $(LIBS2_@GUI@_libpng) -lpng

.SUFFIXES: .c .o

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

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

$(LIBEXECDIR@WIN32TAG@):
	mkdir -p $(LIBEXECDIR@WIN32TAG@)

install: $(LIBEXECDIR@WIN32TAG@)
	$(LIBTOOL_INSTALL) $(PROG) $(LIBEXECDIR@WIN32TAG@)

uninstall:
	rm -f $(LIBEXECDIR@WIN32TAG@)/$(PROG)

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

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

distclean: clean
	rm -f Makefile
