#
# $Id: Makefile.in,v 1.16 2000/12/27 04:10:39 marc Exp $
# 
# Copyright (c) 1996, 1997, 1998, 1999, Marc Horowitz.  All rights reserved.
# See the LICENSE file in the release for redistribution information.

all::

SHELL = /bin/sh

## this does recursion for db2, if it's in the tree

SUBDIRS = db2-sleepycat/dist

depend all install check clean distclean maintainer-clean::
	for i in ${SUBDIRS}; do (test -d $$i && cd $$i && ${MAKE} $@) || exit 1; done

## this builds the keyserver

ALL = pksclient pksd pksdctl pgpsplit
ALL_PURE = pksclient.pure pksd.pure
ALL_SH = pks-mail.sh pks-queue-run.sh

SYSCONF = pksd.conf
DATA = mail_intro pks_help.en
MAN5 = pksd.conf.5
MAN8 = pks-intro.8 pksclient.8 pksd.8 pksdctl.8

UTILS = pksmailreq wwwtest pgpdump kvcv kxa pkscheck pksdump pksstripbad

all:: $(ALL) $(SYSCONF)
all-pure:: $(ALL_PURE)
all-utils:: $(UTILS)

DBDIR = db2-sleepycat/dist

CC = @CC@
INSTALL = @INSTALL@
INSTALL_PROGRAM = $(INSTALL)
INSTALL_DATA = $(INSTALL)
SOCKLIBS = @LIBS@
VPATH = @srcdir@

srcdir = @srcdir@
prefix = @prefix@
exec_prefix = @exec_prefix@

bindir = @bindir@
datadir = @datadir@
sysconfdir = @sysconfdir@
localstatedir = @localstatedir@
man5dir = @mandir@/man5
man8dir = @mandir@/man8

MKDEP = makedepend
PURIFY = purify

INCLUDES = -I$(DBDIR)
DBG = -DDEBUG
DEFINES = $(DBG) @DEFS@
CFLAGS = @gcc_cflags@ -g -O $(INCLUDES) $(DEFINES)

LIBDB = $(DBDIR)/libdb.a

CLEAN = rm -f

PKSOBJS = pks_www.o pks_socket.o
WWWOBJS = www.o
MAILOBJS = mail_req.o mail_send.o
INCROBJS = pks_incr.o
DBOBJS = kd_add.o kd_delete.o kd_disable.o kd_generic.o kd_get.o kd_index.o \
	kd_search.o kd_since.o kd_types.o
PGPOBJS = pgputil.o md5c.o armor.o pgpcrc.o shs.o
MPOBJS = kd_signal.o multiplex.o mp_signal.o
MISCOBJS = parse.o llist.o globals.o logging.o
UTILOBJS = util.o

# portable make doesn't do $^.  So I get to use a new variable
# for each program.  sigh.

O1 = pksclient.o $(DBOBJS) $(PGPOBJS) $(MISCOBJS) $(UTILOBJS)
pksclient: $(O1)
	$(CC) -o $@ $(O1) $(LDFLAGS) $(LIBDB)

pksclient.pure: $(O1) 
	$(PURIFY) $(CC) -o $@ $(O1) $(LDFLAGS) $(LIBDB)

O3 = pksd.o pks_config.o $(PKSOBJS) $(WWWOBJS) $(MAILOBJS) \
	$(INCROBJS) $(DBOBJS) $(PGPOBJS) $(MPOBJS) $(MISCOBJS) $(UTILOBJS)
pksd: $(O3)
	$(CC) -o $@ $(O3) $(LDFLAGS) $(SOCKLIBS) $(LIBDB)

pksd.pure: $(O3)
	$(PURIFY) $(CC) -o $@ $(O3) $(LDFLAGS) $(SOCKLIBS) $(LIBDB)

O5 = pksdctl.o
pksdctl: $(O5)
	$(CC) -o $@ $(O5) $(LDFLAGS) $(SOCKLIBS)


O6 = pksmailreq.o $(MAILOBJS) $(INCROBJS) \
	$(DBOBJS) $(PGPOBJS) $(MPOBJS) $(MISCOBJS) $(UTILOBJS)
pksmailreq: $(O6)
	$(CC) -o $@ $(O6) $(LDFLAGS) $(LIBDB)

O7 = pkscheck.o $(DBOBJS) $(PGPOBJS) $(UTILOBJS) $(MISCOBJS)
pkscheck: $(O7)
	$(CC) -o $@ $(O7) $(LDFLAGS) $(LIBDB)

O8 = pksdump.o $(DBOBJS) $(PGPOBJS) $(UTILOBJS) $(MISCOBJS)
pksdump: $(O8)
	$(CC) -o $@ $(O8) $(LDFLAGS) $(LIBDB)

O9 = wwwtest.o $(WWWOBJS) $(MPOBJS) $(MISCOBJS) $(UTILOBJS)
wwwtest: $(O9)
	$(CC) -o $@ $(O9) $(LDFLAGS) $(SOCKLIBS) $(LIBDB)

O10 = pksstripbad.o $(DBOBJS) $(PGPOBJS) $(MISCOBJS) $(UTILOBJS)
pksstripbad: $(O10)
	$(CC) -o $@ $(O10) $(LDFLAGS) $(SOCKLIBS) $(LIBDB)

pgpdump: pgpdump.o pgpfile.o $(PGPOBJS) $(UTILOBJS)

pgpsplit: pgpsplit.o $(PGPOBJS) $(UTILOBJS)

kvcv: kvcv.o pgpfile.o $(PGPOBJS) $(UTILOBJS)

kxa: kxa.o pgpfile.o $(PGPOBJS) $(UTILOBJS)

pksd.conf: mkpksdconf
	sh mkpksdconf > pksd.conf

depend::
	$(MKDEP) -- $(CFLAGS) -- *.c

check::

installdirs::
	-mkdir -p $(bindir) $(datadir) $(sysconfdir) $(man5dir) $(man8dir)
	-mkdir -p $(localstatedir)/db $(localstatedir)/incoming

install:: all installdirs
	for f in $(ALL); do $(INSTALL_PROGRAM) $$f $(bindir); done
	for f in $(SYSCONF); do $(INSTALL_DATA) $$f $(sysconfdir); done
	for f in $(ALL_SH); do $(INSTALL_PROGRAM) $(srcdir)/$$f $(bindir); done
	for f in $(DATA); do $(INSTALL_DATA) $(srcdir)/$$f $(datadir); done
	for f in $(MAN5); do $(INSTALL_DATA) $(srcdir)/$$f $(man5dir); done
	for f in $(MAN8); do $(INSTALL_DATA) $(srcdir)/$$f $(man8dir); done

install-utils:: all-utils installdirs
	for f in $(UTILS); do $(INSTALL_PROGRAM) $$f $(bindir); done

clean::
	$(CLEAN) $(ALL) $(SYSCONF) $(ALL_PURE) $(UTILS) *.o *~

distclean:: clean
	rm -rf config.status config.log config.cache Makefile mkpksdconf

maintainer-clean:: distclean
	rm -rf configure
# DO NOT DELETE THIS LINE -- make depend depends on it.
