#******************************************************************************
#                              PACOR II SOFTWARE
#                      Property of the U.S. Government
#                              NASA/GSFC/Code 560
#******************************************************************************
#
#    UNIT NAME:
#	Makefile2
#
#    PURPOSE:
#	To compile the sources in the directory.
#
#    INVOCATION METHOD:
#          make help
#                  to see this help message
#
#          make [ debug | purify | purifynodebug | purifyoptimize | quantify | nodebug | optimize | gprof | tcov ]
#                  to compile PDPS task
#
#          make lint
#                  to run lint on ?*.*c and create .ln files.
#
#          make cadre
#                  to run reverse engineering bmdl tool on *.c files
#
#          make clean
#                  to remove *%, *.lis, core, *.err, *.met, and xxx files.
#
#          make cleaner
#                  to remove *%, *.lis, core,  *.err, *.met, xxx, *.o, *.ln,  
#		   precompiled units, executables, *.d , *.tcov, and pxx.
#
#
#    RETURNED VALUE:
#
#	TYPE = void
#
#	VALUE           DESCRIPTION
#	------------    ----------------------------
#	none
#
#    ARGUMENT LIST:
#
#       NAME 		TYPE		USE	DESCRIPTION
#       ------------	---------	---	----------------------------
#	none
#
#    EXTERNAL FILE/RECORD REFERENCES:
#
#       NAME		USE	DESCRIPTION
#       ----		---	-------------------------------------
#	none
#
#    EXTERNAL VARIABLES:
#
#       SOURCE		NAME		TYPE	USE	DESCRIPTION
#       ------		----		----	---	--------------------
#	Makefile2	EXECUTABLE	macro	O	Executable name for task
#	Makefile2	INCLUDES	macro	O	List of *.h include in Include, 
#							  pxxInclude, xxxInclude, and 
#							  dbxInclude directories
#	Makefile2	MYCFLAGS	macro	O	CFLAGS options
#	Makefile2	PURIFY		macro	O	PURIFY options (if any)
#	Makefile2	QUANTIFY	macro	O	QUANTIFY options (if any)
#	Makefile2	SOURCES		macro	O	List of *.c files
#	Makefile2	TASK		macro	O	name of task
#
#    EXTERNAL UNIT/MACRO/PROCEDURE/FUNCTION REFERENCES:
#
#       NAME		PURPOSE
#       ------------	----------------------------------------------
#	none
#
#    ABNORMAL TERMINATION CONDITIONS, ERROR MESSAGES:
#	none
#
#    ASSUMPTIONS, CONSTRAINTS, RESTRICTIONS:
#	Directory names must be in form <executable>Lib, where <executable> is the
#	lower case form of the executable file name.
#
#    DEVELOPMENT HISTORY:
#
#    	Author	      Change-ID	  Release      Date     Description of Change
#    	-----------   ---------	  --------   --------   -----------------------
#       J. kerich     n/a         TRACE R1.0 03/27/96   Original Implementation
#       A. Taylor     TRACE0116   TRACE R2.0 02/25/97   Add PER task
#       R. Wiechert   WIND970001  R1.0       06/16/97   Modify MYCFLAGS for Sun
#
#    NOTES:
#	This file creates the INCLUDES, SOURCES and TASK environment 
#	variables, and calls Makefile3 to do the actual work.
#
#	INCLUDES is defined by running 'ls *.h' on the directories and changing 
#		the newlines to spaces.
#
#	SOURCES is defined by running 'ls ?*.c' and changing the newlines to spaces.
#
#	TASK is defined by choping off the Lib in the director name.
#
#	The SOURCESCPC is defined by running 'ls ?*.pc', changing the newlines
#	to spaces, and changing .pc to .c to get a list of precompiled c units.
#
#******************************************************************************

SHELL= /usr/bin/sh
TARGETS= tcov cadre debug nodebug optimize lint gprof purify purifynodebug purifyoptimize quantify
LIBRARY= libpxx.a
TOOLS= hashinit verifyhash viewhash vhashindex time_convert lzptime lzp_isas fread

SOURCESCPC=`ls ?*.pc 2>/dev/null | sed "s/\.pc/\.c/" | tr '\012' '\040'`
TASK=`pwd | tr '\057' '\012' | tail -1 | sed "s/Lib//"`
EXECUTABLE=`pwd | tr '\057' '\012' | tail -1 | sed "s/Lib//" | tr "[a-z]" "[A-Z]"`

#******************************************************************************
#
#	Dependency entries.
#
#******************************************************************************

help:
	@ echo "Usage:"
	@ echo "	make help"
	@ echo "		to see this help message."
	@ echo ""
	@ echo "	make [ debug | purify | purifynodebug | purifyoptimize | quantify | nodebug | optimize | gprof | tcov ]"
	@ echo "		to create local task."
	@ echo ""
	@ echo "	make lint"
	@ echo "		to run lint on ?*.c and create .ln files."
	@ echo ""
	@ echo "	make cadre"
	@ echo "		to run reverse engineering bmdl tool on *.c files"
	@ echo ""
	@ echo "	make clean"
	@ echo "		to remove *%, *~, *.lis, core, *.err, *.met, and xxx files."
	@ echo ""
	@ echo "	make cleaner"
	@ echo "		to remove *%, *~, *.lis, core, *.err, *.met, xxx, *.o, *.ln, "
	@ echo "		precompiled units, executables, *.d , *.tcov, and pxx."


$(TARGETS): FORCE
	@	SOURCES=`ls ?*.*c 2>/dev/null | sed "s/\.pc/\.c/" | sort -u | tr '\012' '\040'`; export SOURCES; \
	TASK=`pwd | tr '\057' '\012' | tail -1 | sed "s/Lib//"`; export TASK;\
	if [ "$(TASK)" = "csd" -o "$(TASK)" = "cgp" -o "$(TASK)" = "hgp" -o "$(TASK)" = "ppa" -o "$(TASK)" = "pha"  -o "$(TASK)" = "pei" ] ;\
	then INCLUDES=`ls Include/?*.h  ../../pxxInclude/?*.h  ../../../xxxInclude/?*.h ../../../dbxInclude/?*.h 2>/dev/null | tr '\012' '\040'`; export INCLUDES; \
	else INCLUDES=`ls Include/?*.h  ../pxxInclude/?*.h ../../xxxInclude/?*.h ../../dbxInclude/?*.h 2>/dev/null | tr '\012' '\040'`; export INCLUDES;\
	fi;\
	EXECUTABLE=`pwd | tr '\057' '\012' | tail -1 | sed "s/Lib//" | tr "[a-z]" "[A-Z]"`; export EXECUTABLE;\
	if [ $@ = "debug" ];\
	then MYCFLAGS='-Xc -xcg92 -DSVR4 -Dsun -Dsparc -Dunix -g -xildoff -DDEBUG'; export MYCFLAGS; \
	elif [ $@ = "nodebug" ];\
	then MYCFLAGS='-Xc -xcg92 -DSVR4 -Dsun -Dsparc -Dunix -g -xildoff'; export MYCFLAGS; \
	elif [ $@ = "optimize" ];\
	then MYCFLAGS='-Xc -xcg92 -DSVR4 -Dsun -Dsparc -Dunix -O'; export MYCFLAGS; \
	elif [ $@ = "gprof" ];\
	then MYCFLAGS='-Xc -xcg92 -DSVR4 -Dsun -Dsparc -Dunix -xpg -O'; export MYCFLAGS; \
	elif [ $@ = "tcov" ];\
	then MYCFLAGS='-Xc -xcg92 -DSVR4 -Dsun -Dsparc -Dunix -xa'; export MYCFLAGS; \
	elif [ $@ = "purify" ];\
	then MYCFLAGS='-Xc -xcg92 -DSVR4 -Dsun -Dsparc -Dunix -g -xildoff -DDEBUG'; export MYCFLAGS; PURIFY='purify -first-only -chain-length=20 -suppression-file-names=".purify, .purify.solaris2.2"'; export PURIFY; \
	elif [ $@ = "purifynodebug" ];\
	then MYCFLAGS='-Xc -xcg92 -DSVR4 -Dsun -Dsparc -Dunix -g -xildoff'; export MYCFLAGS; PURIFY='purify -first-only -chain-length=20 -suppression-file-names=".purify, .purify.solaris2.2"'; export PURIFY; \
	elif [ $@ = "purifyoptimize" ];\
	then MYCFLAGS='-Xc -xcg92 -DSVR4 -Dsun -Dsparc -Dunix -O'; export MYCFLAGS; PURIFY='purify -first-only -chain-length=20 -suppression-file-names=".purify, .purify.solaris2.2"'; export PURIFY; \
	elif [ $@ = "quantify" ];\
	then MYCFLAGS='-Xc -xcg92 -DSVR4 -Dsun -Dsparc -Dunix -g -xildoff'; export MYCFLAGS; QUANTIFY='quantify -write-summary-file=/.quantifyout'; export QUANTIFY; \
	elif [ $@ = "lint" ];\
	then MYCFLAGS=''; export MYCFLAGS; \
	else @ echo "Invalid option"; \
	fi;\
	if [ "$(TASK)" = "csd" -o "$(TASK)" = "cgp" -o "$(TASK)" = "ppa" -o "$(TASK)" = "pei" -o "$(TASK)" = "per" ] ;\
	then $(MAKE) -f ../../Makefile3 $@ DEPTH='../..'; \
	else $(MAKE) -f ../Makefile3 $@ DEPTH='..' ; \
	fi

# .PRECIOUS: $(EXECUTABLE) $(LIBRARY)

clean:
	-rm -f *% *~ *.lis core *.err *.met

cleaner: clean
	-rm -f *.o *.ln $(SOURCESCPC) $(EXECUTABLE) *.d *.tcov $(LIBRARY) $(TOOLS)
	-@if [ -h SCCS ]; \
	then sccs clean ;\
	fi

FORCE:
