#     Makefile for the occam compiler TB routines for the FORTRAN library
#
#
# This file assumes that it is being run within the directory of the sources
# and output files.
#
# We must be careful here since some of the routines are compiled
# in both TB and TA mode; TB can call TA, but not vice versa.
#
# The macro OUTNAME must be supplied from the command line.
#
#                          5-Feb-91 SRH
#
#                 This file is set up for UNIX.


SWITCH=-

# this name must be supplied from the command line
OUTNAME=

# for the flexibility to pass something in from the command line 
OCCEXTRAS=

# do not define TB in PREOPT - see SQRT example below
PREPROCESSOR=preocc
PREOPT=$(SWITCH)d FORTRAN $(SWITCH)d UNISTOP
LIBRARIAN=ilibr
LIBOPT=
OCCAM=oc
OCCOPT=$(SWITCH)d $(SWITCH)v $(SWITCH)x $(SWITCH)u $(SWITCH)tb $(SWITCH)zlcp %f $(SWITCH)zlcs %  $(OCCEXTRAS)

INTO=>
COPY=cp
RENAME=mv
DELETE=rm
CONCATENATE=cat

# files which must be in TB mode since they are more efficient in this
# mode, rsqrt because it uses ROUNDSN and UNPACKSN, the others because
# the source code is different for TB than for TA ( ASM is used )
TBXMODE=	r32op.tbx r32operr.tbx r32gterr.tbx r32eqerr.tbx \
		rsqrt.tbx

# The following files contain routines which call those in
# TBXMODE above and so for efficiency are compiled in TB mode
# also.  ( Actually, ABS in rabsfint.occ does not make such a call,
# but it is in the same file as FPINT which does. )
CALLTBMODE=	rscaleb.tbx  rargred.tbx  rmulby2.tbx rdivby2.tbx \
		rabsfint.tbx

#-------------------------------- Main rule ---------------------------------

# Force the whole library to be made
all:		$(OUTNAME)

$(OUTNAME):	$(TBXMODE)
	$(CONCATENATE) $(TBXMODE)  $(INTO)  $(OUTNAME)


# now for the TB stuff

r32op.tbx:	r32op.occ
	$(PREPROCESSOR) $(@:.tbx=.occ) $(PREOPT) $(SWITCH)d TB $(SWITCH)o $(@:.tbx=.pbx)
	$(OCCAM) $(@:.tbx=.pbx) $(OCCOPT) $(SWITCH)o $@
	$(DELETE) $(@:.tbx=.pbx)

r32operr.tbx:	r32operr.occ
	$(PREPROCESSOR) $(@:.tbx=.occ) $(PREOPT) $(SWITCH)d TB $(SWITCH)o $(@:.tbx=.pbx)
	$(OCCAM) $(@:.tbx=.pbx) $(OCCOPT) $(SWITCH)o $@
	$(DELETE) $(@:.tbx=.pbx)

r32gterr.tbx:	r32gterr.occ
	$(PREPROCESSOR) $(@:.tbx=.occ) $(PREOPT) $(SWITCH)d TB $(SWITCH)o $(@:.tbx=.pbx)
	$(OCCAM) $(@:.tbx=.pbx) $(OCCOPT) $(SWITCH)o $@
	$(DELETE) $(@:.tbx=.pbx)

r32eqerr.tbx:	r32eqerr.occ
	$(PREPROCESSOR) $(@:.tbx=.occ) $(PREOPT) $(SWITCH)d TB $(SWITCH)o $(@:.tbx=.pbx)
	$(OCCAM) $(@:.tbx=.pbx) $(OCCOPT) $(SWITCH)o $@
	$(DELETE) $(@:.tbx=.pbx)

# note how we use the TA source code for SQRT
rsqrt.tbx:	rsqrt.occ
	$(PREPROCESSOR) $(@:.tbx=.occ) $(PREOPT) $(SWITCH)d TA $(SWITCH)o $(@:.tbx=.pbx)
	$(OCCAM) $(@:.tbx=.pbx) $(OCCOPT) $(SWITCH)o $@
	$(DELETE) $(@:.tbx=.pbx)


# now for the TB stuff that calls the more primitive ones; note how we define
# TA on the preprocessor command line

rabsfint.tbx:	r32gterr.tbx i32tor32.tax r32toi32.tax rabsfint.occ
	$(LIBRARIAN) $(LIBOPT) r32gterr.tbx i32tor32.tax r32toi32.tax $(SWITCH)o $(TARGETLIB)
	$(PREPROCESSOR) $(@:.tbx=.occ) $(PREOPT) $(SWITCH)d TA $(SWITCH)d UNISTOP $(SWITCH)o $(@:.tbx=.pbx)
	$(OCCAM) $(@:.tbx=.pbx) $(SWITCH)x $(SWITCH)tb $(OCCOPT) $(SWITCH)o $@
	$(DELETE) $(@:.tbx=.pbx)
	$(DELETE) $(TARGETLIB)

rscaleb.tbx:	r32operr.tbx rscaleb.occ
	$(LIBRARIAN) $(LIBOPT) r32operr.tbx $(SWITCH)o $(TARGETLIB)
	$(PREPROCESSOR) $(@:.tbx=.occ) $(PREOPT) $(SWITCH)d TA $(SWITCH)d UNISTOP $(SWITCH)o $(@:.tbx=.pbx)
	$(OCCAM) $(@:.tbx=.pbx) $(SWITCH)x $(SWITCH)tb $(OCCOPT) $(SWITCH)o $@
	$(DELETE) $(@:.tbx=.pbx)
	$(DELETE) $(TARGETLIB)

rargred.tbx:	r32operr.tbx i32tor32.tax rargred.occ
	$(LIBRARIAN) $(LIBOPT) r32operr.tbx i32tor32.tax $(SWITCH)o $(TARGETLIB)
	$(PREPROCESSOR) $(@:.tbx=.occ) $(PREOPT) $(SWITCH)d TA $(SWITCH)d UNISTOP $(SWITCH)o $(@:.tbx=.pbx)
	$(OCCAM) $(@:.tbx=.pbx) $(SWITCH)x $(SWITCH)tb $(OCCOPT) $(SWITCH)o $@
	$(DELETE) $(@:.tbx=.pbx)
	$(DELETE) $(TARGETLIB)

rmulby2.tbx:	r32operr.tbx rmulby2.occ
	$(LIBRARIAN) $(LIBOPT) r32operr.tbx $(SWITCH)o $(TARGETLIB)
	$(PREPROCESSOR) $(@:.tbx=.occ) $(PREOPT) $(SWITCH)d TA $(SWITCH)d UNISTOP $(SWITCH)o $(@:.tbx=.pbx)
	$(OCCAM) $(@:.tbx=.pbx) $(SWITCH)x $(SWITCH)tb $(OCCOPT) $(SWITCH)o $@
	$(DELETE) $(@:.tbx=.pbx)
	$(DELETE) $(TARGETLIB)

rdivby2.tbx:	r32operr.tbx rdivby2.occ
	$(LIBRARIAN) $(LIBOPT) r32operr.tbx $(SWITCH)o $(TARGETLIB)
	$(PREPROCESSOR) $(@:.tbx=.occ) $(PREOPT) $(SWITCH)d TA $(SWITCH)d UNISTOP $(SWITCH)o $(@:.tbx=.pbx)
	$(OCCAM) $(@:.tbx=.pbx) $(SWITCH)x $(SWITCH)tb $(OCCOPT) $(SWITCH)o $@
	$(DELETE) $(@:.tbx=.pbx)
	$(DELETE) $(TARGETLIB)
