# 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.117 2007/03/10 21:29:46 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=1.10.9

ifneq (,)
This makefile requires GNU Make.
endif

.SUFFIXES:	

srcdir=		.

prefix=		
subdirs=         libmaa # doc -- use rfc2229 instead
exec_prefix=	${prefix}
man1_prefix=	${prefix}/man/man1
man8_prefix=	${prefix}/man/man8
bindir=         ${exec_prefix}/bin
libdir=         ${exec_prefix}/lib
libexecdir=     ${exec_prefix}/libexec
sbindir=        ${exec_prefix}/sbin
includedir=     ${prefix}/include
datadir=        ${prefix}/share


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

DESTDIR=

SHELL=		/bin/sh

USE_PLUGIN=2
USE_DICT_ORG=
EXEEXT=

CONF_DIR=${prefix}/etc/
PLUGIN_DIR=${libexecdir}/
DICT_DIR=${datadir}/

CC=		    cc
CPP=		cc -E
AR=         ar
RANLIB=		ranlib
INSTALL=	/usr/bin/install -c -o root -g wheel
INSTALL_PROGRAM=install  -s -o root -g wheel -m 555
INSTALL_SCRIPT= install  -o root -g wheel -m 555
INSTALL_DATA=	install  -o root -g wheel -m 444
LEX=		flex
LEXLIB= 	-lfl
YACC=		bison -y
JUDYLIB=        
DBILIB=         -ldbi

CFLAGS= -I/usr/local/include  -Ilibmaa -DHAVE_CONFIG_H -g -DUSE_PLUGIN  -DDICT_PLUGIN_PATH=\"$(PLUGIN_DIR)\" -DDICT_DICTIONARY_PATH=\"$(DICT_DIR)\" -DDICT_VERSION=\"$(DICT_VERSION)\" -DDICT_CONFIG_PATH=\"$(CONF_DIR)\" -I.

LDFLAGS=        -L/usr/local/lib  -Llibmaa -lmaa  
LIBOBJS=         wcrtomb.$U. wctomb.$U. mbrlen.$U. mbrtowc.$U. mbstowcs.$U. mbtowc.$U. iswspace.$U. iswalnum.$U. towlower.$U. nl_langinfo.$U.
EXES=	 	dict dictd dictzip dictfmt

all: $(EXES) $(LIBRARIES)

ifdef USE_PLUGIN

PLUGINS := 
#dictdplugin_man.la

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

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

LIBRARIES=
#libdictdplugin.a
INCLUDES=   dictdplugin.h

all: plugins

.PHONY : samples install.samples uninstall.samples
samples         : dictdplugin_exit.la dictdplugin_popen.la man_popen.dict
install.samples : samples
	{ \
    mkdir -p $(DESTDIR)$(libexecdir); \
    mkdir -p $(DESTDIR)$(datadir); \
    $(INSTALL_DATA) dictdplugin_exit.la dictdplugin_popen.la $(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.la,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



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

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

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

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

%: %.o
	libtool --mode=link $(CC) -o $@ -static \
		$(filter-out local_regex local_zlib local_libmaa, $^) \
		$(OBJS) $(LDFLAGS) -lz

dictd: dictd.o
	libtool --mode=link $(CC) -o $@ -static \
		$(filter-out local_regex local_zlib local_libmaa, $^) \
		$(DBILIB) $(OBJS) $(LDFLAGS) -lz

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 --mode=link $(CC) -o $@ -static -module \
		$(filter-out local_regex local_zlib local_libmaa, $(^:.o=.lo)) \
		-rpath "${PLUGIN_DIR}" \
		$(LDFLAGS)

dictdplugin_man.la : data.o str.o heap.o dictdplugin_man.o \
                      plugins_common.o $(LIBOBJS)
	libtool --mode=link $(CC) -o $@ -module \
		$(filter-out local_regex local_zlib local_libmaa, $(^:.o=.lo)) \
		-rpath "${PLUGIN_DIR}" \
		$(LDFLAGS)

dictdplugin_judy.la : data.o str.o heap.o dictdplugin_judy.o \
                      plugins_common.o $(LIBOBJS)
	libtool --mode=link $(CC) -o $@ -module \
		$(filter-out local_regex local_zlib local_libmaa, $(^:.o=.lo)) \
		-rpath "${PLUGIN_DIR}" \
		$(LDFLAGS) $(JUDYLIB)

dictdplugin_dbi.la : heap.o dictdplugin_dbi.o str.o \
                     plugins_common.o $(LIBOBJS)
	libtool --mode=link $(CC) -o $@ -module \
		$(filter-out local_regex local_zlib local_libmaa, $(^:.o=.lo)) \
		-rpath "${PLUGIN_DIR}" \
		$(LDFLAGS) $(DBILIB) -ldl

.PHONY: plugins
plugins: $(PLUGINS)

man_popen.dict : dictdplugin-config dictfmt
	PATH=`pwd`:$${PATH}; export PATH;  \
   { \
      echo `./dictdplugin-config --plugindir`'/search_man'; \
      echo "qwertyuioplkjhgfdsazxcvbnm 0987654321QWERTYUIOPLKJHGFDSAZXCVBNM"; \
   } | ./dictfmt_plugin dictdplugin_popen.la -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
	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)/dict.1 && \
	$(INSTALL_SCRIPT) dictl $(DESTDIR)$(bindir) && \
	$(INSTALL_DATA) dictl.1 $(DESTDIR)$(man1_prefix)/dictl.1

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) $(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)$(libexecdir); 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=gawk rcs2log -i 2 -r -d'1996-09-20<' . doc regex zlib libmaa \
	| sed -e 's,/cvsroot/dict/dictd1/,,g' \
	      -e 's,/cvs/dict/dictd1/,,g' \
	      -e 's,cheusov@[^>]*,vle@gmx.net,g' \
	      -e 's,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;)

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 *.la *.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
	-rm -f test/_* test/testdb.t.txt

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

.PHONY: test
test: $(EXES) $(LIBRARIES)
	@cd $(srcdir)/test && sh ./dictd_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
	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


syntax highlighted by Code2HTML, v. 0.9.1