#  Makefile  -  install and test the fortran multiple precision library
#	        mpfun.f  and the automatic translator  transmp  from
#		David Bailey, NASA Ames Research Center, dbailey@nas.nasa.gov
#
#  Source:   netlib (research.att.com), /toms/719.Z, 24 sept 1993
#
#  System:   Linux omicron 0.99.12 #7 Mon Sep 20 1993 i486
#	     gcc version 2.4.5, i486
#	     f2c, FORTRAN 77 to C Translator, VERSION 22 July 1992  22:54:52
#
#  Modifications:
#		1) Implement IMPLICIT AUTOMATIC lines 724,1352 in transmp.f
#
#		2) Promote the first argument of MPDMC to double precision
#		        in the definition of MPEPS in transmp.f, line 4662
#		     21   FORMAT (6X,'CALL MPDMC (DBLE(',A,'), ',A,', MPEPS)')
#
#		3) Implement the optimisation in  /usr/bin/f77
#			set -- `getopt cD:gI:N:O:o:Suw6 "$@"`
#			-O)	case $2 in [123456]) O=-O$2;   shift;;
#			        *) echo "Missing level -O?";  exit 1;; esac
#				CCFLAGS="$CCFLAGS $O";         shift;;
#
#  Problem:  The crucial BLOCK DATA is included automatically by mptrans via a
#     call to mpsetp since bdata.f was added to mpsetp.f before compilation.
#     But if transmp/mpsetp is not used, bdata.o has to be linked in directly.
#
#  Jacques Gelinas, Ph.D., Maths, C.M.R., oct 93,  gelinas@cmr.ca
#

default what:
	@echo	"testmp		-	perform 64 standard mpfun tests (first!)"
	@echo	"testran		-	test  the f77 -> mpfun tranlator"
	@echo	"one    		-	one simple test of mpfun: exp(1), ln(exp(1))"
	@echo	"cheb    	-	chebycheff coefficients of sin(x)/x from f77"
	@echo	"cheb.mp    	-	chebycheff coefficients of sin(x)/x from mpfun"
	@echo	"cheb.bc   	-	chebycheff coefficients of sin(x)/x from bc"
	@echo	"install  	-	/usr/local/bin/transmp, /usr/lib/mpfun.a"
	@echo	"uninstall  	-	/usr/local/bin/transmp, /usr/lib/mpfun.a"
	@echo	"explode		-	first try at exploding toms archive 719.Z"
	@echo	"libmp		-	build the multiple precision library (need source)"
	@echo	"trans		-	build the f77 -> mpfun translator    (need source)"
	@echo	"clean		-	remove test files"
	@echo	"veryclean	-	remove library and translator"

testmp:		libmp.a testmp.f bdata.f
	f77 -O2 -o testmp testmp.f bdata.f -L. -lmp
	testmp | tee testmp.out

testran:	testran.f transmp libmp.a
	transmp < testran.f > tranout.f
	f77 -O2 -o tranout tranout.f -L. -lmp
	tranout | tee tranout.out
	diff -s testran.out tranout.out

install:	libmp.a transmp
	cp -i transmp /usr/local/bin
	cp -i libmp.a /usr/lib

uninstall:	
	rm -i /usr/local/bin/transmp
	rm -i /usr/lib/libmp.a

one:	one.f
	f77 -o one one.f; one
	expand one.f|sed 's/ 200/ 100/'|transmp >one.mp.f
	f77 -o one.mp one.mp.f -L. -lmp; one.mp
	expand one.f|transmp >one.mp.f
	f77 -o one.mp one.mp.f -L. -lmp; one.mp
	expand one.f|sed 's/ 200/ 1000/'|transmp >one.mp.f
	f77 -o one.mp one.mp.f -L. -lmp; one.mp

libmp:		explode
	( cd src; f77 -O6 -c *.f; rm testmp.o testran.o transmp.o;\
	  ar qs ../libmp.a *.o; rm -f *.o )

explode:	719.Z  explode.awk
	-mkdir src
	( cd src; zcat ../719.Z | awk -f ../explode.awk | sh -v )
	awk 'NR<14' src/testran.out > testran.out
	awk 'NR>13' src/testran.out > mpfun.doc

trans:		src/transmp.f
	f77 -O6 -o transmp src/transmp.f

cheb:		cheb.f
	f77 -o cheb cheb.f; time cheb

cheb.mp:	cheb.mp.f
	f77 -o cheb.mp cheb.mp.f -L. -lmp; time cheb.mp

cheb.mp.f:	cheb.f
	expand cheb.f | transmp > cheb.mp.f

cheb.bc:	cheb.bcl
	time bc -l cheb.bcl

clean:
	rm -f *~ *.o core* testmp testmp.o testmp.out  transmp.o tranout*
	rm -f cheb cheb.mp cheb.mp.f one one.mp one.mp.f

veryclean:	clean
	rm -f mpfun.a transmp
