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@

LIBDIR = $(DESTDIR)$(libdir)/mlterm

VPATH = $(top_srcdir)/xwindow/libtype

XFT_OBJ = x_window_xft.o x_font_xft.o x_functbl_xft.o
CAIRO_OBJ = x_window_cairo.o x_font_cairo.o x_functbl_cairo.o
NODL_OBJ = @NODL_OBJ@ x_font_ft.o

LKIK = ${top_builddir}/kiklib/src/libkik.la
LKIK_DEB = -lkik_deb

# XDATADIR is to avoid conflicting with DATADIR structure in w32api/objidl.h.
CFLAGS = $(CFLAGS_LOCAL) @KIK_CFLAGS@ @MKF_CFLAGS@ @DEB_CFLAGS@ @X_CFLAGS@ @XFT_CFLAGS@ \
	@CAIRO_CFLAGS@ @TYPE_CFLAGS@ @OT_LAYOUT_CFLAGS@ @CFLAGS@ @CPPFLAGS@ \
	-DLIBDIR=\"$(libdir)\" \
	-I/usr/local/include -I${top_srcdir}/mlterm -I${top_srcdir}/xwindow/libotl

XFT_LIBS = @XFT_LIBS@
CAIRO_LIBS = @CAIRO_LIBS@
LIBS = $(LIBS_LOCAL) $(LKIK) -L/usr/local/lib -R/usr/local/lib

INSTALL_OPT = -m 755

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

TYPE_LIBS = @TYPE_LIBS@

all: $(TYPE_LIBS)

libtype_xft.la: $(XFT_OBJ)
	$(LIBTOOL_LINK) -o libtype_xft.la $(XFT_OBJ:.o=.lo) \
	-rpath $(libdir)/mlterm \
	-module -avoid-version @NO_UNDEFINED_FLAG@ @DEXPORT@ \
	$(LIBS) $(XFT_LIBS)

libtype_cairo.la: $(CAIRO_OBJ)
	$(LIBTOOL_LINK) -o libtype_cairo.la $(CAIRO_OBJ:.o=.lo) \
	-rpath $(libdir)/mlterm \
	-module -avoid-version @NO_UNDEFINED_FLAG@ @DEXPORT@ \
	$(LIBS) $(CAIRO_LIBS)

libtype.a: $(NODL_OBJ)
	$(LIBTOOL_LINK) -o libtype.a $(NODL_OBJ:.o=.lo)

x_font_ft.o: x_font_ft.c
	$(LIBTOOL_CC) @TYPE_CFLAGS@ -c $<

.SUFFIXES: .c .o

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

install : $(LIBDIR)
	if test "$(TYPE_LIBS)" != "" ; then \
		$(LIBTOOL_INSTALL) $(INSTALL_OPT) $(TYPE_LIBS) $(LIBDIR) ; \
	fi

uninstall :
	rm -f $(LIBDIR)/*type_*

$(LIBDIR) :
	mkdir -p $(LIBDIR)

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

clean:
	rm -rf $(TYPE_LIBS) $(XFT_OBJ) $(XFT_OBJ:.o=.lo) \
		$(CAIRO_OBJ) $(CAIRO_OBJ:.o=.lo) x_font_ft.o x_font_ft.lo .libs

distclean: clean
	rm -f Makefile

libfc_wrapper.la: fc_wrapper.o
	$(LIBTOOL_LINK) -o libfc_wrapper.la fc_wrapper.lo -rpath $(libdir)/mlterm \
	-module -avoid-version `pkg-config freetype2 --libs`

install_fc_wrapper : $(LIBDIR)
	$(LIBTOOL_INSTALL) $(INSTALL_OPT) libfc_wrapper.la $(LIBDIR)
