# Makefile.in -- Makefile for dict
# Created: Wed Apr 24 14:14:09 1996 by faith@dict.org
# Copyright 1996-2002 Rickard E. Faith (faith@dict.org)
# Copyright 2002-2008 Aleksey Cheusov (vle@gmx.net)
# 
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 1, or (at your option) any
# later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 675 Mass Ave, Cambridge, MA 02139, USA.
# 

# Add a _letter_ if you change the version number and release your own version.
# Numbers are for the original author(s) only.
DICT_VERSION=@DICT_VERSION@

ifneq (,)
This makefile requires GNU Make.
endif

.SUFFIXES:	

srcdir=		@srcdir@
VPATH=		@srcdir@:.
prefix=		@prefix@
subdirs=        @allsubdirs@ # doc -- use rfc2229 instead
exec_prefix=	@exec_prefix@
man1_prefix=	@mandir@/man1
man8_prefix=	@mandir@/man8
bindir=         @bindir@
libdir=         @libdir@
libexecdir=     @libexecdir@
sbindir=        @sbindir@
includedir=     @includedir@
datadir=        @datadir@


DESTDIR=

SHELL=		/bin/sh

USE_PLUGIN=@USE_PLUGIN@
EXEEXT=@EXEEXT@

CONF_DIR=@sysconfdir@
PLUGIN_DIR=${libexecdir}
DICT_DIR=${datadir}

CC=		@CC@
CXX=		@CXX@
CPP=		@CPP@
LIBTOOL=        @LIBTOOL@
INSTALL=	@INSTALL@ -c
INSTALL_PROGRAM=@INSTALL_PROGRAM@ -c
INSTALL_SCRIPT= @INSTALL_SCRIPT@ -c
INSTALL_DATA=	@INSTALL_DATA@ -c
LEX=		@LEX@
YACC=		@YACC@

LEXLIB= 	@LEXLIB@

CFLAGS= @CPPFLAGS@ @DEFS@ @CFLAGS@ -DDICT_PLUGIN_PATH=\"$(PLUGIN_DIR)/\" -DDICT_DICTIONARY_PATH=\"$(DICT_DIR)/\" -DDICT_VERSION=\"$(DICT_VERSION)\" -DDICT_CONFIG_PATH=\"$(CONF_DIR)/\" -I. -I$(srcdir)

LIBMAA=		@LIBMAA@
LIBS=		@LIBS@ ${LIBMAA}
LDFLAGS=        @LDFLAGS@
LIBOBJS=        @LIBOBJS@
EXES=	 	dict dictd dictzip dictfmt

all: $(EXES) $(LIBRARIES)

ifdef USE_PLUGIN

PLUGINS=@PLUGINS@
#dictdplugin_man.la

LIBRARIES=
#libdictdplugin.a
INCLUDES=   dictdplugin.h

all: plugins

.PHONY : samples install.samples uninstall.samples
samples         : dictdplugin_exit.la dictdplugin_popen.la
install.samples : samples
	mkdir -p $(DESTDIR)$(libexecdir) && \
	$(LIBTOOL) --mode=install $(INSTALL) -c dictdplugin_exit.la dictdplugin_popen.la $(DESTDIR)$(libexecdir) && \
	$(INSTALL_SCRIPT) search_man $(DESTDIR)$(libexecdir)

uninstall.samples :
	$(LIBTOOL) --mode=uninstall rm -f $(DESTDIR)$(libexecdir)/search_man.la
	$(LIBTOOL) --mode=uninstall rm -f $(DESTDIR)$(libexecdir)/dictdplugin_exit.la
	$(LIBTOOL) --mode=uninstall rm -f $(DESTDIR)$(libexecdir)/dictdplugin_popen.la

endif

ifdef USE_PLUGIN
SRCHOBJS=       index.o data.o str.o plugin.o #dictdplugin.o 
else
SRCHOBJS=       index.o data.o str.o #dictdplugin.o 
endif

NETOBJS=        daemon.o strategy.o net.o servscan.o servparse.o md5.o
CLIOBJS=        net.o clientscan.o clientparse.o md5.o

TMPS=           servscan.c servparse.c servparse.h \
		clientscan.c clientparse.c clientparse.h

@SET_MAKE@

%.o: %.c
	$(LIBTOOL) --tag=CC --mode=compile $(CC) -c $(CFLAGS) $< -o $@
%.o: %.cpp
	$(LIBTOOL) --tag=CXX --mode=compile $(CXX) -c $(CFLAGS) $< -o $@

%: %.o
	$(LIBTOOL) --tag=CC --mode=link $(CC) -o $@ -static \
		$^ $(OBJS) $(LDFLAGS) -lz ${LIBS}

include $(srcdir)/deps

dictd.o : servparse.h

$(PLUGINS) dictdplugin_popen.la dictdplugin_exit.la : $(LIBOBJS)
#	libdictdplugin.a 

lib%.a : %.o
	$(AR) rc $@ $^

%.la : %.o $(LIBOBJS)
	$(LIBTOOL) --tag=CC --mode=link $(CC) -o $@ -module \
		$(^:.o=.lo) \
		-rpath "${PLUGIN_DIR}" \
		$(LDFLAGS) ${LIBS}

dictdplugin_man.la : data.o str.o heap.o dictdplugin_man.o \
                      plugins_common.o $(LIBOBJS)
	$(LIBTOOL) --tag=CC --mode=link $(CC) -o $@ -module \
		$(^:.o=.lo) \
		-rpath "${PLUGIN_DIR}" \
		$(LDFLAGS) ${LIBS}

dictdplugin_judy.la : data.o str.o heap.o dictdplugin_judy.o \
                      plugins_common.o $(LIBOBJS)
	$(LIBTOOL) --tag=CC --mode=link $(CC) -o $@ -module \
		$(^:.o=.lo) \
		-rpath "${PLUGIN_DIR}" \
		$(LDFLAGS) -lJudy ${LIBS}

dictdplugin_dbi.la : heap.o dictdplugin_dbi.o str.o \
                     plugins_common.o $(LIBOBJS)
	$(LIBTOOL) --tag=CC --mode=link $(CC) -o $@ -module \
		$(^:.o=.lo) \
		-rpath "${PLUGIN_DIR}" \
		$(LDFLAGS) -ldbi ${LIBS}

.PHONY: plugins
plugins: $(PLUGINS)

dict    : $(CLIOBJS) $(LIBOBJS) parse.o
dictd   : $(NETOBJS) $(SRCHOBJS) $(LIBOBJS) parse.o
dictzip : data.o $(LIBOBJS)
dictfmt : str.o $(LIBOBJS)

servscan.c: servscan.l
	$(LEX) $(LFLAGS) $< && mv lex.yy.c $@

servscan.o: servscan.c servparse.o servparse.h

servparse.c servparse.h : servparse.y
	$(YACC) -tdv $<; \
    cmp -s y.tab.h servparse.h || mv y.tab.h servparse.h; \
    cmp -s y.tab.c servparse.c || mv y.tab.c servparse.c; \
    rm -f y.tab.h y.tab.c

servparse.o: servparse.c

clientscan.c: clientscan.l
	$(LEX) $(LFLAGS) -o$@ $<

clientscan.o: clientscan.c clientparse.o clientparse.h

clientparse.c clientparse.h: clientparse.y
	$(YACC) -tdv $<; \
    cmp -s y.tab.h clientparse.h || mv y.tab.h clientparse.h; \
    cmp -s y.tab.c clientparse.c || mv y.tab.c clientparse.c; \
    rm -f y.tab.h y.tab.c

clientparse.o: clientparse.c

.PHONY: install.dict install.dictzip install.dictfmt install.dictd \
        install.libs install.includes install.colorit

install.dict: dict
	mkdir -p $(DESTDIR)$(bindir) && \
        mkdir -p $(DESTDIR)$(man1_prefix) && \
	$(LIBTOOL) --mode=install $(INSTALL_PROGRAM) dict$(EXEEXT) $(DESTDIR)$(bindir)/ && \
	$(INSTALL_DATA) dict.1 $(DESTDIR)$(man1_prefix)/ && \
	$(INSTALL_SCRIPT) dictl $(DESTDIR)$(bindir)/ && \
	$(INSTALL_DATA) dictl.1 $(DESTDIR)$(man1_prefix)/
	$(INSTALL_SCRIPT) @srcdir@/dict_lookup $(DESTDIR)$(bindir)/ && \
	$(INSTALL_DATA) dict_lookup.1 $(DESTDIR)$(man1_prefix)/

install.colorit: colorit
	mkdir -p $(DESTDIR)$(bindir) && \
        mkdir -p $(DESTDIR)$(man1_prefix) && \
	$(INSTALL_SCRIPT) colorit $(DESTDIR)$(bindir) && \
	$(INSTALL_DATA) colorit.1 $(DESTDIR)$(man1_prefix)

install.dictzip: dictzip
	mkdir -p $(DESTDIR)$(bindir) && \
        mkdir -p $(DESTDIR)$(man1_prefix) && \
	$(LIBTOOL) --mode=install $(INSTALL_PROGRAM) dictzip$(EXEEXT) $(DESTDIR)$(bindir) && \
	$(INSTALL_DATA) dictzip.1 $(DESTDIR)$(man1_prefix)/dictzip.1

install.dictfmt: dictfmt dictfmt_index2word dictfmt_index2suffix
	mkdir -p $(DESTDIR)$(bindir) && \
        mkdir -p $(DESTDIR)$(man1_prefix) && \
	$(LIBTOOL) --mode=install $(INSTALL_PROGRAM) dictfmt$(EXEEXT) $(DESTDIR)$(bindir) && \
	$(INSTALL_SCRIPT) dictfmt_index2suffix $(DESTDIR)$(bindir) && \
	$(INSTALL_SCRIPT) dictfmt_index2word $(DESTDIR)$(bindir) && \
	$(INSTALL_SCRIPT) dictunformat $(DESTDIR)$(bindir) && \
	$(INSTALL_DATA) dictfmt.1 $(DESTDIR)$(man1_prefix) && \
	$(INSTALL_DATA) dictfmt_index2word.1 $(DESTDIR)$(man1_prefix) && \
	$(INSTALL_DATA) dictfmt_index2suffix.1 $(DESTDIR)$(man1_prefix) && \
	$(INSTALL_DATA) dictunformat.1 $(DESTDIR)$(man1_prefix)

install.dictd: dictd
	mkdir -p $(DESTDIR)$(sbindir) && \
        mkdir -p $(DESTDIR)$(man8_prefix) && \
	$(LIBTOOL) --mode=install $(INSTALL_PROGRAM) dictd$(EXEEXT) $(DESTDIR)$(sbindir) && \
	$(INSTALL_DATA) dictd.8 $(DESTDIR)$(man8_prefix)/dictd.8

install.libs: $(LIBRARIES)
	if test _$(USE_PLUGIN) != _; then \
	mkdir -p $(DESTDIR)$(libdir) && \
	if test "$(LIBRARIES)"; then \
	$(INSTALL_DATA) $(LIBRARIES) $(DESTDIR)$(libdir); fi fi

install.includes:
	if test _$(USE_PLUGIN) != _; then \
	mkdir -p $(DESTDIR)$(includedir) && \
	if test "$(INCLUDES)"; then \
	   $(INSTALL_DATA) $(addprefix @srcdir@/, $(INCLUDES)) \
	      $(DESTDIR)$(includedir); \
	fi fi

install.plugins:
	if test _$(USE_PLUGIN) != _; then \
	mkdir -p $(DESTDIR)$(libexecdir) && \
	if test "$(PLUGINS)"; then \
	$(LIBTOOL) --mode=install $(INSTALL_DATA) $(PLUGINS) $(DESTDIR)$(PLUGIN_DIR); else true; fi fi

.PHONY: install

install: \
install.dict install.dictzip install.dictd install.dictfmt \
install.libs install.includes install.plugins install.colorit
ifdef USE_PLUGIN
	$(INSTALL_SCRIPT) dictdplugin-config $(DESTDIR)$(bindir)
endif

uninstall.dict:
	$(LIBTOOL) --mode=uninstall rm -f $(DESTDIR)$(bindir)/dict$(EXEEXT)
	rm -f $(DESTDIR)$(man1_prefix)/dict.1
	rm -f $(DESTDIR)$(bindir)/dictl $(DESTDIR)$(man1_prefix)/dictl.1

uninstall.dictzip:
	$(LIBTOOL) --mode=uninstall rm -f $(DESTDIR)$(bindir)/dictzip$(EXEEXT)
	rm -f $(DESTDIR)$(man1_prefix)/dictzip.1

uninstall.dictd:
	$(LIBTOOL) --mode=uninstall rm -f $(DESTDIR)$(sbindir)/dictd$(EXEEXT)
	rm -f $(DESTDIR)$(man8_prefix)/dictd.8

uninstall.dictfmt:
	$(LIBTOOL) --mode=uninstall rm -f $(DESTDIR)$(bindir)/dictfmt$(EXEEXT)
	rm -f $(DESTDIR)$(man1_prefix)/dictfmt.1
	rm -f $(DESTDIR)$(man1_prefix)/dictfmt_index2word.1
	rm -f $(DESTDIR)$(man1_prefix)/dictfmt_index2suffix.1
	rm -f $(DESTDIR)$(man1_prefix)/dictunformat.1
	rm -f $(DESTDIR)$(bindir)/dictfmt_index2suffix
	rm -f $(DESTDIR)$(bindir)/dictfmt_index2word
	rm -f $(DESTDIR)$(bindir)/dictunformat

uninstall.colorit:
	rm -f $(DESTDIR)$(bindir)/colorit $(DESTDIR)$(man1_prefix)/colorit.1

uninstall.includes:
ifdef USE_PLUGIN
	rm -f $(addprefix $(DESTDIR)$(includedir)/, $(INCLUDES))
endif

uninstall.libs:
ifdef USE_PLUGIN
	if test "$(LIBRARIES)"; then \
	  rm -f $(addprefix $(DESTDIR)$(libdir)/, $(LIBRARIES)); \
	else true; fi
endif

uninstall.plugins:
ifdef USE_PLUGIN
	if test "$(PLUGINS)"; then \
	   $(LIBTOOL) --mode=uninstall \
	      rm -f $(addprefix $(DESTDIR)$(libexecdir)/, $(PLUGINS)); \
	fi
endif

.PHONY: uninstall

.PHONY: \
uninstall.dict uninstall.dictzip uninstall.dictfmt uninstall.dictd \
uninstall.libs uninstall.includes uninstall.plugins uninstall.colorit

uninstall: \
uninstall.dict uninstall.dictzip uninstall.dictfmt uninstall.dictd \
uninstall.libs uninstall.includes uninstall.plugins uninstall.colorit
ifdef USE_PLUGIN
	rm -f $(DESTDIR)$(bindir)/dictdplugin-config
endif

.PHONY: ChangeLog
ChangeLog:
	@(echo "***** Making new ChangeLog..."; \
	rm -f ChangeLog; \
	AWK=@AWK@ rcs2log -i 2 -r -d'1996-09-20<' . doc | \
	./exclude_libmaa_logs | \
	sed -e 's,/cvsroot/dict/dictd1/,,g' \
	      -e 's,/cvs/dict/dictd1/,,g' \
	      -e 's,cheusov *<cheusov@[^>]*>,Aleksey Cheusov <vle@gmx.net>,g' \
	      -e 's,faith *<faith@[^>]*>,Rik Faith <faith@dict.org>,g' \
	      -e 's,hilliard...hilliard@.*,Bob Hilliard  <hilliard@debian.org>,g' \
	      -e 's,tek...tek@.*,Julian Squires  <tek@wiw.org>,g' \
              -e 's,\(.*\)<\([^@<>]\+\)@\([^@<>]\+\)>\(.*\),\1<\2 at \3}\4,g' \
	> ChangeLog;)

cvsdist:
	@( CVSROOT=`cat CVS/Root` && \
	export CVSROOT && \
	VERSION=$(DICT_VERSION) && \
	VERSION_CVS=`echo $${VERSION} | tr . -` && \
	export VERSION VERSION_CVS && \
	$(MAKE) ChangeLog && \
	cp ChangeLog /tmp/dictd.ChangeLog.$${VERSION} && \
	echo "***** Exporting files for dictd-$${VERSION}..." && \
	cd /tmp && \
	rm -rf /tmp/dictd-$${VERSION} && \
	cvs export -fd dictd-$${VERSION} -r dictd-$${VERSION_CVS} dictd1 && \
	cd dictd-$${VERSION} && \
	rm -rf libmaa && \
	mv /tmp/dictd.ChangeLog.$${VERSION} ChangeLog && \
	autoheader && autoconf && \
	rm -rf autom4te.cache libmaa/autom4te.cache && \
	chmod -R a+rX,g-w . && \
	cd .. && \
	echo "***** Taring and zipping dictd-$${VERSION}.tar.gz..." && \
	tar cvvf dictd-$${VERSION}.tar dictd-$${VERSION} && \
	gzip -9f dictd-$${VERSION}.tar && \
	echo "***** Done making /tmp/dictd-$${VERSION}.tar.gz")

.PHONY: clean distclean tags
clean:
	-rm -f *.o *.lo *.os *.a *.la *.s *~ core a.out config.log
	-rm -f $(EXES) $(TMPS)
	-rm -f *.log *.aux *.toc *.dvi *.ps
	-rm -f *.cfg *.dtk .inslog tca.map
	-rm -f *.dct *.idx y.output TAGS
	-rm -f *.dict *.index
	-rm -f *.exe *.dll
	-rm -f test/_* test/testdb.t.txt test/log.txt
	-rm -f ChangeLog*

recursive-clean: clean
	@for subdir in `echo $(subdirs)`; do \
		echo making clean in $$subdir; \
		(cd $$subdir && $(MAKE) clean) || exit 1; \
	done

distclean: recursive-clean
	@for subdir in `echo $(subdirs)`; do \
		echo making $@ in $$subdir; \
		(cd $$subdir && $(MAKE) $@) || exit 1; \
	done
	rm -f config.h config.cache config.status stamp-h.in stamp-h
	rm -f Makefile doc/Makefile dictdplugin-config
	rm -f colorit dictl dictunformat
	rm -f test/dictd_test test/dictzip_test
	rm -rf autom4te.cache libmaa/autom4te.cache
	rm -f  dictfmt_index2suffix dictfmt_index2word
	rm -f *.1 *.8

cvsclean: distclean
	rm -f configure libmaa/configure config.h.in libmaa/config.h.in

tags:
	etags *.[ch]

deps:
	for i in *.c *.cpp; do \
      gcc -MM $$i 2>/dev/null; \
   done | awk '{gsub(/ \/[^ ]+/, ""); print}' | \
   sed 's,\(.*[.]\)o,\1o \1os,1' > deps

.PHONY: test
test: $(EXES) $(LIBRARIES)
	cd test && sh dictd_test && sh dictzip_test

# The following is based on the "Automatic Remaking" node in the GNU
# Autoconf documentation:

$(srcdir)/configure: configure.in
	cd $(srcdir) && autoconf

# autoheader might not change config.h.in, so touch a stamp file.
${srcdir}/config.h.in: stamp-h.in
${srcdir}/stamp-h.in: configure.in
	cd ${srcdir} && autoheader
	touch ${srcdir}/stamp-h.in

config.h: stamp-h
stamp-h: config.h.in config.status
	./config.status

Makefile: Makefile.in config.status
	./config.status

config.status: configure
	./config.status --recheck
