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

VPATH = ${top_srcdir}/tool/mlconfig

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

LIBEXECDIR = $(DESTDIR)$(libexecdir)/mlterm
LIBEXECDIR_win32 = $(DESTDIR)$(bindir)

LPOBL = @LPOBL@

# XDATADIR is to avoid conflicting with DATADIR structure in w32api/objidl.h.
CFLAGS = $(CFLAGS_LOCAL) @GTK_CFLAGS@ @IMAGELIB_CFLAGS@ @DEB_CFLAGS@ \
	@POBL_CFLAGS@ @GUI_CFLAGS@ @SSH2_CFLAGS@ @CFLAGS@ @CPPFLAGS@ \
	-I${top_srcdir}/xwindow -I${top_srcdir}/vtemu \
	-I${top_builddir}/common -I${top_srcdir}/common \
	-I${top_srcdir}/inputmethod \
	-I/usr/local/include \
	-DSYSCONFDIR=\"$(sysconfdir)\" -DLOCALEDIR=\"$(datadir)/locale\" \
	-DXDATADIR=\"$(datadir)\" -DLIBDIR=\"$(libdir)\"

LIBS1 = $(LIBS_LOCAL) @INTL_LIBS@ @DL_SELF@ @DL_LIBS_IM@ @GTK_LIBS@

# -lX11 is for http://fedoraproject.org/wiki/Features/ChangeInImplicitDSOLinking
LIBS2_xlib = $(LPOBL) @X_LIBS_FOR_MLCONFIG@

LIBS2_wayland = $(LPOBL) @X_LIBS_FOR_MLCONFIG@

LIBS2_sdl2 = $(LPOBL) @X_LIBS_FOR_MLCONFIG@

# mlconfig is statically linked with libpobl.
# Then it works if installed libpobl.dll is compiled with USE_WIN32API or not.
LIBS2_win32 = -mwindows ${top_builddir}/baselib/src/.libs/libpobl.a

LIBS2_quartz = $(LPOBL)

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

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

PACKAGE = @PACKAGE@
VERSION = @VERSION@

OBJ = main.o mc_combo.o mc_char_encoding.o mc_im.o mc_tabsize.o mc_logsize.o \
	mc_font.o mc_color.o mc_radio.o mc_space.o mc_alpha.o mc_ctl.o \
	mc_sb_view.o mc_wall_pic.o mc_bgtype.o mc_io.o mc_io_pty.o mc_io_file.o \
	mc_pty.o mc_char_width.o mc_flags.o mc_auto_detect.o mc_ratio.o mc_wordsep.o \
	mc_unicode_areas.o mc_geometry.o mc_click.o mc_opentype.o

LPOBL_DEB=-lpobl_deb

all: mlconfig

debug:
	$(MAKE) LPOBL="$(LPOBL_DEB)" all

mlconfig: $(OBJ)
	$(LIBTOOL_LINK) $(OBJ) $(CFLAGS) -o mlconfig $(LIBS)
	# "cd po" must be enclosed by () because it may not return
	# to the $(top_builddir)/tool/mlconfig at the next line.
	if test -f po/Makefile; then (cd po ; $(MAKE) update-gmo); fi
	# if test -f po/Makefile; then cd po ; $(MAKE) update-po; fi

.c.o:
	$(CC) $(DEFS) $(CFLAGS) -c $<

install: $(LIBEXECDIR@WIN32TAG@)
	$(LIBTOOL_INSTALL) -m 755 mlconfig $(LIBEXECDIR@WIN32TAG@)
	if test -f po/Makefile; then (cd po ; $(MAKE) install); fi

uninstall:
	rm -f $(LIBEXECDIR@WIN32TAG@)/mlconfig
	if test -f po/Makefile; then (cd po ; $(MAKE) uninstall); fi

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

clean:
	rm -rf $(OBJ) mlconfig mlconfig.exe *.core .libs
	if test -f po/Makefile; then (cd po ; $(MAKE) clean); fi

distclean: clean
	rm -f Makefile
	if test -f po/Makefile; then (cd po ; $(MAKE) distclean); fi
