#	Makefile	1.0	83/07/02
# $Header:Makefile 12.0$
# $ACIS:Makefile 12.0$
# $Source: /ibm/acis/usr/src/lib/libc/ca/gen/RCS/Makefile,v $
#
# ********* N.B. -R switch below is so that floating point emulator
#      and .s files it depends on are in text segment only, to be
#      linked into the kernel
#
CSRCS = abs.c atof.c bcmp.c copysign.c disktab.c dknu.c dknu16.c drem.c \
	ecvt.c fpabort.c fpclass.c \
	swapfpflag.c swapfptrap.c swapround.c fpnext.c frexp.c index.c \
	insque.c l10.c ldexp.c modf.c mul211.c mulu211.c mulu32.c \
	rad2a.c rindex.c rint.c scalb.c shlun.c spdiv7.c tentothe.c
SSRCS = abort.s alloca.s blt.s bzero.s c19d.s clear.s compat.s cvd10.s \
	ffs.s fpfpx2.s index.s ldiv.s lmul.s rindex.s setjmp.s \
	drem_rtfl.s fabs_rtfl.s fpflag_rtfl.s fpround_rtfl.s fptrap_rtfl.s \
	scalb_rtfl.s rint_rtfl.s whichfpa_rtfl.s \
	strcat.s strcmp.s strcpy.s strlen.s strncmp.s uldiv.s ulrem.s umf2x.s
OBJS =  atof.o modf.o frexp.o ldexp.o bcmp.o blt.o bzero.o clear.o \
	compat.o disktab.o insque.o ldiv.o lmul.o setjmp.o uldiv.o \
	abort.o ecvt.o index.o rindex.o strcat.o strcmp.o \
	strcpy.o strlen.o strncmp.o abs.o c19d.o umf2x.o cvd10.o \
	copysign.o rint.o drem.o fpclass.o fpnext.o scalb.o alloca.o ffs.o \
	fpfpx2.o tentothe.o l10.o shlun.o mulu32.o spdiv7.o rad2a.o mul211.o \
        dknu16.o dknu.o mulu211.o  strncmp.o \
	swapfpflag.o swapfptrap.o swapround.o fpabort.o

RTFLOBJS = drem_rtfl.o fabs_rtfl.o fpflag_rtfl.o fpround_rtfl.o fptrap_rtfl.o \
	scalb_rtfl.o rint_rtfl.o whichfpa_rtfl.o

ALLOBJS= ${OBJS} ${RTFLOBJS}
CFLAGS=	-O -DRTFL
LD=	/bin/ld
TAGSFILE=tags

.s.o:
	/lib/cpp -E -DPROF $*.s >$*.cpp.s
	${AS} -o $*.o $*.cpp.s
	${LD} -X -r $*.o
	mv a.out profiled/$*.o
	/lib/cpp -E $*.s >$*.cpp.s
	${AS} -R -o $*.o $*.cpp.s
	${LD} -x -r $*.o
	mv a.out $*.o
	rm $*.cpp.s

.c.o:
	${CC} -p -c ${CFLAGS} $*.c
	${LD} -X -r $*.o
	mv a.out profiled/$*.o
	${CC} -c ${CFLAGS} $*.c
	${LD} -x -r $*.o
	mv a.out $*.o

all: genlib

genlib genlib_p: ${ALLOBJS}
	@echo "building profiled genlib"
	@cd profiled; ar cru ../genlib_p ${ALLOBJS}
	@echo "building normal genlib"
	@ar cru genlib ${ALLOBJS}

compat.o:	compat.s
	/lib/cpp -E -DPROF $*.s >$*.cpp.s
# need to save fpa address in data area so needs to be 
# writeable and thus this as without the -R option
	${AS} -o $*.o $*.cpp.s 
	${LD} -x -r $*.o
	cp a.out profiled/$*.o
	mv a.out $*.o
	rm $*.cpp.s

${RTFLOBJS}: rtflgen.h
	/lib/cpp -E -DPROF $*.s >$*.cpp.s
	${AS} -o $*.o $*.cpp.s
	${LD} -X -r $*.o
	mv a.out profiled/$*.o
	/lib/cpp -E $*.s >$*.cpp.s
	${AS} -o $*.o $*.cpp.s
	${LD} -x -r $*.o
	mv a.out $*.o
	rm $*.cpp.s

tags:
	cwd=`pwd`; \
	for i in ${CSRCS}; do \
		ctags -a -f ${TAGSFILE} $$cwd/$$i; \
	done

clean:
	rm -f ${OBJS} ${RTFLOBJS} errs a.out core tags genlib genlib_p
	(cd profiled; rm -f ${OBJS} ${RTFLOBJS} )
