#  "$Header: makefile.s32,v 820.1 86/12/04 19:42:27 root Exp $";
#  "%W% %Y% %Q% %G%";

#
# Makefile for 4.2 BSD
#
# This makefile is constructed from a machine description:
#	config machine
# Most changes should be made in the machine description
#	/sys/conf/``machineid''
# after which you should do
#	 config machineid
# Generic makefile changes should be made in
#	/sys/conf/makefile
# after which config should be rerun for all machines.
#
# N.B.: NO DEPENDENCIES ON FOLLOWING FLAGS ARE VISIBLE TO MAKEFILE
#	IF YOU CHANGE THE DEFINITION OF ANY OF THESE RECOMPILE EVERYTHING
#
# -DTRACE	compile in kernel tracing hooks
# -DQUOTA	compile in file system quotas
# -DSWABIPS	compile in code to byte swap ip packets on 3Mb/s Ethernet
#
#	The following are folded into the definiton "s32":
#
#		JAMDEBUG, NEWRPC, MAPUPPER64K, USE_FIXED_POINT,
#		IOCTL4_1C, SYSCALLTRACE, VALID_CLOCKFIX, PGINPROF
#		DISKMON, GETSYSERROR, KGCLOCK
#
C2=	/bin/c2
AS=	/bin/as -ge
# Do not load vmunix demand-paged.
LD=	/bin/ld -N
TOUCH=	touch -f -c

COPTS=	${IDENT} -DKERNEL

#
# CFLAGS is not used by '/usr/valid/bin/config' when it builds the '${CC}' lines
#
CFLAGS=	-O ${COPTS}

STANDOBJS= almul.o blt.o clear.o float.o ldiv.o lmul.o strcpy.o strcmp.o \
	strlen.o strncpy.o

%OBJS

%CFILES

%LOAD

clean:
	rm -f eddep *vmunix tags *.o locore.c locore.i *.s libstand.a \
		kernsyms errs linterrs makelinks

lint: /tmp
	@lint -hbxn -I. -DGENERIC ${COPTS} ../s32/Locore.c \
	  ${CFILES} ../s32/swapgeneric.c ioconf.c | \
	    grep -v ' rcsid never used' | \
	    grep -v ' sccsid never used' | \
	    grep -v 'struct/union .* never defined' | \
	    grep -v 'possible pointer alignment problem'

../s32/symbols.sort: ../s32/symbols.raw
	rm -f ../s32/symbols.sort
	grep -v '^#' ../s32/symbols.raw \
	    | sed 's/^	//' | sort -u > ../s32/symbols.sort

locore.o : assym.s ../s32/locore.s
	rm -f locore.o locore.c locore.i
	cat assym.s ../s32/locore.s > locore.c
	${CC} -I. -DLOCORE ${COPTS} -P -E locore.c > locore.i
	${AS} -o locore.o locore.i

libstand.a : /lib/libc.a
	rm -rf libstand.a libstand.dir
	mkdir libstand.dir
	cd libstand.dir ; ar x /lib/libc.a ${STANDOBJS}
	cd libstand.dir ; ar r ../libstand.a ${STANDOBJS}
	rm -rf libstand.dir


# the following is necessary because autoconf.o depends on #if GENERIC
autoconf.o: makefile

# depends on network configuration
af.o : makefile

# depends on maxusers
assym.s: makefile


.PRECIOUS : ../machine/pte.h

../machine/pte.h :
	rm -f ../machine
	-ln -s s32 ../machine

../machine/param.h :
	rm -f ../machine
	-ln -s s32 ../machine


#
#	Deal with '/lib/cpp'-s ambigious sense of '.'
#	in the context of nested include-files
#	of the same leaf-name (when one leaf references the other);
#	but the leaves are in different subtrees:
#
../DOT:	makefile
	rm -f ../DOT
	-ln -s `pwd` ../DOT

assym.s: ../h/param.h ../machine/pte.h ../h/buf.h ../h/vmparam.h \
    ../h/vmmeter.h ../h/dir.h ../h/cmap.h ../h/map.h \
    ../h/proc.h ../h/msgbuf.h ../s32/genassym.c ../s32/vmparam.h
	rm -f assym.s a.out
	cc ${COPTS} ${PARAM} ../s32/genassym.c; ./a.out >assym.s; rm -f a.out

kernsyms : ../conf/kernsyms.c
	rm -f kernsyms
	cc ../conf/kernsyms.c -o kernsyms

touchlist: ../h/param.h ../h/tty.h ../h/ioctl.h ../h/user.h ../h/vm.h
	${TOUCH} touchlist

../h/param.h: ../h/signal.h
	${TOUCH} ../h/param.h
../h/tty.h:  ../h/ttychars.h ../h/ttydev.h
	${TOUCH} ../h/tty.h
../h/ioctl.h: ../h/sgtty.h ../h/ttychars.h ../h/ttydev.h
	${TOUCH} ../h/ioctl.h
../h/user.h: ../s32/pcb.h ../h/dmap.h ../h/types.h \
    ../h/errno.h
	${TOUCH} ../h/user.h
../h/vm.h: ../h/vmmac.h ../h/vmmeter.h ../h/vmparam.h ../h/vmsystm.h
	${TOUCH} ../h/vm.h

#
# Build the kernel-dependent utilities
#
UTIL_DIR=../etc
UTILS=	ps pstat vmstat iostat adb config

#
# Note that to obtain the kernel compile-time options, the individual
# utilities' makefiles must reference COPTS.
#
${UTILS}:	/tmp
	cd ${UTIL_DIR}/$@; make COPTS="${IDENT} ${PARAM}" clean $@
	cp ${UTIL_DIR}/$@/$@ .


depend:
	rm -f makedep eddep		junk.fileList
	grep '^#include' ${CFILES} >	junk.fileList
	grep '^#include' ../*/*.h >>	junk.fileList
	grep -v '<'		  <	junk.fileList | \
	sed -e 's/:[^"]*"\([^"]*\)".*/: \1/' \
	    -e 's/\.c/.o/' \
	    -e 's,^../[a-zA-Z0-9]*/[a-zA-Z0-9]*\.h,./&,' \
	    -e 's,^../[a-zA-Z0-9]*/,,' \
	    -e 's,\./\.\./,../,' >	junk.sedList
	awk ' { if ($$1 != prev) { print rec; rec = $$0; prev = $$1; } \
		else { if (length(rec $$2) > 78) { print rec; rec = $$0; } \
		       else rec = rec " " $$2 } } \
	      END { print rec } ' <	junk.sedList	> makedep
	echo '/^# DO NOT DELETE THIS LINE/+1,$$d' >eddep
	echo '$$r makedep' >>eddep
	echo 'w' >>eddep
	rm -f makefile.bak
	mv makefile makefile.bak
	cp makefile.bak makefile
	chmod u+w makefile
	ex - makefile < eddep
	rm -f eddep makedep junk.fileList junk.sedList



links:
	egrep '#if' ${CFILES} | sed -f ../conf/defines | \
	  sed -e 's/:.*//' -e 's/\.c/.o/' | sort -u > dontlink
	echo ${CFILES} | tr -s ' ' '\12' | sed 's/\.c/.o/' | \
	  sort -u | comm -23 - dontlink | \
	  sed 's,../.*/\(.*.o\),rm -f \1;ln -s ../GENERIC/\1 \1,' > makelinks
	sh makelinks && rm -f dontlink

tags:
	rm -f tags
	ctags	 -t ${CFILES}
	ctags -a -t \
		../h/*.h ../s32/*.h ../net/*.h ../netinet/*.h ../conn/*.h \
		../efs/*.h ../dfs/*.h ../rpc/*.h

print:
	@pr -f makefile ../sys/TODO linterrs
	@/usr/ucb/ctags -x ${CFILES} | pr -f -h XREF
	@(size vmunix *.o) | pr -f -h sizes
	@ls -ls | pr -f
	@cd ../h; ls -ls | pr -f ; pr -f *.m *.h
	@echo 'once upon a time ...'
	@cd ../sys; pr -f asm.sed Locore.c scb.s locore.s
	@pr -f ${CFILES}

ioconf.o: ioconf.c ../h/param.h ../machine/pte.h ../h/buf.h ../h/map.h \
    ../h/vm.h ../s32dev/mbvar.h
	rm -f ioconf.o
	${CC} -I. -c -O ${COPTS} ioconf.c

param.c: ../conf/param.c
	rm -f param.c
	cp ../conf/param.c .

param.o: param.c makefile
	rm -f param.o
	${CC} -I. -c ${CFLAGS} ${PARAM} param.c

%RULES

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

