#
#  Makefile for the common source directory
#
#  $Id: Makefile.in,v 1.10 1994/09/30 22:11:28 hardy Exp $
#
SUBDIRS		= util template
DEBUG_TOP	= #-O #-g #-DDEBUG

srcdir = @srcdir@
VPATH  = @srcdir@
prefix = /usr/local/harvest
INSTALL_BINDIR	= $(prefix)/bin
INSTALL_LIBDIR	= $(prefix)/lib
INSTALL_MANDIR 	= $(prefix)/man

SHELL		= /bin/sh
CC		= @CC@
INSTALL		= @INSTALL@
INSTALL_BIN 	= @INSTALL_PROGRAM@
INSTALL_FILE 	= @INSTALL_DATA@
RANLIB		= @RANLIB@
LN_S		= @LN_S@
XTRA_LIBS	= @XTRA_LIBS@


# old variables for backward compatability
INSTALLDIR 	= $(INSTALL_BINDIR)
INSTALL_SCRIPT 	= $(INSTALL_BIN)

INSTALL_DIRS	= $(prefix) $(INSTALL_BINDIR) $(INSTALL_LIBDIR) \
		  $(INSTALL_MANDIR)

all:
	@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)" \
			DEBUG_TOP="$(DEBUG_TOP)" \
			INSTALL_BIN="$(INSTALL_BIN)" \
			INSTALL_FILE="$(INSTALL_FILE)" \
			INSTALLDIR="$(INSTALL_BINDIR)" \
			INSTALL_SCRIPT="$(INSTALL_SCRIPT)"  $@); \
	done

install:
	@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)" \
			INSTALLDIR="$(INSTALL_BINDIR)" \
			INSTALL_SCRIPT="$(INSTALL_SCRIPT)" $@); \
	done

clean:
	-@for dir in lib $(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)" \
			INSTALLDIR="$(INSTALL_BINDIR)" \
			INSTALL_SCRIPT="$(INSTALL_SCRIPT)" $@); \
	done

realclean:	clean
	-rm -f Makefile include/autoconf.h include/paths.h config.status *~ core
	-@for dir in gdbm lib $(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)" \
			INSTALLDIR="$(INSTALL_BINDIR)" \
			INSTALL_SCRIPT="$(INSTALL_SCRIPT)"  $@); \
	done

#
#  Compiles and installs gdbm from scratch.  Works with gdbm-1.7.3
#
all-gdbm:
	@echo Making all in gdbm
	@rm -f gdbm/autoconf.h
	@$(LN_S) ../include/autoconf.h gdbm/autoconf.h
	@(cd gdbm; \
		$(MAKE) $(MFLAGS) gdbm.h libgdbm.a; \
		$(INSTALL_FILE) gdbm.h ../include/gdbm.h; \
		$(INSTALL_FILE) libgdbm.a ../lib/libgdbm.a; \
		$(RANLIB) ../lib/libgdbm.a \
	)
