# Makefile.in -- Makefile for dict
# Created: Wed Apr 24 14:14:09 1996 by faith@dict.org
# Revised: Sat May  4 21:55:59 2002 by faith@dict.org
# Copyright 1996-2002 Rickard E. Faith (faith@dict.org)
# 
# 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.
# 
# $Id: Makefile.in,v 1.103 2004/12/13 19:12:55 cheusov Exp $
#

# 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@


local_regex=    @local_regex@
local_libmaa=   @local_libmaa@
local_zlib=     @local_zlib@

DESTDIR=

SHELL=		/bin/sh

USE_PLUGIN=@USE_PLUGIN@
USE_DICT_ORG=@USE_DICT_ORG@
EXEEXT=@EXEEXT@

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

CC=		    @CC@
CPP=		@CPP@
AR=         @AR@
RANLIB=		@RANLIB@
INSTALL=	@INSTALL@
INSTALL_PROGRAM=@INSTALL_PROGRAM@
INSTALL_SCRIPT= @INSTALL_SCRIPT@
INSTALL_DATA=	@INSTALL_DATA@
LEX=		@LEX@
LEXLIB= 	@LEXLIB@
YACC=		@YACC@
JUDYLIB=        @JUDYLIB@
DBILIB=         @DBILIB@

CFLAGS= @CFLAGS@ -DDICT_PLUGIN_PATH=\"$(PLUGIN_DIR)\" -DDICT_DICTIONARY_PATH=\"$(DICT_DIR)\" -DDICT_VERSION=\"$(DICT_VERSION)\" -DDICT_CONFIG_PATH=\"$(CONF_DIR)\"

SCFLAGS=        @SCFLAGS@
LDFLAGS=        @LDFLAGS@
XTRACFLAGS=     @WCFLAGS@ @XTRACFLAGS@ @DEFS@ @CPPFLAGS@ -I.
XTRALDFLAGS=    @WLDFLAGS@ @XTRALDFLAGS@
LDLIBS=		@LIBS@
LIBOBJS=        @LIBOBJS@
LIBSOBJS=       $(LIBOBJS:.o=.os)
EXES=	 	dict dictd dictzip dictfmt

all: $(EXES) $(LIBRARIES)

ifdef USE_PLUGIN

PLUGINS := 
#dictdplugin_man.so

ifdef JUDYLIB
PLUGINS := $(PLUGINS) dictdplugin_judy.so
endif

ifdef DBILIB
PLUGINS := $(PLUGINS) dictdplugin_dbi.so
endif

LIBRARIES=
#libdictdplugin.a
INCLUDES=   dictdplugin.h

all: plugins

.PHONY : samples install.samples uninstall.samples
samples         : dictdplugin_exit.so dictdplugin_popen.so man_popen.dict
install.samples : samples
	{ \
    if test ! -d $(DESTDIR)$(libexecdir); then $(INSTALL) -d 755 $(DESTDIR)$(libexecdir); fi; \
    if test ! -d $(DESTDIR)$(datadir); then $(INSTALL) -d 755 $(DESTDIR)$(datadir); fi; \
    $(INSTALL_DATA) dictdplugin_exit.so dictdplugin_popen.so $(DESTDIR)$(libexecdir); \
    $(INSTALL_DATA) man_popen.{dict,index} $(DESTDIR)$(datadir); \
    $(INSTALL_SCRIPT) search_man $(DESTDIR)$(libexecdir); \
    } || true

uninstall.samples :
	rm -f $(DESTDIR)$(datadir)/man_popen.{dict,index} $(DESTDIR)$(libexecdir)/{search_man,dictdplugin_exit.so,dictdplugin_popen.so}

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@

ifeq (1,$(local_libmaa))
$(PLUGINS) dictdplugin_popen.so dictdplugin_exit.so $(EXES) : local_libmaa
local_libmaa :
	( cd $(srcdir)/libmaa && $(MAKE) ) && touch local_libmaa
endif

ifeq (1,$(local_regex))
$(PLUGINS) dictdplugin_popen.so dictdplugin_exit.so $(EXES) : local_regex
local_regex :
	( cd $(srcdir)/regex && $(MAKE) CC="$(CC) $(CFLAGS)" lib ) && \
		touch local_regex
endif

ifeq (1,$(local_zlib))
$(PLUGINS) dictdplugin_popen.so dictdplugin_exit.so $(EXES) : local_zlib
local_zlib :
	( cd $(srcdir)/zlib && \
	$(MAKE) CC="$(CC)" CFLAGS="$(CFLAGS)" libz.a ) && \
		touch local_zlib
endif

ALLCFLAGS=$(XTRACFLAGS) $(CFLAGS)
ALLLDFLAGS=$(XTRALDFLAGS) $(LDFLAGS) $(LDLIBS)

%.o: %.c
	$(CC) -c $(ALLCFLAGS) $(SCFLAGS) $< -o $@
%.o: %.cpp
	$(CXX) -c $(ALLCFLAGS) $(SCFLAGS) $< -o $@
%.os: %.c
	$(CC) -fPIC -c $(ALLCFLAGS) $(SCFLAGS) $< -o $@
%.os: %.cpp
	$(CXX) -fPIC -c $(ALLCFLAGS) $(SCFLAGS) $< -o $@

%: %.o
	$(CC) -o $@ $(filter-out local_regex local_zlib local_libmaa, $^) \
		$(OBJS) $(ALLLDFLAGS)

dictd: dictd.o
	$(CC) -o $@ $(filter-out local_regex local_zlib local_libmaa, $^) \
		$(DBILIB) $(OBJS) $(ALLLDFLAGS)

include $(srcdir)/deps

dictd.o : servparse.h

$(PLUGINS) dictdplugin_popen.so dictdplugin_exit.so : $(LIBSOBJS)
#	libdictdplugin.a 

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

%.so : %.os
	$(CC) -o $@ $(filter-out local_regex local_zlib local_libmaa, $^) \
		$(ALLLDFLAGS) -shared

dictdplugin_man.so : data.os str.os heap.os dictdplugin_man.os \
                      plugins_common.os
	$(CC) $(filter-out local_regex local_zlib local_libmaa, $^) \
		 $(ALLLDFLAGS) -shared -o $@

dictdplugin_judy.so : data.os str.os heap.os dictdplugin_judy.os \
                      plugins_common.os
	$(CC) $(filter-out local_regex local_zlib local_libmaa, $^) \
		 $(ALLLDFLAGS) $(JUDYLIB) -shared -o $@

dictdplugin_dbi.so : heap.os dictdplugin_dbi.os str.os \
                     plugins_common.os
	$(CC) $(filter-out local_regex local_zlib local_libmaa, $^) \
		 $(ALLLDFLAGS) $(DBILIB) -ldl -shared -o $@

.PHONY: plugins
plugins: $(PLUGINS)

man_popen.dict : dictdplugin-config dictfmt_plugin dictfmt
	PATH=`pwd`:$${PATH}; export PATH;  \
   { \
      echo `./dictdplugin-config --plugindir`'/search_man'; \
      echo "qwertyuioplkjhgfdsazxcvbnm 0987654321QWERTYUIOPLKJHGFDSAZXCVBNM"; \
   } | ./dictfmt_plugin dictdplugin_popen.so -s \
      'Example man dict based on example POPEN plugin' man_popen

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) -o$@ $<

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
	if test ! -d $(DESTDIR)$(bindir); then \
        $(INSTALL) -d 755 $(DESTDIR)$(bindir); \
    fi; \
	if test ! -d $(DESTDIR)$(man1_prefix); then \
        $(INSTALL) -d 755 $(DESTDIR)$(man1_prefix); \
    fi; \
	$(INSTALL_PROGRAM) dict$(EXEEXT) $(DESTDIR)$(bindir); \
	$(INSTALL_DATA) dict.1 $(DESTDIR)$(man1_prefix)/dict.1; \
	$(INSTALL_SCRIPT) dictl $(DESTDIR)$(bindir); \
	$(INSTALL_DATA) dictl.1 $(DESTDIR)$(man1_prefix)/dictl.1

install.colorit: colorit
	if test ! -d $(DESTDIR)$(bindir); then \
        $(INSTALL) -d 755 $(DESTDIR)$(bindir); \
    fi; \
	if test ! -d $(DESTDIR)$(man1_prefix); then \
        $(INSTALL) -d 755 $(DESTDIR)$(man1_prefix); \
    fi; \
	$(INSTALL_SCRIPT) colorit $(DESTDIR)$(bindir); \
	$(INSTALL_DATA) colorit.1 $(DESTDIR)$(man1_prefix)

install.dictzip: dictzip
	if test ! -d $(DESTDIR)$(bindir); then \
        $(INSTALL) -d 755 $(DESTDIR)$(bindir); \
    fi; \
	if test ! -d $(DESTDIR)$(man1_prefix); then \
        $(INSTALL) -d 755 $(DESTDIR)$(man1_prefix); \
    fi; \
	$(INSTALL_PROGRAM) dictzip$(EXEEXT) $(DESTDIR)$(bindir); \
	$(INSTALL_DATA) dictzip.1 $(DESTDIR)$(man1_prefix)/dictzip.1

install.dictfmt: dictfmt dictfmt_index2word dictfmt_index2suffix dictfmt_plugin
	if test ! -d $(DESTDIR)$(bindir); then \
        $(INSTALL) -d 755 $(DESTDIR)$(bindir); \
    fi; \
	if test ! -d $(DESTDIR)$(man1_prefix); then \
        $(INSTALL) -d 755 $(DESTDIR)$(man1_prefix); \
    fi; \
	$(INSTALL_PROGRAM) dictfmt$(EXEEXT) $(DESTDIR)$(bindir); \
	$(INSTALL_SCRIPT) dictfmt_index2suffix $(DESTDIR)$(bindir); \
	$(INSTALL_SCRIPT) dictfmt_index2word $(DESTDIR)$(bindir); \
	$(INSTALL_SCRIPT) dictfmt_virtual $(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); \
	test _$(USE_PLUGIN) != _ && \
	    $(INSTALL_SCRIPT) dictfmt_plugin $(DESTDIR)$(bindir) || true

install.dictd: dictd
	if test ! -d $(DESTDIR)$(sbindir); then \
        $(INSTALL) -d 755 $(DESTDIR)$(sbindir); \
    fi; \
	if test ! -d $(DESTDIR)$(man8_prefix); then \
        $(INSTALL) -d 755 $(DESTDIR)$(man8_prefix); \
    fi; \
	$(INSTALL_PROGRAM) dictd$(EXEEXT) $(DESTDIR)$(sbindir); \
	$(INSTALL_DATA) dictd.8 $(DESTDIR)$(man8_prefix)/dictd.8

install.libs: $(LIBRARIES)
	test _$(USE_PLUGIN) != _ && \
	{ if test ! -d $(DESTDIR)$(libdir); then $(INSTALL) -d 755 $(DESTDIR)$(libdir); fi; \
	$(INSTALL_DATA) $(LIBRARIES) $(DESTDIR)$(libdir); } || true

install.includes:
	test _$(USE_PLUGIN) != _ && \
	{ if test ! -d $(DESTDIR)$(includedir); then $(INSTALL) -d 755 $(DESTDIR)$(includedir); fi; \
    $(INSTALL_DATA) $(INCLUDES) $(DESTDIR)$(includedir); } || true

install.plugins:
	test _$(USE_PLUGIN) != _ && \
	{ if test ! -d $(DESTDIR)$(libexecdir); then $(INSTALL) -d 755 $(DESTDIR)$(libexecdir); fi; \
    test $(PLUGINS) && \
        $(INSTALL_DATA) $(PLUGINS) $(DESTDIR)$(libexecdir); } || true

.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

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

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

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

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

uninstall.dictfmt:
	rm -f $(DESTDIR)$(bindir)/dictfmt$(EXEEXT) $(DESTDIR)$(man1_prefix)/dictfmt.1 \
    $(DESTDIR)$(man1_prefix)/dictfmt_index2word.1 \
    $(DESTDIR)$(man1_prefix)/dictfmt_index2suffix.1 \
    $(DESTDIR)$(man1_prefix)/dictunformat.1 \
	$(DESTDIR)$(bindir)/dictfmt_index2suffix \
	$(DESTDIR)$(bindir)/dictfmt_index2word \
	$(DESTDIR)$(bindir)/dictfmt_virtual \
	$(DESTDIR)$(bindir)/dictunformat; \
	test _$(USE_PLUGIN) != _ && \
		rm -f $(DESTDIR)$(bindir)/dictfmt_plugin || true

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
	rm -f $(addprefix $(DESTDIR)$(libdir)/, $(LIBRARIES))
endif

uninstall.plugins:
ifdef USE_PLUGIN
	rm -f $(addprefix $(DESTDIR)$(libexecdir)/, $(PLUGINS))
endif

.PHONY: uninstall

uninstall: \
uninstall.dict uninstall.dictd uninstall.dictfmt uninstall.dictzip \
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 regex zlib libmaa \
	| sed 's,/cvsroot/dict/dictd1/,,g; \
	       s,/cvs/dict/dictd1/,,g;\
	       s,cheusov@[^>]*,vle@gmx.net,g;\
	       s,faith@[^>]*,faith@dict.org,g;\
	       s,hilliard...hilliard@.*,Bob Hilliard  <hilliard@debian.org>,g; \
	       s,tek...tek@.*,Julian Squires  <tek@wiw.org>,g; \
           s,\(.*\)<\([^@<>]\+\)@\([^@<>]\+\)>\(.*\),\1<\2 at \3}\4,g' \
	> ChangeLog;)

dist:
	@( 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} && \
	mv /tmp/dictd.ChangeLog.$${VERSION} ChangeLog && \
	make -f Makefile.conf && \
	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 *.os *.a *.so *.s *~ core a.out config.log $(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

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 \
	 	if [ "$$subdir" != "zlib" ]; then \
			if [ "$$subdir" = "regex" ]; then \
				echo making clean in $$subdir; \
				(cd $$subdir && $(MAKE) clean) || exit 1; \
			else \
				echo making $@ in $$subdir; \
				(cd $$subdir && $(MAKE) $@) || exit 1; \
			fi \
		fi \
	done; \
	rm -f regex/regex.h; \
	rm -f config.h config.cache config.status stamp-h.in stamp-h; \
	rm -f Makefile doc/Makefile dictdplugin-config include_regex.h
	rm -f local_* colorit dictl
	rm -rf autom4te.cache libmaa/autom4te.cache

cvsclean: distclean
	rm -f configure libmaa/configure

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

# 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
	date > ${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

