#
#	Copyright (c) 1990,1991,1992 OPEN SOFTWARE FOUNDATION, INC.
#	ALL RIGHTS RESERVED
#

#	This makefile is the general builder for all of /project/docsrc/src/...
#
#	It supports the standard targets: install, clean, and clobber
#	by running makefiles in subdirectories.  Important parameters
#	like the location of the installation locations is either
#	passed down via makefile invocation or defaulted.

InstallCmd	= cp
MAKE		= make


SHELL		= /bin/sh
TOP		= /tmp/DTE
TOPBINDIR	= $(TOP)/bin
BINDIR		= $(TOP)/bin/$(MACHINE)
LIBDIR		= $(TOP)/libdata
MANDIR		= $(TOP)/man
SNAPSHOT	=
ALL_ARGS	= TOP=$(TOP) BINDIR=$(BINDIR) MACHINE=$(MACHINE) \
		  LIBDIR=$(LIBDIR) MANDIR=$(MANDIR) SNAPSHOT=$(SNAPSHOT) \
		  InstallCmd=$(InstallCmd)

SOURCES		= Makefile

TOOLDIRS	= dte macros glossary installref
PROGDIRS	= dte installref sml
TOOLSRCDIRS	= dte macros glossary installref sml

all: force
	for dir in $(TOOLDIRS); \
	    do (echo ""; echo "--- building $$dir ---"; date; cd $$dir; \
		$(MAKE) $(ALL_ARGS) $@ ) \
	    done

tools: all

install: force
	@sh -c 'if [ -d $(TOP) ]; then true; else mkdir $(TOP); fi'
	@sh -c 'if [ -d $(TOPBINDIR) ]; then true; else mkdir $(TOPBINDIR); fi'
	@sh -c 'if [ -d $(BINDIR) ]; then true; else mkdir $(BINDIR); fi'
	@sh -c 'if [ -d $(LIBDIR) ]; then true; else mkdir $(LIBDIR); fi'
	@sh -c 'if [ -d $(MANDIR) ]; then true; else mkdir $(MANDIR); fi'
	for dir in $(TOOLDIRS); \
	    do (echo ""; echo "--- installing $$dir ---"; date; cd $$dir; \
		$(MAKE) $(ALL_ARGS) $@ ) \
	    done

#  For installing programs, but not macros, glossary, etc.  (intended for
#  support of multiple acrhitectures on same directory structure.
install-progs: force
	@sh -c 'if [ -d $(TOP) ]; then true; else mkdir $(TOP); fi'
	@sh -c 'if [ -d $(BINDIR) ]; then true; else mkdir $(BINDIR); fi'
	for dir in $(PROGDIRS); \
	    do (echo ""; echo "--- installing $$dir ---"; date; cd $$dir; \
		$(MAKE) $(ALL_ARGS) install ) \
	    done

install-tools: install

snapshot: force
	@sh -c 'if [ -z "$(SNAPSHOT)" ]; \
	    then echo "SNAPSHOT must be defined on command line - no default!";\
		exit 1 ; \
	    else true ; fi'
	@sh -c 'if [ -d $(SNAPSHOT) ]; then true; else mkdir $(SNAPSHOT); fi'
	-for d in tools tools/src tools/bin tools/man \
		tools/src/dte tools/src/macros tools/src/glossary \
		tools/src/installref tools/src/sml ; \
	    do (if [ -d $(SNAPSHOT)/$$d ]; then true; \
		else mkdir $(SNAPSHOT)/$$d; fi ) done
	-rm -f $(SNAPSHOT)/tools/src/Makefile
	$(InstallCmd) $(SOURCES) $(SNAPSHOT)/tools/src/.
	for dir in $(TOOLSRCDIRS); \
	    do (echo ""; echo "--- copying $$dir ---"; cd $$dir; \
		$(MAKE) $(ALL_ARGS) $@ ) \
	    done

# dependency hack
force:

clean:
	for dir in $(TOOLDIRS); \
	    do ( cd $$dir; $(MAKE) clean ) ; done

clobber:
	for dir in $(TOOLDIRS); \
	    do ( cd $$dir; $(MAKE) clobber ) ; done

rev-list:
	@date | sed -e 's/^/# /'
	@echo ""
	@echo "# Files in `pwd`"
	@(p=`pwd` ; rcsstat -R -V $(SOURCES) | sed -e "s@^\.@$$p@" )
	@echo ""
	@for dir in $(TOOLSRCDIRS); \
	    do (cd $$dir ; $(MAKE) $(ALL_ARGS) $@ ) done

