# $Header: Makefile_ca,v 12.0 88/11/16 17:47:08 ericm dec88 $
# $Source: /ibm/acis/usr/src/usr.bin/RCS/Makefile_ca,v $
#
#	Makefile	4.29	83/08/20
#
DESTDIR=
CFLAGS=	-O
IFLAGS=-c -s

# Programs that live in subdirectories, and have makefiles of their own.
#
SUBDIR=	at calendar dc diction diff3 efl eqn f77 find graph learn \
	lex lint m4 nroff neqn plot prof ratfor refer spell struct \
	tbl tip troff uucp xsend yacc

# Shell scripts that need only be installed and are never removed.
#
SCRIPT=	install lorder nohup

# C programs that live in the current directory and do not need
# explicit make lines.
#
# NOTYET ar11 tc tk
STD=	basename cal cb checkeq col comm crypt deroff \
	file join look mesg ptx ranlib rev sleep sort spline \
	split sum tabs touch tr tsort tty uniq units 

# C programs that live in the current directory and need explicit make lines.
# (make depend has special rules for these files)
#
NSTD=	bc egrep fgrep
KMEM=	iostat

all:	${SUBDIR} ${STD} ${NSTD} ${KMEM}

${SUBDIR}: FRC
	cd $@; make ${MFLAGS}

FRC:

bc egrep:
	${YACC} ${YFLAGS} $@.y
	${CC} -c ${CFLAGS} y.tab.c
	mv y.tab.o $@.o
	${CC} -o $@ $@.o
	rm -f $@.o

${STD} ${KMEM}:
	${CC} ${CFLAGS} -o $@ $@.c

install: all
	for i in ${SUBDIR}; do \
		(cd $$i; make ${MFLAGS} DESTDIR=${DESTDIR} install ); done
	for i in ${SCRIPT}; do (install -c $$i.sh ${DESTDIR}/usr/bin/$$i); done
	for i in ${STD} ${NSTD}; do \
		(install ${IFLAGS} $$i ${DESTDIR}/usr/bin/$$i); \
	done
	for i in ${KMEM}; do \
		(install -s -g kmem -m 2755 $$i ${DESTDIR}/usr/bin/$$i); done
	install -c units.lib ${DESTDIR}/usr/lib/units

clean:
	rm -f a.out core *.s *.o y.tab.c
	for i in ${SUBDIR}; do (cd $$i; make ${MFLAGS} clean); done
	rm -f ${STD} ${NSTD} ${KMEM}

# beware of the non-standard stuff for bc and egrep
depend:
	for i in ${STD} ${KMEM} fgrep; do \
	    ${CC} -M ${CFLAGS} ${INCPATH} $$i.c | sed 's/\.o//' | \
	    awk ' { if ($$1 != prev) \
		{ if (rec != "") print rec; rec = $$0; prev = $$1; } \
		else { if (length(rec $$2) > 78) { print rec; rec = $$0; } \
		else rec = rec " " $$2 } } \
		END { print rec } ' >> makedep; done
	for i in bc egrep; do \
	    ${CC} -M ${CFLAGS} ${INCPATH} $$i.y | sed 's/\.o//' | \
	    awk ' { if ($$1 != prev) \
		{ if (rec != "") print rec; rec = $$0; prev = $$1; } \
		else { if (length(rec $$2) > 78) { print rec; rec = $$0; } \
		else rec = rec " " $$2 } } \
		END { print rec } ' >> makedep; done
	echo '/^# DO NOT DELETE THIS LINE/+2,$$d' >eddep
	echo '$$r makedep' >>eddep
	echo 'w' >>eddep
	cp Makefile Makefile.bak
	ed - Makefile < eddep
	rm eddep makedep
	echo '# DEPENDENCIES MUST END AT END OF FILE' >> Makefile
	echo '# IF YOU PUT STUFF HERE IT WILL GO AWAY' >> Makefile
	echo '# see make depend above' >> Makefile

# Files listed in ${NSTD} have explicit make lines given below.

# Following files have explicit make lines because they
# are big and should be linked to be demand paged.

fgrep: fgrep.c
	${CC} ${CFLAGS} -o fgrep fgrep.c

# DO NOT DELETE THIS LINE -- make depend uses it
