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

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

VPATH = $(top_srcdir)/src

INCDIR_TMP = $(top_builddir)/include

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

CFLAGS = $(CFLAGS_LOCAL) @DEB_CFLAGS@ @CFLAGS@ @CPPFLAGS@ @DL_CFLAGS@ @UTMP_CFLAGS@ \
	-DLIBEXECDIR=\"${libexecdir}\"
LIBS = $(LIBS_LOCAL) @XPG4_LIBS@ @DL_LIBS@ @UTMP_LIBS@

COMOBJ = kik_debug.o kik_map.o kik_args.o kik_mem.o kik_conf.o kik_file.o kik_path.o \
	kik_conf_io.o kik_str.o kik_cycle_index.o kik_langinfo.o kik_time.o kik_locale.o \
	kik_privilege.o kik_unistd.o kik_sig_child.o kik_dialog.o kik_dlfcn.o

DEPOBJ = kik_pty_@PTY_NAME@.o kik_utmp_@UTMP_NAME@.o kik_dlfcn_@DL_LOADER@.o
OBJ = $(COMOBJ) $(DEPOBJ)

INC = $(COMOBJ:.o=.h) kik_slist.h kik_types.h kik_util.h kik_def.h kik_net.h kik_pty.h kik_utmp.h kik_dlfcn.h

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

LIBNAME=libkik
LIBNAME_DEB=libkik_deb
MAJOR = 16
MINOR = 0

SUBDIRS = config util io collection sys i18n


all : $(LIBNAME).la collect-headers

debug :
	$(MAKE) LIBNAME=$(LIBNAME_DEB) $(LIBNAME_DEB).a

install : install-inc install-la

install-inc : $(INCDIR)/kiklib
	cp $(INCDIR_TMP)/kiklib/*.h $(INCDIR)/kiklib

install-la : $(LIBDIR)
	$(LIBTOOL_INSTALL) $(LIBNAME).la $(LIBDIR)

install-ar : $(LIBDIR)
	$(LIBTOOL_INSTALL) $(LIBNAME).a $(LIBDIR)

install-deb :
	$(MAKE) LIBNAME=$(LIBNAME_DEB) $(OVERRIDE_MACROS) install-ar

uninstall:
	rm -rf $(LIBDIR)/*kik.* $(INCDIR)/kiklib

$(INCDIR)/kiklib :
	mkdir -p $(INCDIR)/kiklib

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

$(INCDIR_TMP)/kiklib :
	mkdir -p $(INCDIR_TMP)/kiklib

collect-headers: $(INCDIR_TMP)/kiklib $(INC) kik_config.h
	for file in $(INC) ; do \
		if test -f $${file} ; \
		then cp $${file} $(INCDIR_TMP)/kiklib ; \
		else cp $(top_srcdir)/src/$${file} $(INCDIR_TMP)/kiklib ; \
		fi \
	done
	cp kik_config.h $(INCDIR_TMP)/kiklib
	touch collect-headers

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

.SUFFIXES: .c.o

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

$(LIBNAME).la : $(OBJ)
	$(LIBTOOL_LINK) -o $(LIBNAME).la $(OBJ:.o=.lo) -rpath $(libdir) \
		@NO_UNDEFINED_FLAG@ -version-info $(MAJOR):$(MINOR):0

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

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