#         Makefile for the occam T2 routines for the C 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.
#
#                           4-Dec-90 SRH
#
#                  This file is set up for UNIX.
#

SWITCH=-

# this 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 C $(SWITCH)d T2 $(SWITCH)d UNISTOP
LIBRARIAN=ilibr
LIBOPT=
OCCAM=oc
OCCOPT=$(SWITCH)d $(SWITCH)v $(SWITCH)x $(SWITCH)t2 $(SWITCH)u $(SWITCH)zlcp %c $(SWITCH)zlcs % $(OCCEXTRAS)

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

# this is not actually our target, but it is used in getting to where we
# are going
TARGETLIB=occam2.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
%.t2x: %.occ
	$(PREPROCESSOR) $< $(PREOPT) $(SWITCH)o $*.p2x
	$(OCCAM) $*.p2x $(OCCOPT) $(SWITCH)o $*.t2x
	$(DELETE) $*.p2x

# files with routines called explicitly by icc ( see SW-0054 ) ( and
# some also happen to be required by the maths routines )
ICCT2X= 	i32plus.t2x  i32minus.t2x i32eq.t2x    i32gt.t2x    \
		i32times.t2x i32divrm.t2x i32lshft.t2x i32rshft.t2x \
		i32band.t2x  i32bor.t2x   i32xor.t2x   i32bnot.t2x  \
		\
		r32operr.t2x r32eqerr.t2x r32gterr.t2x \
		r64operr.t2x r64eqerr.t2x r64gterr.t2x \
		r32toi16.t2x i16tor32.t2x r32toi32.t2x i32tor32.t2x \
		r64tor32.t2x r32tor64.t2x \
		r64toi16.t2x i16tor64.t2x r64toi32.t2x i32tor64.t2x

# Files with routines required by some of those in ICCT2X ( or to be
# precise, by r32operr.t2x, r64operr.t2x and r64toi16.t2x ).
# They also are required by r32op.t2x, r64op.t2x, rargred.t2x and
# dargred.t2x.
ICCSUPPORT=	rimul.t2x    ridiv.t2x    qrimul.t2x   qridiv.t2x \
		qnorm.t2x    qshiftl.t2x  qshiftr.t2x

# files which are explicitly called in the C harnesses of the occam
# concatenations ( and are also required by the maths routines )
EXPLICIT=	r32op.t2x    r32gt.t2x    \
		r64op.t2x    r64gt.t2x

# files with routines that are solely required by the unsigned comparison
# routines
UNSIGNEDSUPPORT= i64divrm.t2x r32toi64.t2x i64tor32.t2x

# the rest are required to support the occam maths routines or are maths
# routines themselves ( eg SQRT, though some maths routines call it too )
# with the exception that i64bor and i64band are required by dabsfint
OTHERS=		r32eq.t2x    r64eq.t2x    \
		i64eq.t2x    i64gt.t2x    \
		i64band.t2x  i64bor.t2x   \
		i64lshft.t2x i64rshft.t2x \
		r64toi64.t2x i64tor64.t2x \
		rnotfnte.t2x rfunpack.t2x rminusx.t2x  rsqrt.t2x \
		rabsfint.t2x ranalyse.t2x rscaleb.t2x  rargred.t2x  \
		rmulby2.t2x  rdivby2.t2x  ie32comp.t2x \
		dnotfnte.t2x dfunpack.t2x dminusx.t2x  dsqrt.t2x \
		dabsfint.t2x danalyse.t2x dscaleb.t2x  dargred.t2x  \
		dmulby2.t2x  ddivby2.t2x  ie64comp.t2x

#---------------------------------- Rule --------------------------------------

# force build of OUTNAME
all:		$(OUTNAME)

$(OUTNAME):	$(EXPLICIT) $(OTHERS) $(UNSIGNEDSUPPORT) $(ICCT2X) $(ICCSUPPORT)
	$(CONCATENATE) $(EXPLICIT) $(OTHERS) $(UNSIGNEDSUPPORT) $(ICCT2X) $(ICCSUPPORT)  $(INTO)  $(OUTNAME)
	$(COPY) $(OUTNAME) occam2.lib
	$(DELETE) occamutl.lib


#--------------------------- files with dependencies ---------------------------
#
# We are booting ourselves up here - we have to create the a compiler 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
# $(@:.t2x=.p2x) is a macro which means replace the suffix of the target
# ( .t2x ) by the new suffix .p2x;  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.

# files that are related to single precision reals

r32op.t2x:    occamutl.lib r32op.occ
	$(PREPROCESSOR) $(@:.t2x=.occ) $(PREOPT)  $(SWITCH)o $(@:.t2x=.p2x)
	$(OCCAM) $(@:.t2x=.p2x)  $(OCCOPT) $(SWITCH)o $@
	$(DELETE) $(@:.t2x=.p2x)

r32operr.t2x: occamutl.lib r32operr.occ
	$(PREPROCESSOR) $(@:.t2x=.occ) $(PREOPT)  $(SWITCH)o $(@:.t2x=.p2x)
	$(OCCAM) $(@:.t2x=.p2x)  $(OCCOPT) $(SWITCH)o $@
	$(DELETE) $(@:.t2x=.p2x)

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

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

rargred.t2x:	r32operr.t2x i32tor32.t2x occamutl.lib rargred.occ
	$(LIBRARIAN) $(LIBOPT) r32operr.t2x i32tor32.t2x $(SWITCH)o $(TARGETLIB)
	$(PREPROCESSOR) $(@:.t2x=.occ) $(PREOPT)  $(SWITCH)o $(@:.t2x=.p2x)
	$(OCCAM) $(@:.t2x=.p2x)  $(OCCOPT) $(SWITCH)o $@
	$(DELETE) $(@:.t2x=.p2x)
	$(DELETE) $(TARGETLIB)

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

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

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


# files that are related to double precision reals

DSQRT2X=	i64bor.t2x   i64band.t2x  i64gt.t2x    \
		i64eq.t2x    i64rshft.t2x i64lshft.t2x

dsqrt.t2x:	$(DSQRT2X) dsqrt.occ
	$(LIBRARIAN) $(LIBOPT) $(DSQRT2X) $(SWITCH)o $(TARGETLIB)
	$(PREPROCESSOR) $(@:.t2x=.occ) $(PREOPT)  $(SWITCH)o $(@:.t2x=.p2x)
	$(OCCAM) $(@:.t2x=.p2x)  $(OCCOPT) $(SWITCH)o $@
	$(DELETE) $(@:.t2x=.p2x)
	$(DELETE) $(TARGETLIB)

r64toi16.t2x: occamutl.lib r64toi16.occ
	$(PREPROCESSOR) $(@:.t2x=.occ) $(PREOPT)  $(SWITCH)o $(@:.t2x=.p2x)
	$(OCCAM) $(@:.t2x=.p2x)  $(OCCOPT) $(SWITCH)o $@
	$(DELETE) $(@:.t2x=.p2x)

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

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

dabsfint.t2x:	r64gterr.t2x i64tor64.t2x r64toi64.t2x i64bor.t2x i64band.t2x dabsfint.occ
	$(LIBRARIAN) $(LIBOPT) r64gterr.t2x i64tor64.t2x r64toi64.t2x i64bor.t2x i64band.t2x $(SWITCH)o $(TARGETLIB)
	$(PREPROCESSOR) $(@:.t2x=.occ) $(PREOPT)  $(SWITCH)o $(@:.t2x=.p2x)
	$(OCCAM) $(@:.t2x=.p2x)  $(OCCOPT) $(SWITCH)o $@
	$(DELETE) $(@:.t2x=.p2x)
	$(DELETE) $(TARGETLIB)

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

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

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

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

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

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