#      Makefile for the occam TA routines for the FORTRAN library
#
#
# This file assumes that it is being run within the directory of the sources
# and output files.
#
# 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=

PREPROCESSOR=preocc
PREOPT=$(SWITCH)d FORTRAN $(SWITCH)d UNISTOP $(SWITCH)d TA
LIBRARIAN=ilibr
LIBOPT=
OCCAM=oc
OCCOPT=$(SWITCH)d $(SWITCH)v $(SWITCH)x $(SWITCH)u $(SWITCH)ta $(SWITCH)zlcp %f $(SWITCH)zlcs % $(OCCEXTRAS)

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

# this is not really our target, but we need it to get where we are going
TARGETLIB=occama.lib

# Pattern matching rules.
#
# An explicit rule is chosen in preference to a pattern matching one.
#
# $< is a dynamic macro meaning the name of the dependency file;
# $* is a dynamic macro meaning the base name of the current target
%.tax: %.occ
	$(PREPROCESSOR) $< $(PREOPT) $(SWITCH)o $*.pax
	$(OCCAM) $*.pax $(OCCOPT) $(SWITCH)o $*.tax
	$(DELETE) $*.pax


# the files in USEUTL all #USE occamutl.lib; they are mentioned here
# for reference
USEUTL=		r64op.tax   r64operr.tax r64rem.tax r64remer.tax dargred.tax

# files with routines that if77 calls explicitly ( see SW-???? )
IF77TAX=	r32operr.tax r32eqerr.tax r32gterr.tax \
		r64operr.tax r64eqerr.tax r64gterr.tax \
		r32toi32.tax i32tor32.tax \
		r64toi32.tax i32tor64.tax \
		r32tor64.tax r64tor32.tax

# files with routines that are required by some of those in IF77TAX ( or to
# be precise, by r64operr.tax )
IF77SUPPORT=	rimul.tax    ridiv.tax

# files with routines required by the maths routines or are maths routines
# themselves ( eg SQRT, though this is called by the maths routines too )
REALTAX=	rsqrt.tax    unpacksn.tax roundsn.tax \
		r32op.tax    ie32op.tax   \
		ranalyse.tax rfunpack.tax \
		rdivby2.tax  rmulby2.tax  ie32comp.tax \
		rscaleb.tax  rabsfint.tax \
		r32eq.tax    r32gt.tax    r32remer.tax \
		r64eq.tax    r64gt.tax \
		r64remer.tax r64rem.tax \
		r64op.tax    \
		danalyse.tax dfunpack.tax \
		ddivby2.tax  dmulby2.tax  ie64comp.tax \
		r32toi64.tax i64tor32.tax \
		r64toi64.tax i64tor64.tax \
		dscaleb.tax  dabsfint.tax \
		dminusx.tax  dnotfnte.tax dargred.tax \
		dsqrt.tax

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

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

$(OUTNAME):	$(IF77TAX) $(IF77SUPPORT) $(REALTAX)
	$(CONCATENATE) $(IF77TAX) $(IF77SUPPORT) $(REALTAX)  $(INTO)  $(OUTNAME)
	$(DELETE) occamutl.lib

#---------------------- files with dependencies ------------------------------
#
# We are booting ourselves up here - we have to create the a library with
# what we know will be required from it by the compiler in order that the
# target file may be compiled.  We delete the target library after each use of
# it so that it is only in existence when we want it to be and ensures that
# nothing goes on behind our backs.
#
# $@ is a dynamic macro which means the current target.
# $(@:.tax=.pax) is a macro which means replace the suffix of the target
# ( .tax ) by the new suffix .pax;  we use this rather than $* because 
# $* is really only meant for use in pattern matching rules or suffix rules,
# and gives strange results in explicit rules.


#
occamutl.lib: $(IF77SUPPORT)
	$(LIBRARIAN) $(IF77SUPPORT) $(LIBOPT) $(SWITCH)o occamutl.lib


# routines which are related to single precision reals

rabsfint.tax:	r32gterr.tax i32tor32.tax r32toi32.tax rabsfint.occ
	$(LIBRARIAN) $(LIBOPT) r32gterr.tax i32tor32.tax r32toi32.tax $(SWITCH)o $(TARGETLIB)
	$(PREPROCESSOR) $(@:.tax=.occ) $(PREOPT) $(SWITCH)o $(@:.tax=.pax)
	$(OCCAM) $(@:.tax=.pax) $(OCCOPT) $(SWITCH)o $@
	$(DELETE) $(@:.tax=.pax)
	$(DELETE) $(TARGETLIB)

rscaleb.tax:	r32operr.tax rscaleb.occ
	$(LIBRARIAN) $(LIBOPT) r32operr.tax $(SWITCH)o $(TARGETLIB)
	$(PREPROCESSOR) $(@:.tax=.occ) $(PREOPT)  $(SWITCH)o $(@:.tax=.pax)
	$(OCCAM) $(@:.tax=.pax) $(OCCOPT) $(SWITCH)o $@
	$(DELETE) $(@:.tax=.pax)
	$(DELETE) $(TARGETLIB)

rmulby2.tax:	r32operr.tax rmulby2.occ
	$(LIBRARIAN) $(LIBOPT) r32operr.tax $(SWITCH)o $(TARGETLIB)
	$(PREPROCESSOR) $(@:.tax=.occ) $(PREOPT) $(SWITCH)o $(@:.tax=.pax)
	$(OCCAM) $(@:.tax=.pax) $(OCCOPT) $(SWITCH)o $@
	$(DELETE) $(@:.tax=.pax)
	$(DELETE) $(TARGETLIB)

rdivby2.tax:	r32operr.tax rdivby2.occ
	$(LIBRARIAN) $(LIBOPT) r32operr.tax $(SWITCH)o $(TARGETLIB)
	$(PREPROCESSOR) $(@:.tax=.occ) $(PREOPT) $(SWITCH)o $(@:.tax=.pax)
	$(OCCAM) $(@:.tax=.pax) $(OCCOPT) $(SWITCH)o $@
	$(DELETE) $(@:.tax=.pax)
	$(DELETE) $(TARGETLIB)

ie32comp.tax:	r32gt.tax r32eq.tax ranalyse.tax ie32comp.occ
	$(LIBRARIAN) $(LIBOPT) r32gt.tax r32eq.tax ranalyse.tax $(SWITCH)o $(TARGETLIB)
	$(PREPROCESSOR) $(@:.tax=.occ) $(PREOPT) $(SWITCH)o $(@:.tax=.pax)
	$(OCCAM) $(@:.tax=.pax) $(OCCOPT) $(SWITCH)o $@
	$(DELETE) $(@:.tax=.pax)
	$(DELETE) $(TARGETLIB)

r32op.tax:	ie32op.tax r32op.occ
	$(LIBRARIAN) $(LIBOPT) ie32op.tax $(SWITCH)o $(TARGETLIB)
	$(PREPROCESSOR) $(@:.tax=.occ) $(PREOPT) $(SWITCH)o $(@:.tax=.pax)
	$(OCCAM) $(@:.tax=.pax) $(OCCOPT) $(SWITCH)o $@
	$(DELETE) $(@:.tax=.pax)
	$(DELETE) $(TARGETLIB)

r32operr.tax:	ie32op.tax r32operr.occ
	$(LIBRARIAN) $(LIBOPT) ie32op.tax $(SWITCH)o $(TARGETLIB)
	$(PREPROCESSOR) $(@:.tax=.occ) $(PREOPT) $(SWITCH)o $(@:.tax=.pax)
	$(OCCAM) $(@:.tax=.pax) $(OCCOPT) $(SWITCH)o $@
	$(DELETE) $(@:.tax=.pax)
	$(DELETE) $(TARGETLIB)

rsqrt.tax:	unpacksn.tax roundsn.tax rsqrt.occ
	$(LIBRARIAN) $(LIBOPT) unpacksn.tax roundsn.tax $(SWITCH)o $(TARGETLIB)
	$(PREPROCESSOR) $(@:.tax=.occ) $(PREOPT) $(SWITCH)o $(@:.tax=.pax)
	$(OCCAM) $(@:.tax=.pax) $(OCCOPT) $(SWITCH)o $@
	$(DELETE) $(@:.tax=.pax)
	$(DELETE) $(TARGETLIB)

r32remer.tax:	r32remer.occ
	$(PREPROCESSOR) $(@:.tax=.occ) $(PREOPT) $(SWITCH)o $(@:.tax=.pax)
	$(OCCAM) $(@:.tax=.pax) $(OCCOPT) $(SWITCH)o $@
	$(DELETE) $(@:.tax=.pax)


# routines which are related to double precision reals

dabsfint.tax:	r64gterr.tax i64tor64.tax r64toi64.tax dabsfint.occ
	$(LIBRARIAN) $(LIBOPT) r64gterr.tax i64tor64.tax r64toi64.tax $(SWITCH)o $(TARGETLIB)
	$(PREPROCESSOR) $(@:.tax=.occ) $(PREOPT) $(SWITCH)o $(@:.tax=.pax)
	$(OCCAM) $(@:.tax=.pax) $(OCCOPT) $(SWITCH)o $@
	$(DELETE) $(@:.tax=.pax)
	$(DELETE) $(TARGETLIB)

dargred.tax:	r64operr.tax i32tor64.tax occamutl.lib dargred.occ
	$(LIBRARIAN) $(LIBOPT) r64operr.tax i32tor64.tax $(SWITCH)o $(TARGETLIB)
	$(PREPROCESSOR) $(@:.tax=.occ) $(PREOPT) $(SWITCH)o $(@:.tax=.pax)
	$(OCCAM) $(@:.tax=.pax) $(OCCOPT) $(SWITCH)o $@
	$(DELETE) $(@:.tax=.pax)
	$(DELETE) $(TARGETLIB)

dscaleb.tax:	r64operr.tax dscaleb.occ
	$(LIBRARIAN) $(LIBOPT) r64operr.tax $(SWITCH)o $(TARGETLIB)
	$(PREPROCESSOR) $(@:.tax=.occ) $(PREOPT) $(SWITCH)o $(@:.tax=.pax)
	$(OCCAM) $(@:.tax=.pax) $(OCCOPT) $(SWITCH)o $@
	$(DELETE) $(@:.tax=.pax)
	$(DELETE) $(TARGETLIB)

dmulby2.tax:	r64operr.tax dmulby2.occ
	$(LIBRARIAN) $(LIBOPT) r64operr.tax $(SWITCH)o $(TARGETLIB)
	$(PREPROCESSOR) $(@:.tax=.occ) $(PREOPT) $(SWITCH)o $(@:.tax=.pax)
	$(OCCAM) $(@:.tax=.pax) $(OCCOPT) $(SWITCH)o $@
	$(DELETE) $(@:.tax=.pax)
	$(DELETE) $(TARGETLIB)

ddivby2.tax:	r64operr.tax ddivby2.occ
	$(LIBRARIAN) $(LIBOPT) r64operr.tax $(SWITCH)o $(TARGETLIB)
	$(PREPROCESSOR) $(@:.tax=.occ) $(PREOPT) $(SWITCH)o $(@:.tax=.pax)
	$(OCCAM) $(@:.tax=.pax) $(OCCOPT) $(SWITCH)o $@
	$(DELETE) $(@:.tax=.pax)
	$(DELETE) $(TARGETLIB)

ie64comp.tax:	r64gt.tax r64eq.tax danalyse.tax ie64comp.occ
	$(LIBRARIAN) $(LIBOPT) r64gt.tax r64eq.tax danalyse.tax $(SWITCH)o $(TARGETLIB)
	$(PREPROCESSOR) $(@:.tax=.occ) $(PREOPT) $(SWITCH)o $(@:.tax=.pax)
	$(OCCAM) $(@:.tax=.pax) $(OCCOPT) $(SWITCH)o $@
	$(DELETE) $(@:.tax=.pax)
	$(DELETE) $(TARGETLIB)

r64operr.tax:	occamutl.lib r64operr.occ
	$(PREPROCESSOR) $(@:.tax=.occ) $(PREOPT) $(SWITCH)o $(@:.tax=.pax)
	$(OCCAM) $(@:.tax=.pax) $(OCCOPT) $(SWITCH)o $@
	$(DELETE) $(@:.tax=.pax)

r64op.tax:	occamutl.lib r64op.occ
	$(PREPROCESSOR) $(@:.tax=.occ) $(PREOPT) $(SWITCH)o $(@:.tax=.pax)
	$(OCCAM) $(@:.tax=.pax) $(OCCOPT) $(SWITCH)o $@
	$(DELETE) $(@:.tax=.pax)

r64rem.tax:	occamutl.lib r64rem.occ
	$(PREPROCESSOR) $(@:.tax=.occ) $(PREOPT) $(SWITCH)o $(@:.tax=.pax)
	$(OCCAM) $(@:.tax=.pax) $(OCCOPT) $(SWITCH)o $@
	$(DELETE) $(@:.tax=.pax)

r64remer.tax:	occamutl.lib r64remer.occ
	$(PREPROCESSOR) $(@:.tax=.occ) $(PREOPT) $(SWITCH)o $(@:.tax=.pax)
	$(OCCAM) $(@:.tax=.pax) $(OCCOPT) $(SWITCH)o $@
	$(DELETE) $(@:.tax=.pax)
