#
#  Makefile for the database manipulation source directory 
#
#  Makefile.in,v 1.23 1995/11/16 19:26:29 duane Exp
#
SUBDIRS		= gdbmutil

prefix = @prefix@
INSTALL_BINDIR	= $(prefix)/bin
INSTALL_LIBDIR	= $(prefix)/lib
INSTALL_UTILDIR	= $(INSTALL_LIBDIR)/gatherer
INSTALL_MANDIR	= $(prefix)/man

CC		= @CC@
INSTALL		= @INSTALL@
INSTALL_BIN	= @INSTALL_PROGRAM@
INSTALL_FILE	= @INSTALL_DATA@
RANLIB		= @RANLIB@
XTRA_LIBS	= @XTRA_LIBS@

GDBM_DEFINE	=
GDBM_INCLUDE	= 
GDBM_LDFLAGS	= 
GDBM_LIBS	= -lgdbm

DEBUG		= $(DEBUG_TOP) #-O #-g #-DDEBUG
DEBUG_LDFLAGS	=
DEBUG_LIBS	= 
DEFINES		=

LIBDIR		= ../../common/lib
INCLUDE		= -I../../common/include $(GDBM_INCLUDE)
LDFLAGS		= -L$(LIBDIR) $(GDBM_LDFLAGS)
LIBS		= -ltemplate -lutil $(GDBM_LIBS) $(DEBUG_LIBS) $(XTRA_LIBS)

CFLAGS		= $(DEBUG) $(DEFINES) $(INCLUDE) $(GDBM_DEFINE)

PROGS		= mergedb template2db rmbinary consoldb cleandb expiredb
SCRIPTS		= folddb mkgathererstats.pl

all:	$(PROGS) $(SCRIPTS)
	@for dir in $(SUBDIRS); do \
		echo Making $@ in $$dir; \
		(cd $$dir; $(MAKE) $(MFLAGS) \
			INSTALL_BINDIR="$(INSTALL_BINDIR)" \
			INSTALL_LIBDIR="$(INSTALL_LIBDIR)" \
			INSTALL_UTILDIR="$(INSTALL_UTILDIR)" \
			INSTALL_MANDIR="$(INSTALL_MANDIR)" \
			RANLIB="$(RANLIB)" \
			INSTALL_BIN="$(INSTALL_BIN)" \
			INSTALL_FILE="$(INSTALL_FILE)" \
			DEBUG="$(DEBUG)" \
			DEBUG_TOP="$(DEBUG_TOP)" \
			DEBUG_LIBS="$(DEBUG_LIBS)" \
			INSTALLDIR="$(INSTALL_BINDIR)" \
			INSTALL_SCRIPT="$(INSTALL_SCRIPT)" $@); \
	done

ctags:
	@ctags -w *.c

clean:
	-rm -f core $(PROGS) *.o tags mon.out Makefile.bak
	@for dir in $(SUBDIRS); do \
		echo Making $@ in $$dir; \
		(cd $$dir; $(MAKE) $(MFLAGS) \
			INSTALL_BINDIR="$(INSTALL_BINDIR)" \
			INSTALL_LIBDIR="$(INSTALL_LIBDIR)" \
			INSTALL_MANDIR="$(INSTALL_MANDIR)" \
			RANLIB="$(RANLIB)" \
			INSTALL_BIN="$(INSTALL_BIN)" \
			INSTALL_FILE="$(INSTALL_FILE)" \
			DEBUG="$(DEBUG)" \
			DEBUG_LIBS="$(DEBUG_LIBS)" \
			INSTALLDIR="$(INSTALL_BINDIR)" \
			INSTALL_SCRIPT="$(INSTALL_SCRIPT)" $@); \
	done

realclean:	clean
	-rm -f Makefile
	@for dir in $(SUBDIRS); do \
		echo Making $@ in $$dir; \
		(cd $$dir; $(MAKE) $(MFLAGS) \
			INSTALL_BINDIR="$(INSTALL_BINDIR)" \
			INSTALL_LIBDIR="$(INSTALL_LIBDIR)" \
			INSTALL_MANDIR="$(INSTALL_MANDIR)" \
			RANLIB="$(RANLIB)" \
			INSTALL_BIN="$(INSTALL_BIN)" \
			INSTALL_FILE="$(INSTALL_FILE)" \
			DEBUG="$(DEBUG)" \
			DEBUG_LIBS="$(DEBUG_LIBS)" \
			INSTALLDIR="$(INSTALL_BINDIR)" \
			INSTALL_SCRIPT="$(INSTALL_SCRIPT)" $@); \
	done

install:	all install-bin 
	@for dir in $(SUBDIRS); do \
		echo Making $@ in $$dir; \
		(cd $$dir; $(MAKE) $(MFLAGS) \
			INSTALL_BINDIR="$(INSTALL_BINDIR)" \
			INSTALL_LIBDIR="$(INSTALL_LIBDIR)" \
			INSTALL_UTILDIR="$(INSTALL_UTILDIR)" \
			INSTALL_MANDIR="$(INSTALL_MANDIR)" \
			RANLIB="$(RANLIB)" \
			INSTALL_BIN="$(INSTALL_BIN)" \
			INSTALL_FILE="$(INSTALL_FILE)" \
			DEBUG="$(DEBUG)" \
			DEBUG_LIBS="$(DEBUG_LIBS)" \
			INSTALLDIR="$(INSTALL_BINDIR)" \
			INSTALL_SCRIPT="$(INSTALL_SCRIPT)" $@); \
	done

install-bin:	$(PROGS)
	@for f in $(PROGS) $(SCRIPTS); do \
		echo $(INSTALL_BIN) $$f $(INSTALL_UTILDIR); \
		$(INSTALL_BIN) $$f $(INSTALL_UTILDIR); \
	done

mergedb template2db rmbinary consoldb cleandb extractdb expiredb:	
	$(CC) $(CFLAGS) -o $@ $@.c $(LDFLAGS) $(LIBS)

dbcheck:	
	$(CC) $(CFLAGS) -o $@ $@.c $(LDFLAGS) -lurl -lmd5 $(LIBS)


mergedb:	mergedb.c 
template2db:	template2db.c
rmbinary:	rmbinary.c
dbcheck:	dbcheck.c
consoldb:	consoldb.c
cleandb:	cleandb.c
extractdb:	extractdb.c
expiredb:	expiredb.c
