top_builddir = ..
top_srcdir = @top_srcdir@
prefix = @prefix@
exec_prefix = @exec_prefix@
bindir = @bindir@
libdir = @libdir@
libexecdir = @libexecdir@

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

BINDIR = $(DESTDIR)$(bindir)
LIBDIR = $(DESTDIR)$(libdir)

VPATH = $(top_srcdir)/mlterm

# @FRIBIDI_CFLAGS@ and @IND_CFLAGS@ are for NO_DYNAMIC_LOAD_CTL.
CFLAGS = $(CFLAGS_LOCAL) @DEB_CFLAGS@ @KIK_CFLAGS@ @MKF_CFLAGS@ @SSH2_CFLAGS@ \
	@UTMP_CFLAGS@ @FRIBIDI_CFLAGS@ @IND_CFLAGS@ @CTL_CFLAGS@ @VT52_CFLAGS@ \
	@IMAGE_CFLAGS@ @TOOLS_CFLAGS@ @OT_LAYOUT_CFLAGS@ @CFLAGS@ \
	@ML_NORM_CFLAGS@ @CPPFLAGS@ \
	-I/usr/local/include -DLIBEXECDIR=\"$(libexecdir)\" -DBINDIR=\"$(bindir)\" \
	-DLIBDIR=\"$(libdir)\"

OBJ_CORE = ml_char.o ml_str.o ml_line.o ml_model.o ml_ot_layout.o @ML_NORM_OBJ@ @CTL_LOADER_OBJ@
OBJ = ml_char_encoding.o ml_color.o ml_edit.o ml_edit_util.o ml_edit_scroll.o \
	ml_cursor.o ml_logical_visual.o ml_logs.o ml_screen.o ml_shape.o \
	ml_str_parser.o ml_term.o ml_vt100_parser.o ml_term_manager.o \
	ml_bidi.o ml_iscii.o ml_config_menu.o ml_config_proto.o ml_drcs.o \
	ml_pty.o ml_termcap.o ml_line_shape.o cygfile.o @ML_PTY_OBJ@

LIBNAME = libmlterm

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


all : @LMLTERM_CORE@ $(LIBNAME).a

debug : @LMLTERM_CORE@ $(LIBNAME).a

$(LIBNAME).a : $(OBJ)
	$(LIBTOOL_LINK) -o $(LIBNAME).a $(OBJ:.o=.lo)

$(LIBNAME)_core.a : $(OBJ_CORE)
	$(LIBTOOL_LINK) -o $(LIBNAME)_core.a $(OBJ_CORE:.o=.lo)

$(LIBNAME)_core.la : $(OBJ_CORE)
	$(LIBTOOL_LINK) -o $(LIBNAME)_core.la $(OBJ_CORE:.o=.lo) \
	@NO_UNDEFINED_FLAG@ -rpath $(libdir) -avoid-version @LKIK@ $(LIBS)

install : $(LIBDIR)
	if test "`echo @LMLTERM_CORE@|grep .la`" != "" ; then \
		if test "`strings $(libdir)/*mlterm_core*|grep ml_ot_layout_new`" != "" -a \
	                "@OT_LAYOUT_CFLAGS@" = "" ; then \
			echo "libmlterm_core which supports open type layout has been already installed." \
			echo "Do you overwrite it ? [y/n]" ; \
			read in ; \
			if test "$$in" = "y" ; then \
				$(LIBTOOL_INSTALL) @LMLTERM_CORE@ $(LIBDIR) ; \
			fi ; \
		else \
			$(LIBTOOL_INSTALL) @LMLTERM_CORE@ $(LIBDIR) ; \
		fi ; \
	fi

uninstall :
	rm -f $(LIBDIR)/*mlterm_core.*

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

clean :
	rm -rf $(OBJ) $(OBJ:.o=.lo) $(OBJ_CORE) $(OBJ_CORE:.o=.lo) .libs *.a *.la

distclean: clean
	rm -f Makefile

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

.SUFFIXES : .c.o

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

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