SHELL = /bin/sh

#=============================================================================
#
#  This is a template makefile to build a class library using sdb.
#
#  This file is designed to be invoked by a shell script called sdssmake
#  which selects supported options.  One of the C++ compilers must be selected
#  when running sdssmake, as well as the "-objectivity" flag.
#  (e.g., sdssmake -cc irixcxx -objectivity).
#
#  The following products must be setup when making such a product:
#	sdb		- for sdb libraries and include files
#	dervish		- for dervish libraries and include files.
#	sdsstools	- for sdssmake and filter_warn
#	tex		- for making the postscript documentation
#
#  INSTALL_DIR    --- Root directory into which the product is to be installed.#                     For example, INSTALL_DIR = $(MYSCH_DIR).
#  SUBDIRECTORIES --- List of subdirectories contained in the root directory
#                     for this product (i.e., this directory).
#
#  For example, for the product "mySch":
#     INSTALL_DIR   = $(MYSCH_DIR)
#     SUBDIRECTORIES= bin doc etc examples include lib src test ups
#
#=============================================================================

INSTALL_DIR	= $(TS_DIR)
SUBDIRECTORIES	= bin doc etc examples include lib src test ups
OPDBDIRECTORIES	= bin doc etc examples include lib src ups

#=============================================================================
#
# You should not have to edit any of the rest of this file, if all you are
# doing is building one class library and one executable, and some supporting
# TCL scripts.
#
#=============================================================================

#===========================================================================
# STANDARD TARGETS
#===========================================================================

default:
	@ echo Please invoke this makefile using sdssmake. >&2
	@ exit 1

all :
	@ echo "Updating libraries and directories"
	@ echo ""
	@ for f in $(SUBDIRECTORIES); do \
		(cd $$f ; echo In $$f; $(MAKE) $(MFLAGS) all ); \
	done

opdb :
	@ echo "Updating libraries and directories"
	@ echo ""
	@ for f in $(OPDBDIRECTORIES); do \
		(cd $$f ; echo In $$f; $(MAKE) $(MFLAGS) all ); \
	done
	(cd src ; echo In src; $(MAKE) $(MFLAGS) all )

install :
	@ echo ""
	@ echo "You should be sure to have updated before doing this."
	@ if [ "$(INSTALL_DIR)" = "" ]; then \
		echo You have not specified a destination directory >&2; \
		exit 1; \
	fi 
	@ if [ `(cd $(INSTALL_DIR); pwd)` = `pwd` ]; then \
		echo "The destination directory is the same as the current directory." >&2; \
		echo "The install will be aborted." >&2; \
		exit 1; \
	fi
	@ echo ""
	@ echo "You will be installing in \$$INSTALL_DIR = $(INSTALL_DIR)"
	@ echo ""
	@ echo "I'll give you 5 seconds to think about it (control-C to abort) ..."
	@ for pos in          5 4 3 2 1; do \
	   echo "                              " | sed -e 's/ /'$$pos'/'$$pos; \
	   sleep 1; \
	done
	@ rm -rf $(INSTALL_DIR)
	@ mkdir $(INSTALL_DIR)
	@ for f in $(SUBDIRECTORIES); do \
		(cd $$f ; echo In $$f; $(MAKE) $(MFLAGS) install ); \
	done
	/bin/cp Makefile $(INSTALL_DIR)

installDoc :
	@ echo ""
	@ echo "You should be sure to have updated before doing this."
	@ if [ "$(INSTALL_DIR)" = "" ]; then \
		echo You have not specified a destination directory >&2; \
		exit 1; \
	fi 
	@ if [ `(cd $(INSTALL_DIR); pwd)` = `pwd` ]; then \
		echo "The destination directory is the same as the current directory." >&2; \
		echo "The install will be aborted." >&2; \
		exit 1; \
	fi
	@ echo ""
	@ echo "You will be installing in \$$INSTALL_DIR = $(INSTALL_DIR)"
	@ echo ""
	@ echo "I'll give you 5 seconds to think about it (control-C to abort) ..."
	@ for pos in          5 4 3 2 1; do \
	   echo "                              " | sed -e 's/ /'$$pos'/'$$pos; \
	   sleep 1; \
	done
	@ rm -rf $(INSTALL_DIR)/doc
	@ mkdir $(INSTALL_DIR)/doc
	(cd doc ; echo In doc; $(MAKE) $(MFLAGS) install )

clean :
	@ echo in .
	rm -f *~ core *.bak *.orig *.old .#* #*#
	@ for f in $(SUBDIRECTORIES); do \
		(cd $$f ; echo In $$f; $(MAKE) $(MFLAGS) clean); \
	done
