#
# 5799-WZQ (C) COPYRIGHT IBM CORPORATION 1987,1988
# LICENSED MATERIALS - PROPERTY OF IBM
# REFER TO COPYRIGHT INSTRUCTIONS FORM NUMBER G120-2083
#
# $Header:Makefile 12.0$ 
# $ACIS:Makefile 12.0$ 
# $Source: /ibm/acis/usr/src/usr.lib/libm/RCS/Makefile,v $ 

#
#	@(#)Makefile	4.9	9/11/85
#
SCCSID = "@(#)Makefile	4.9 9/11/85"
#
# This high quality math library is intended to run on either a VAX in
# D_floating format or a machine that conforms to the IEEE standard 754
# for double precision floating-point arithmetic.
#
# WARNING: On machines other than the ones mentioned above, run the original
# Version 7 math library, if nothing better is available.

# ARITH indicates the type of floating point arithmetic used; legal
# values are:
#
# VAX           - VAX D - format (56 - bit precision)
# IEEE          - IEEE double format (53 - bit precision)

ARITH = IEEE

#
# MACH indicates the type of floating point hardware you are using; legal
# values are:
#
# IBMRT         - for the IBM RTPC, the default.
# VAX		- for the VAX D_floating format.
# NATIONAL	- for those IEEE machines whose floating point implementation
#		  has similar byte ordering as the NATIONAL 32016 with 32081.
# IEEE		- for other IEEE machines, we hope.
#

MACH = IBMRT

#
# machine directories under the IEEE directory
#
MACHINES = IBMRT IEEE NATIONAL

MACHDIR = ${ARITH}/${MACH}

#
# invoke object-code optimizer with appropriate MACH and ARITH definition
#
CFLAGS=-O -D${ARITH} -D${MACH} -DRTFL

INSTALL= install

DESTDIR=


#
# Files comprising the standard Math library;
# actually there are more under ${ARITH}/ subdirectory.
#

SRCS =	atan.c atanh.c erf.c floor.c j0.c j1.c jn.c fmod.c

OBJS =	atan.o atanh.o erf.o floor.o j0.o j1.o jn.o fmod.o         

TAGSFILE=tags

CC = FP_PRECISION=double cc

.c.o:
####	generate additional code for profiling (-p)
	${CC} -p ${CFLAGS} -c $*.c
####	generate relocation bits (-r) 
####    & preserve local symbols except those begining with L (-X)
	-ld -X -r $*.o
	mv a.out profiled/$*.o
	${CC} ${CFLAGS} -c $*.c
####	generate relocation bits (-r) but don't preserve local symbols (-x)
	-ld -x -r $*.o
	mv a.out $*.o

all: libm.a libm_p.a

libm.a libm_p.a: ${OBJS} arithfiles
	mkdir tmp
	cp *.o tmp
	cd tmp; ar x ../${ARITH}/${ARITH}lib
	ar cru libm.a `ls tmp/*.o | sort -t +1`
	rm -f tmp/*
	cp profiled/*.o tmp
	cd tmp; ar x ../${ARITH}/${ARITH}lib_p
	ar cru libm_p.a `ls tmp/*.o | sort -t +1`
	rm -f -r tmp

arithfiles:
	@cd ${ARITH}; make "CC=${CC}" "MACH=${MACH}" "CFLAGS=${CFLAGS}"

install: libm.a libm_p.a
	-rm -f ${DESTDIR}/usr/lib/libnm.a ${DESTDIR}/usr/lib/libnm_p.a
	${INSTALL} libm.a ${DESTDIR}/usr/lib
	ln ${DESTDIR}/usr/lib/libm.a ${DESTDIR}/usr/lib/libnm.a
	ranlib ${DESTDIR}/usr/lib/libm.a
	${INSTALL} libm_p.a ${DESTDIR}/usr/lib
	ln ${DESTDIR}/usr/lib/libm_p.a ${DESTDIR}/usr/lib/libnm_p.a
	ranlib ${DESTDIR}/usr/lib/libm_p.a

tags:
	(cd ${ARITH}; make ${MFLAGS} MACH=${MACH} TAGSFILE=../${TAGSFILE} tags)
	cwd=`pwd`; \
	for i in ${SRCS}; do \
		ctags -a -f ${TAGSFILE} $$cwd/$$i; \
	done

clean:
	-rm -f *.o profiled/*.o libm.a libm_p.a tags
	cd ${ARITH}; rm -f *.o profiled/*.o ${ARITH}lib ${ARITH}lib_p
	-rm -f ${MACHDIR}/*.o ${MACHDIR}/profiled/*.o 
	-rm -f ${MACHDIR}/${MACH}lib ${MACHDIR}/${MACH}lib_p

cleanall:
	rm -f *.o profiled/*.o libm.a libm_p.a tags
	cd VAX; rm -f *.o profiled/*.o VAXlib VAXlib_p
	cd IEEE; rm -f *.o profiled/*.o IEEElib IEEElib_p; \
	for i in ${MACHINES}; do (cd $$i; rm -f *.o profiled/*.o \
	$${i}lib $${i}lib_p); done
