#	Makefile	6.2	83/09/25

# kernel #defined prior 861210 (sdo)
# Try compiling without optimization to fix c2 rearranging stuff for us
# (bog, jht)
CFLAGS=	${COPTS}
COPTS=	-I../../ -I../../h ${DEFINES} -sed asm.sed
#
# Compile-time options.
# M68010, M68020: CPUs the code can run on.
# A45J:		  A particular mask of the 68020 that is special.
# STANDALONE for standalone stuff.
# HEINOUS to enable code that shouldd not be enabled (debugging only --
#	turns on LEDs, that sort of thing).
# SA_ADVANCED to compile libsa.a code with writes, stats, and other advanced
#	calls.  This option is controlled from within the makefile;  don't
#	enable it here.  Compiling without SA_ADVANCED produces a smaller
#	library for use with the boot code.
# USE_ERM to use Ed's Enhanced Resident Monitor with the code -- provides
#	magic debugging hooks.
#
BOOT_DEFINES=	-DM68020 -DM68010 -DSTANDALONE -DA45J -UDoSum \
	-DLITTLEBUFFER
SA_DEFINES=	-DM68020 -DM68010 -DSTANDALONE -DA45J -UDoSum \
	-DLITTLEBUFFER -DUSE_ERM
ADVFLAG=	-DSA_ADVANCED
RELOC=	2000
REL_BSS= 100000

CFILES=	autoconf.c conf.c header.c id.c it.c idioctl.c is.c machdep.c prf.c \
	rim.c sc.c sys.c sys1.c \
	toplevel.c ufs_alloc.c ../../sys/ufs_tables.c ufs_syscalls.c \
	ufs_inode.c ../../s32/errlst.c
HFILES=	dev.h isreg.h isvar.h rfreg.h saio.h sas32.h
SRCS=	${CFILES} ${HFILES}

# Full-on standalone library. The sum of LIBBOOT, LIBDEVS, and LIBADV.
LIBSA=		libsa.a
# Standalone code needed to make the boot code work.
LIBBOOT=	libboot.a

# Directory for placement of libsa's objects.
ADV_OBJ_DIR=	advanced
# Directory for placement of boot code's objects.
BOOT_OBJ_DIR=	boot

BOOT_OBJECTS=	\
	${BOOT_OBJ_DIR}/autoconf.o	\
	${BOOT_OBJ_DIR}/toplevel.o	\
	${BOOT_OBJ_DIR}/sys.o		\
	${BOOT_OBJ_DIR}/sys1.o		\
	${BOOT_OBJ_DIR}/conf.o		\
	${BOOT_OBJ_DIR}/prf.o		\
	${BOOT_OBJ_DIR}/sc.o		\
	${BOOT_OBJ_DIR}/rim.o		\
	${BOOT_OBJ_DIR}/rt.o		\
	${BOOT_OBJ_DIR}/it.o		\
	${BOOT_OBJ_DIR}/id.o		\
	${BOOT_OBJ_DIR}/is.o		\
	${BOOT_OBJ_DIR}/machdep.o

ADV_OBJECTS=	\
	${ADV_OBJ_DIR}/autoconf.o	\
	${ADV_OBJ_DIR}/toplevel.o	\
	${ADV_OBJ_DIR}/sys.o		\
	${ADV_OBJ_DIR}/sys1.o		\
	${ADV_OBJ_DIR}/ufs_syscalls.o	\
	${ADV_OBJ_DIR}/ufs_inode.o	\
	${ADV_OBJ_DIR}/ufs_alloc.o	\
	${ADV_OBJ_DIR}/ufs_tables.o	\
	${ADV_OBJ_DIR}/errlst.o	\
	${ADV_OBJ_DIR}/conf.o		\
	${ADV_OBJ_DIR}/prf.o		\
	${ADV_OBJ_DIR}/sc.o		\
	${ADV_OBJ_DIR}/rim.o		\
	${ADV_OBJ_DIR}/rt.o		\
	${ADV_OBJ_DIR}/idioctl.o	\
	${ADV_OBJ_DIR}/id.o		\
	${ADV_OBJ_DIR}/it.o		\
	${ADV_OBJ_DIR}/is.o		\
	${ADV_OBJ_DIR}/machdep.o

# Files we need from /lib/libc.a.
LIBC=	/lib/libc.a
LIBC_DIR=	libc
LIBC_OBJECTS=	\
	${LIBC_DIR}/almul.o	\
	${LIBC_DIR}/atoi.o	\
	${LIBC_DIR}/atol.o	\
	${LIBC_DIR}/bcopy.o	\
	${LIBC_DIR}/calloc.o	\
	${LIBC_DIR}/ctime.o	\
	${LIBC_DIR}/float.o	\
	${LIBC_DIR}/ftell.o	\
	${LIBC_DIR}/index.o	\
	${LIBC_DIR}/ldiv.o	\
	${LIBC_DIR}/lmul.o	\
	${LIBC_DIR}/malloc.o	\
	${LIBC_DIR}/rindex.o	\
	${LIBC_DIR}/strcat.o	\
	${LIBC_DIR}/strcpy.o	\
	${LIBC_DIR}/strcpyn.o	\
	${LIBC_DIR}/strlen.o	\
	${LIBC_DIR}/strncmp.o	\
	${LIBC_DIR}/strncpy.o	\
	${LIBC_DIR}/tell.o	\
	${LIBC_DIR}/telldir.o

ALL=	${LIBSA} ${LIBBOOT}

all:	${ALL}


# How to make the full-on Valid Standalone library.
# The library of advanced standalone I/O routines like creat, write and ioctl.
${LIBSA}: /tmp ${ADV_OBJ_DIR}
	make \
		"DESTINATION=${ADV_OBJ_DIR}"	\
		"LIB_OBJECTS=${ADV_OBJECTS} ${LIBC_OBJECTS}"	\
		"DEFINES=${SA_DEFINES} ${ADVFLAG}"	\
		${ADV_OBJ_DIR}/${LIBSA}
	-rm ${LIBSA}
	ln ${ADV_OBJ_DIR}/${LIBSA} ${LIBSA}


# The library of routines necessary to support the boot code.
${LIBBOOT}: /tmp ${BOOT_OBJ_DIR}
	make "DESTINATION=${BOOT_OBJ_DIR}"	\
		"DEFINES=${BOOT_DEFINES}"\
		"LIB_OBJECTS=${BOOT_OBJECTS} ${LIBC_OBJECTS}"	\
		${BOOT_OBJ_DIR}/${LIBBOOT}
	-rm ${LIBBOOT}
	ln ${BOOT_OBJ_DIR}/${LIBBOOT} ${LIBBOOT}

${BOOT_OBJ_DIR}/${LIBBOOT}: ${LIB_OBJECTS}
	rm -rf ${BOOT_OBJ_DIR}/${LIBBOOT}
	ar crv ${BOOT_OBJ_DIR}/${LIBBOOT} ${LIB_OBJECTS} ${LIB_OBJECTS}

${ADV_OBJ_DIR}/${LIBSA}: ${LIB_OBJECTS}
	rm -rf ${ADV_OBJ_DIR}/${LIBSA}
	ar crv ${ADV_OBJ_DIR}/${LIBSA} ${LIB_OBJECTS} ${LIB_OBJECTS}

# Sundry source we can recover from /lib/libc.a.
# (We really don't want to load with /lib/libc.a because it also includes all
# the UNIX system calls, and they ain't no system to call, Sunshine!)
${LIBC_OBJECTS}:	${LIBC} ${LIBC_DIR}
	ar xv ${LIBC} $@

# Individual source files.  My, but this is icky!
${DESTINATION}/autoconf.o:	autoconf.c
	cc -c ${CFLAGS} autoconf.c
	mv autoconf.o ${DESTINATION}/autoconf.o
${DESTINATION}/sc.o:		sc.c
	cc -c ${CFLAGS} sc.c
	mv sc.o ${DESTINATION}/sc.o
${DESTINATION}/rim.o:		rim.c
	cc -c ${CFLAGS} rim.c
	mv rim.o ${DESTINATION}/rim.o
${DESTINATION}/rt.o:		rt.c
	cc -c ${CFLAGS} rt.c
	mv rt.o ${DESTINATION}/rt.o
${DESTINATION}/idioctl.o:		idioctl.c
	cc -c ${CFLAGS} idioctl.c
	mv idioctl.o ${DESTINATION}/idioctl.o
${DESTINATION}/it.o:		it.c
	cc -c ${CFLAGS} it.c
	mv it.o ${DESTINATION}/it.o
${DESTINATION}/id.o:		id.c
	cc -c ${CFLAGS} id.c
	mv id.o ${DESTINATION}/id.o
${DESTINATION}/is.o:		is.c
	cc -c ${CFLAGS} is.c
	mv is.o ${DESTINATION}/is.o
${DESTINATION}/toplevel.o:	toplevel.c
	cc -c ${CFLAGS} toplevel.c
	mv toplevel.o ${DESTINATION}/toplevel.o
${DESTINATION}/sys.o:		sys.c
	cc -c ${CFLAGS} sys.c
	mv sys.o ${DESTINATION}/sys.o
${DESTINATION}/sys1.o:		sys1.c
	cc -c ${CFLAGS} sys1.c
	mv sys1.o ${DESTINATION}/sys1.o
${DESTINATION}/ufs_syscalls.o:	ufs_syscalls.c
	cc -c ${CFLAGS} ufs_syscalls.c
	mv ufs_syscalls.o ${DESTINATION}/ufs_syscalls.o
${DESTINATION}/ufs_inode.o:	ufs_inode.c
	cc -c ${CFLAGS} ufs_inode.c
	mv ufs_inode.o ${DESTINATION}/ufs_inode.o
${DESTINATION}/ufs_alloc.o:	ufs_alloc.c
	cc -c ${CFLAGS} ufs_alloc.c
	mv ufs_alloc.o ${DESTINATION}/ufs_alloc.o
${DESTINATION}/ufs_tables.o:	../../sys/ufs_tables.c
	cc -c ${CFLAGS} ../../sys/ufs_tables.c
	mv ufs_tables.o ${DESTINATION}/ufs_tables.o
${DESTINATION}/errlst.o:	../../s32/errlst.c
	cc -c ${CFLAGS} ../../s32/errlst.c
	mv errlst.o ${DESTINATION}/errlst.o
${DESTINATION}/conf.o:		conf.c
	cc -c ${CFLAGS} conf.c
	mv conf.o ${DESTINATION}/conf.o
${DESTINATION}/prf.o:		prf.c
	cc -c ${CFLAGS} prf.c
	mv prf.o ${DESTINATION}/prf.o
${DESTINATION}/machdep.o:	machdep.c
	cc -c ${CFLAGS} machdep.c
	mv machdep.o ${DESTINATION}/machdep.o

syslib syslib_p: ${OBJS}
#	@echo "building profiled syslib_p"

${ADV_OBJ_DIR} ${BOOT_OBJ_DIR} ${LIBC_DIR}:
	mkdir $@

# startups

startups:	ALWAYS
	make "DEFINES=${SA_DEFINES}" srt0.o relsrt0.o tpsrt0.o

srt0.o: srt0.c ../../s32/mtpr.h ../../s32/cpu.h
	cc -P -DRELOC=0x${RELOC} ${COPTS} srt0.c ; mv srt0.i srt0.s
	as -o srt0.o -ge srt0.s

tpsrt0.o: srt0.c ../../s32/mtpr.h ../../s32/cpu.h
	cc -P -DRELOC=0x${RELOC} -DTP ${COPTS} srt0.c ; mv srt0.i tpsrt0.s
	as -o tpsrt0.o -ge tpsrt0.s

relsrt0.o: srt0.c 
	cc -P -DRELOC=0x${RELOC} -DREL_BSS=0x${REL_BSS} -DREL \
		${COPTS} srt0.c ; mv srt0.i relsrt0.s
	as -o relsrt0.o -ge relsrt0.s

# Handy makefile stuff.

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

print:
	@pr makefile
	@ls -l | pr 
	@pr *.h *.c

clean:
	rm -f ${BOOT_OBJECTS} ${ADV_OBJECTS} ${LIBC_OBJECTS}\
		${BOOT_OBJ_DIR}/${LIBBOOT} ${LIBBOOT}\
		${ADV_OBJ_DIR}/${LIBSA} ${LIBSA}

lint:
	lint ${COPTS} -hxbn boot.c ${SRCS} | \
	    grep -v 'possible pointer alignment' | \
	    grep -v 'struct/union .* never defined'

install: ${ALL}
	cp tpcopy ${DESTDIR}/tp/copy
	cp tpboot ${DESTDIR}/tp/boot
	cp tpformat ${DESTDIR}/tp/format
	cp boot a.out; strip a.out; \
		dd if=a.out of=../floppy/boot bs=32 skip=1
	cp format a.out; strip a.out; \
		dd if=a.out of=../floppy/format bs=32 skip=1
	cp drtest a.out; strip a.out; \
		dd if=a.out of=../floppy/drtest bs=32 skip=1
# beware...
# DO NOT DELETE THIS LINE because ``make depend'' needs to see it!

autoconf.o: ../h/param.h ../h/systm.h ../h/buf.h ../h/dk.h ../h/vm.h
autoconf.o: ../h/conf.h ../h/dmap.h ../s32/cpu.h ../s32/trap.h
autoconf.o: ../s32dev/mbvar.h
conf.o: ../h/param.h ../h/inode.h ../h/fs.h saio.h
id.o: ../h/types.h ../h/param.h ../h/fs.h ../h/inode.h ../s32/vectors.h
id.o: ../s32/cpu.h ../s32/setjmp.h ../s32/dkio.h ../s32/dklabel.h ../h/errno.h
id.o: saio.h isreg.h isvar.h
it.o: ../h/types.h ../h/param.h ../h/fs.h ../h/inode.h ../s32/vectors.h
it.o: ../s32/cpu.h ../s32/setjmp.h ../s32/dkio.h ../s32/dklabel.h saio.h
it.o: isreg.h isvar.h rfreg.h ../h/errno.h
idioctl.o: ../h/types.h ../h/param.h ../h/fs.h ../h/inode.h ../s32/vectors.h
idioctl.o: ../s32/cpu.h ../s32/setjmp.h dk_types.h ../s32/dklabel.h saio.h
idioctl.o: isreg.h isvar.h s32_config.h
is.o: isreg.h isvar.h ../s32/cpu.h
machdep.o: ../h/param.h ../s32/cpu.h ../s32/clock.h sas32.h
prf.o: ../h/param.h ../s32/cpu.h
rim.o: ../h/param.h ../h/fs.h ../h/inode.h ../s32/vectors.h ../s32/cpu.h
rim.o: ../s32/setjmp.h ../s32/dkio.h saio.h sas32.h rfreg.h
sc.o: ../h/types.h ../h/param.h ../h/dir.h ../s32/reg.h ../h/map.h
sc.o: ../s32/setjmp.h ../s32/scCpu.h ../s32/necuart.h ../s32/clock.h
sc.o: ../s32/cpu.h
sys.o: ../h/param.h ../h/inode.h ../h/fs.h ../h/dir.h ../h/types.h ../h/stat.h
sys.o: ../h/errno.h ../h/file.h ../h/time.h saio.h
sys1.o: ../h/param.h ../h/inode.h ../h/fs.h ../h/dir.h ../h/types.h ../h/stat.h
sys1.o: ../h/errno.h ../h/file.h ../h/time.h ../machine/setjmp.h saio.h
toplevel.o: ../h/param.h ../h/inode.h ../h/fs.h ../h/dir.h ../h/types.h
toplevel.o: ../h/stat.h ../h/time.h ../h/errno.h ../h/file.h ../s32/setjmp.h
toplevel.o: saio.h
ufs_alloc.o: ../h/param.h ../h/systm.h ../h/mount.h ../h/fs.h ../h/conf.h
ufs_alloc.o: ../h/buf.h ../h/inode.h ../h/dir.h ../h/user.h ../h/quota.h
ufs_alloc.o: ../h/kernel.h saio.h
.../sys/ufs_tables.o: ../h/param.h
ufs_syscalls.o: ../h/types.h ../h/param.h ../h/file.h ../h/inode.h ../h/fs.h
ufs_syscalls.o: ../h/proc.h saio.h
ufs_inode.o: ../h/param.h ../h/systm.h ../h/mount.h ../h/dir.h ../h/user.h
ufs_inode.o: ../h/inode.h ../h/fs.h ../h/conf.h ../h/buf.h ../h/kernel.h saio.h
.../conn/conn.h: ../vnet/vnet.h
.../crm/bdtst.h: ../dklabel.h ../rfreg.h ../crm.h ../isreg.h ../isvar.h
.../crm/bdtst.h: ../dev.h
.../crm/crm.h: ../s32/setjmp.h cpu.h ecm.h rfreg.h dklabel.h isreg.h isvar.h
.../crm/crm.h: is.h dev.h sc.h tables.h bss.h
.../dfs/dfs.h: ../DOT/rpc.h ../DOT/dfs.h ../h/errno.h
.../dfs/dfs_ioctl.h: ../h/ioctl.h
.../efs/efs.h: ../DOT/rpc.h ../DOT/efs.h ../conn/conn.h
.../efs/efs_ioctl.h: ../h/ioctl.h
.../h/dk_types.h: sys/types.h s32/dkio.h
.../h/fs.h: ../h/param.h
.../h/inode.h: ../h/socket.h
.../h/ioctl.h: ../h/tty.h ../white/mouse.h
.../h/kernel.h: ../h/time.h
.../h/map.h: ../machine/cpu.h
.../h/mbuf.h: ../machine/pte.h ../h/vmmac.h
.../h/mtio.h: ../h/ioctl.h
.../h/param.h: ../machine/param.h ../machine/pte.h ../h/signal.h ../h/types.h
.../h/proc.h: ../h/time.h ../s32/context.h
.../h/quota.h: ../h/param.h
.../h/seg.h: ../machine/pte.h
.../h/sgtty.h: ../h/ioctl.h
.../h/socket.h: ../h/uio.h
.../h/tty.h: ../h/ttychars.h ../h/ttydev.h ../h/types.h
.../h/user.h: ../machine/pcb.h ../h/dmap.h ../h/time.h ../h/resource.h
.../h/user.h: ../h/signal.h ../s32/fpu68881.h ../h/quota.h ../h/inode.h
.../h/user.h: ../h/file.h ../h/fs.h ../h/tty.h ../h/dir.h ../h/errno.h
.../h/vm.h: ../h/vmparam.h ../h/vmmac.h ../h/vmmeter.h ../h/vmsystm.h
.../h/vmmac.h: ../machine/pte.h ../machine/cpu.h
.../h/vmparam.h: ../machine/vmparam.h
.../machine/context.h: ../machine/vmparam.h ../h/map.h
.../machine/cpu.h: ../h/types.h
.../machine/fpu68881.h: ../h/types.h
.../machine/frame.h: ../h/types.h
.../machine/mem.h: ../h/types.h ../machine/param.h ../machine/cpu.h
.../machine/necuart.h: ../s32/nec7201.h
.../machine/vmparam.h: ../machine/ecm.h
.../rpc/rpc.h: ../DOT/rpc.h
.../s32/context.h: ../machine/vmparam.h ../h/map.h
.../s32/cpu.h: ../h/types.h
.../s32/fpu68881.h: ../h/types.h
.../s32/frame.h: ../h/types.h
.../s32/mem.h: ../h/types.h ../machine/param.h ../machine/cpu.h
.../s32/necuart.h: ../s32/nec7201.h
.../s32/vmparam.h: ../machine/ecm.h
.../s32dev/is_ioctl.h: ../h/ioctl.h
.../s32dev/vg_ioctl.h: ../h/ioctl.h
.../s32dev/vp.h: ../h/ioctl.h
.../s32dev/vpb.h: ../h/ioctl.h
.../s32dev/vpreg.h: ../h/ioctl.h
.../usr.include/sgtty.h: ../h/ioctl.h
.../white/cvreg.h: ../white/config.h
