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

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

LIBDIR = $(DESTDIR)$(libdir)
INCDIR = $(DESTDIR)$(prefix)/include
LIBEXECDIR = $(libexecdir)

VPATH = $(top_srcdir)/libind

CFLAGS = $(CFLAGS_LOCAL) @CFLAGS@ @CPPFLAGS@ -I$(top_srcdir)/libind \
	-I/usr/local/include -DLIBDIR=\"$(LIBDIR)\"
LIBS = $(LIBS_LOCAL)

OBJ = indian.o keyboard.o lex.split.o
TBL_OBJ = libind_assamese.o libind_bengali.o libind_gujarati.o libind_hindi.o \
	libind_iitkeyb.o libind_inscript.o libind_kannada.o libind_malayalam.o \
	libind_oriya.o libind_punjabi.o libind_telugu.o #libind_tamil.o

LIBNAME = libind
MAJOR = 0
MINOR = 0

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


all : $(LIBNAME).a $(TBL_OBJ) $(TBL_OBJ:.o=.la) collect-headers

debug : $(LIBNAME).a

.SUFFIXES : .la .o .c

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

.o.la :
	$(LIBTOOL_LINK)	-o $@ $(<:.o=.lo) -rpath $(LIBDIR) \
		-module -avoid-version @NO_UNDEFINED_FLAG@ $(LIBS)

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

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

distclean: clean
	rm -f Makefile
	if test "$(top_builddir)" != "$(top_srcdir)" ; then \
		rm -f indian.h ; \
	fi

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

lex.split.c :
	lex -Psplit $(top_srcdir)/libind/syllable.lex
	# Note that lex doesn't necessarily support -P option. 
	# So lex.split.c is generated by lex in advance and added to source tree.

collect-headers:
	if test "$(top_builddir)" != "$(top_srcdir)" ; then \
		cp $(top_srcdir)/libind/indian.h $(top_builddir)/libind/ ;\
	fi

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

install: $(LIBDIR)/mlterm
	$(LIBTOOL_INSTALL) *.la $(LIBDIR)/mlterm

uninstall:
	rm -f $(LIBDIR)/mlterm/libind_*
