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

VPATH = ${top_srcdir}/tool/mlconfig

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

LIBEXECDIR = $(DESTDIR)$(libexecdir)

LKIK = @LKIK@

# XDATADIR is to avoid conflicting with DATADIR structure in w32api/objidl.h.
CFLAGS = $(CFLAGS_LOCAL) @GTK_CFLAGS@ @IMAGELIB_CFLAGS@ @DEB_CFLAGS@ \
	@KIK_CFLAGS@ @GUI_CFLAGS@ @SSH2_CFLAGS@ @CFLAGS@ @CPPFLAGS@ \
	-I${top_srcdir}/xwindow -I${top_srcdir}/mlterm \
	-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 = $(LKIK) -lX11 -L/usr/local/lib -R/usr/local/lib

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

LIBS2_quartz = $(LKIK)

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_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 @XLFDSEL_OBJ@

LKIK_DEB=-lkik_deb

all: mlconfig

debug:
	$(MAKE) LKIK="$(LKIK_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.
	(cd po ; $(MAKE) update-gmo)
	# cd po ; $(MAKE) update-po

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

install: $(LIBEXECDIR)/mlterm
	$(LIBTOOL_INSTALL) -m 755 mlconfig $(LIBEXECDIR)/mlterm
	cd po ; $(MAKE) install

uninstall:
	rm -f $(LIBEXECDIR)/mlterm/mlconfig
	cd po ; $(MAKE) uninstall

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

clean:
	rm -rf $(OBJ) mlconfig mlconfig.exe *.core .libs
	cd po ; $(MAKE) clean

distclean: clean
	rm -f Makefile
	cd po ; $(MAKE) maintainer-clean
