#	crt0	Normal C run time startoff
#	mcrt0	C run time start off for profiling, ``prof'' conventions
#	gcrt0	C run time start off for profiling, ``gprof'' conventions

CFLAGS=	-O -DLIBC_SCCS
OBJS=	crt0.o mcrt0.o gcrt0.o
FPOBJ=  fpglue.o
CLEANFILES+=	gmon.o mon.o moncrt0.o fpglue.o fpglue_p.o

# This awk script exit's 1 if any output is found.
# The ex scripts should be silent.
STDOUTCK= awk 'BEGIN{X=0}{X=1;print}END{exit X}'

all: ${OBJS}

crt0.o: crt0.c crt0.ex ${FPOBJ}
	${CC} -S -DCRT0 ${.IMPSRC}
#	sed -e 's;_start;start;g' -e '1s;$$;	j	start;' crt0.s >x.s
	${.CURDIR}/crt0.ex crt0.s | ${STDOUTCK}
	${AS} -o x.o crt0.s
	${LD} -x -r -o ${.TARGET} x.o ${FPOBJ}
	rm -f x.s x.o crt0.s

moncrt0.o: crt0.c moncrt0.ex ${FPOBJ} 
	${CC} -S -DMCRT0 ${.CURDIR}/crt0.c
#	sed -e 's;_start;start;g' -e '1s;$$;	j	start;' crt0.s >x.s
	${.CURDIR}/moncrt0.ex crt0.s | ${STDOUTCK}
	${AS} -o x.o crt0.s
	${LD} -x -r -o ${.TARGET} x.o fpglue_p.o
	rm -f x.s x.o crt0.s

mcrt0.o: moncrt0.o mon.o
	${LD} -x -r -o ${.TARGET} moncrt0.o mon.o

gcrt0.o: moncrt0.o gmon.o
	${LD} -x -r -o ${.TARGET} moncrt0.o gmon.o

mon.o:	mon.c mon.ex
	${CC} -S ${DEFS} ${.IMPSRC}
	${.CURDIR}/mon.ex mon.s | ${STDOUTCK}
	${AS} -o x.o mon.s
	${LD} -x -r -o ${.TARGET} x.o
	rm -f x.o mon.s

gmon.o: gmon.c gmon.h gmon.ex
	${CC} -S ${DEFS} ${.IMPSRC}
	${.CURDIR}/gmon.ex gmon.s | ${STDOUTCK}
	${AS} -o x.o gmon.s
	${LD} -x -r -o ${.TARGET} x.o
	rm -f x.o gmon.s

fpglue.o: fpglue.s
	${CPP} ${.IMPSRC} > $*.cpp.s
	${AS} -o $*.o $*.cpp.s
	rm $*.cpp.s
	${CPP} -DPROFILE ${.IMPSRC} > $*_p.cpp.s
	${AS} -o $*_p.o $*_p.cpp.s
	rm $*_p.cpp.s

install:
	install -c -o ${BINOWN} -g ${BINGRP} -m 444 ${OBJS} \
	    ${DESTDIR}/usr/lib

depend lint tags:

.include <bsd.prog.mk>
