# Makefile -  for creating PSAIL runtime library 'libPSAIL.a'
#
# P. Lemkin
# Image Processing Section
# National Cancer Institute, DCBD, LTB
# FCRF, Build 469 Room 150B
# Frederick, MD 21701
#
# Revised December 1, 1987
# Revised October 10, 1987
# Revised October 4, 1987
# Revised September 30, 1987
# Revised September 8, 1987
# February 6, 1987
# Version: @V.56.10
#
#
# --	INTRODUCTION
# This Makefile is used to create a PSAIL runtime library and documentation.
# The 'Makefile' is used to to build the 'psail' compiler and
# 'sairun.o', 'psrung.o' etc. libraries in archive 'libPSAIL.a' for UNIX
# and UNIX-like systems.
#
# --	DIRECTORIES in P = . 		(typically P = ~/psail)
# The PSAIL C source runtime libraries are in	R = P/runtim
#
# --	BUILDING PSAIL
# Read instructions below before proceeding, then rename this file to
# "makefile" or "Makefile". Then run 'make <keyword>' from the
# following list.
#
# Note that there is also other 'make' operations possible:
#
#	make  		        - to compile all library modules.
#	make backup             - to copy all PSAIL directories to BKUPHOST
#	make cleanup		- to remove all .o files.
#	make lib		- to build libPSAIL.a
#	make lint		- to run lint on all .c files.
#	make print		- to list all .c and .h files.
#	make saber		- to make saber.ld file for debugging
#
####################################################################
#  Compile and Link variables:
####################################################################
CFLAGS= -g
LIBS= -lc -lm
LINTFLAGS= -p
LNKFLAGS=

#
###################################################################
#  Directory alias variables
###################################################################
P= $$HOME/psail			# -- top level PSAIL directory.
R= $(P)/runtim			# -- source files for PSAIL runtime lib.
BKUPDIR = psail/bkup/
BKUPHOST = uvip.peter


#
###################################################################
#  File list variables
###################################################################

# -- RUNTIME files;
# -- runtime objects;
OBJSAIRUN= psrglb.o psrun1.o psrun2.o psrun3.o psrun4.o psrun5.o \
	psrun6.o psrun7.o psrun8.o psrun9.o psrung.o psrunl.o \
	psrunp.o psrunw.o psrunx.o

# -- runtime sources;
SRCSAIRUN= psrglb.c psrun1.c psrun2.c psrun3.c psrun4.c psrun5.c \
	psrun6.c psrun7.c psrun8.c psrun9.c psrung.c psrunl.c \
	psrunp.c psrunw.c psrunx.c

# -- common SAIRUN runtime .h's;
HDRSAIRUN= config.h sairun.h psrung.h pmath.h

# -- 2ndary runtime .h's;
HDR2SAIRUN= pmath.h psrdef.h psrglb.h psrun1.h psrun2.h psrun3.h \
	psrun4.h psrun5.h psrun6.h psrun7.h psrun8.h psrun9.h psrunl.h \
	psrunp.h psrunw.h psrunx.h


#
#
####################################################################
#
# Dependencies Section:
#
####################################################################
# --	[ALL] Build the WHOLE ENCHELADA...;
all: $(OBJSAIRUN) libPSAIL.a
	cc $(CFLAGS) $(OBJSAIRUN) -c $(LIBS)

config.h: sairun.h
confg2.h: sairun.h config.h
psrdef.h: config.h confg2.h psrung.h
sairun.h: psrglb.c psrun1.c psrun2.c psrun3.c psrun4.c psrun5.c \
	psrun6.c psrun7.c psrun8.c psrun9.c pmath.h

psrglb.o: psrglb.c config.h psrdef.h

psrun1.o: psrun1.c config.h psrdef.h psrglb.h psrun3.c psrun4.c psrun7.c
psrun2.o: psrun2.c config.h psrdef.h psrglb.h psrun7.c
psrun3.o: psrun3.c config.h psrdef.h psrglb.h psrun1.c psrun8.c
psrun4.o: psrun4.c config.h psrdef.h psrglb.h psrun1.c psrun8.c
psrun5.o: psrun5.c config.h psrdef.h psrglb.h psrun1.c psrun3.c
psrun6.o: psrun6.c config.h psrdef.h psrglb.h 
psrun7.o: psrun7.c config.h psrdef.h psrglb.h psrun1.c psrun3.c \
	 psrun4.c psrun5.c
psrun8.o: psrun8.c config.h psrdef.h psrglb.h psrun7.c psrun9.c
psrun9.o: psrun9.c config.h psrdef.h psrglb.h psrun8.c

psrung.o: psrung.c config.h confg2.h sairun.h psrdef.h psrglb.h \
	gogtab.h psrun1.c

psrunl.o: psrunl.c config.h confg2.h sairun.h psrdef.h psrglb.h

psrunp.o: psrunp.c config.h confg2.h psrdef.h psrglb.h

psrunw.o: psrunw.c config.h psrdef.h psrglb.h psrun3.c psrunw.h

psrunx.o: psrunx.c config.h confg2.h psrdef.h psrglb.h psrung.h


# --    [BACKUP] backup $HOME/psail to BKUP host system.
backup:
	rcp -r . $(BKUPHOST):$(BKUPDIR)
	echo "Finished Backup of $(P)/$(R) to $(BKUPHOST):$(BKUPDIR)"


# --	[CLEANUP] Cleanup all .o files and other trash;
cleanup:
	rm $(OBJSAIRUN)
	echo "Finished CLEANUP of $(P)"


# --    [INSTALL] Install the library in the system
install: libPSAIL.a
	mv libPSAIL.a $(PRUNINSTALL)
	chmod 755 $(PRUNINSTALL)/libPSAIL.a


# --	[LIB] Create the PSAIL runtime library archeive libPSAIL.a
# --    and install in in PRUINSTALL;
libPSAIL.a: lib

lib: $(OBJSAIRUN)
	ar rcv libPSAIL.a $(OBJSAIRUN); 
	ranlib libPSAIL.a;
	ls -l libPSAIL.a


# --	[LINT] Lint all the source files
lint:
	cp /dev/null psail.lint;
	lint $(LINTFLAGS) $(SRCSAIRUN) >> psail.lint


# --	[PRINT] Print all .c and .h files in /runtim
# --	into file psail.lst;
print:
	cp /dev/null psail.lst;
	for x in Makefile *.h sairun.c ps*.c; do\
		cat -n $x | pr -f -h $x >> psail.lst; \
	done



# --	[SABER] create a 'saber.ld' file for debugging with the
#	Saber C debugger (for Vaxes and SUNS).
#	The saber.ld is then loaded into Saber-C C debugger using
#	      #include "saber.ld"    C statement.
# 	NOTE: it is setup for debugging the <sairun.c> etc
#	runtime package.
#
saber.ld: $(SRCSAIRUN)
saber:  saber.ld
	rm -rf saber.ld
	echo "setopt(\"load_options\", \"$(CFLAGS)\");" > saber.ld
	echo "load( \"$(SRCSAIRUN)\" ); " >> saber.ld
	echo "load( \"$(LIBS)\" ); " >> saber.ld
	echo "load( \"-lc\" ); " >> saber.ld
	echo "Script 'saber.ld' for Saber-C is finished."

#
# --	 ---> END OF PSAIL.MAK < ---
