#******************************************************************************
#                              PACOR II SOFTWARE
#                      Property of the U.S. Government
#                              NASA/GSFC/Code 560
#******************************************************************************
#
#    UNIT NAME:
#	Makefile
#
#    PURPOSE:
#	To compile the sources in the chiLib directory and make a library.
#
#    INVOCATION METHOD:
#		make help
#			to see this help message.
#
#		make [ debug | nodebug | optimize | gprof | tcov ]
#			to create libchi.a
#
#		make lint
#			to run lint on *.c and create llib-lxxx.ln.
#
#		make cadre
#			to run reverse engineering bmdl tool on *.c files
#
#               make clean
#                  to remove *%, *", *.lis, and core files.
#
#               make cleaner
#                  to remove *%, *", *.lis, core, *.o, *.ln,  precompiled 
#		   units, $(LIBRARY), *.d ,and  *.tcov.
#
#    EXTERNAL VARIABLES:
#
#       SOURCE		NAME		TYPE	USE	DESCRIPTION
#       ------		----		----	---	--------------------
#       Makefile        INCLUDES        macro   O       List of *.h includes in #                                                         Include and xxxInclude
#                                                         directories
#       Makefile        MYCFLAGS        macro   O       CFLAGS options
#       Makefile        SOURCES         macro   O       List of *.c files
#
#    EXTERNAL FILE/RECORD REFERENCES:
#
#       NAME		USE	DESCRIPTION
#       ----		---	-------------------------------------
# 	none
#
#    EXTERNAL UNIT/MACRO/PROCEDURE/FUNCTION REFERENCES:
#
#       NAME		PURPOSE
#       ------------	----------------------------------------------
#	Makefile2       Make source file with compile rules
#
#    ABNORMAL TERMINATION CONDITIONS, ERROR MESSAGES:
#	none
#
#    ASSUMPTIONS, CONSTRAINTS, RESTRICTIONS:
#	none
#
#    DEVELOPMENT HISTORY:
#
#    	Author	      Change-ID	  Release      Date     Description of Change
#    	-----------   ---------	  --------   --------   ----------------------
#       J. Kerich     n/a         R0B1       07/08/93   Original Implementation
#       J. Kerich     n/a         R1B2       10/27/93   Modified clean and 
#                                                         cleaner option
#       J. Kerich     n/a         TRACE 1.0  03/27/96   Upgrade to work on IRIX
#	C. DeMeter    n/a         TRACE 1.0  06/13/96   Modify for chiLib
#       R. Wiechert   WIND970001  R1.0       06/16/97   Modify MYCFLAGS for Sun
#
#    NOTES: 
#	This file creates the INCLUDES and SOURCES environment variables,
#	and calls Makefile2 todo 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 *.x' and changing the newlines to 
#	spaces.
#
#	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 
#
#******************************************************************************

TARGETS= debug nodebug optimize gprof tcov lint cadre
LIBRARY= libchi.a

SHELL = /usr/bin/sh
SOURCESCPC=`ls ?*.pc 2>/dev/null | sed "s/\.pc/\.c/p" | tr '\012' '\040'`

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

help:
	@ echo "Usage:"
	@ echo "	make help"
	@ echo "		to see this help message."
	@ echo ""
	@ echo "	make [ debug | nodebug | optimize | gprof | tcov ]"
	@ echo "		to create $(LIBRARY)."
	@ echo ""
	@ echo "	make lint"
	@ echo "		to run lint on xxx*.c and create llib-lxxx.ln."
	@ echo ""
	@ echo "	make cadre"
	@ echo "		to run reverse engineering bmdl tool on *.c files"
	@ echo ""
	@ echo "	make clean"
	@ echo "		to remove *%, *", *.lis, and core files."
	@ echo ""
	@ echo "	make cleaner"
	@ echo "		to remove *%, *", *.lis, core, *.ln, precompiled units,"
	@ echo "		*.d , *.tcov, $(LIBRARY)"

################################################################################

$(TARGETS): FORCE
	@	SOURCES=`ls ?*.c ?*.pc 2>/dev/null | sed "s/\.pc/\.c/p" | uniq | tr '\012' '\040'`; export SOURCES;\
	INCLUDES=`ls ../xxxInclude/?*.h  ../dbxInclude/?*.h  2>/dev/null | tr '\012' '\040'`; export INCLUDES;\
	if [ $@ = "debug" ];\
	then MYCFLAGS='-Xc -DSVR4 -Dsun -Dsparc -Dunix -g -xildoff -DDEBUG'; export MYCFLAGS; \
	elif [ $@ = "nodebug" ];\
	then MYCFLAGS='-Xc -DSVR4 -Dsun -Dsparc -Dunix -g -xildoff'; export MYCFLAGS; \
	elif [ $@ = "optimize" ];\
	then MYCFLAGS='-Xc -DSVR4 -Dsun -Dsparc -Dunix -O'; export MYCFLAGS; \
	elif [ $@ = "gprof" ];\
	then MYCFLAGS='-Xc -DSVR4 -Dsun -Dsparc -Dunix -xpg -O'; export MYCFLAGS; \
	elif [ $@ = "tcov" ];\
	then MYCFLAGS='-Xc -DSVR4 -Dsun -Dsparc -Dunix -xa'; export MYCFLAGS; \
	elif [ $@ = "lint" ];\
	then MYCFLAGS=''; export MYCFLAGS; \
	else @ echo "Invalid option"; \
	fi;\
	$(MAKE) -f Makefile2 $@

.PRECIOUS: $(LIBRARY)

clean: 
	rm -f *% *" *.lis core

cleaner: clean
	rm -f *.o *.ln $(SOURCESCPC) *.d *.tcov $(LIBRARY)

FORCE:
