#	Makefile	6.2	83/09/25

DESTDIR=/
# Kernel #defined prior to 121086 (bog)
CFLAGS=	-O ${COPTS} 
COPTS=	-I../../h -I../salib -I../../crm -DM68020 -DM68010 \
	-DSTANDALONE -DA45J -UDoSum -sed asm.sed
730OPTS=-O -DSTANDALONE -DVAX730
RELOC=	2000
REL_BSS= 100000
TP_REL_BSS= 100000

SRCS=	sys.c conf.c prf.c machdep.c \
	autoconf.c hp.c hpmaptype.c ht.c idc.c mba.c mt.c rk.c \
	rl.c tm.c ts.c \
	up.c upmaptype.c uba.c uda.c ut.c \
	drtest.c format.c up.old.c hp.old.c
#DRIVERS=autoconf.o hp.o hpmaptype.o ht.o idc.o mba.o mt.o \
	rk.o rl.o tm.o ts.o \
	up.o upmaptype.o uba.o uda.o ut.o
# These drivers don't have ecc correction and bad sector forwarding;
# they are placed in the file system boot area for 750's.  If your
# root has bad sectors you can try and squeeze the newer drivers in...
#ODRIVERS=hp.old.o up.old.o

DRIVERS=autoconf.o sc.o rim.o id.o is.o
LIBMODS=sys.o conf.o prf.o machdep.o
OLDRIVERS=

# Constants related to the standalone library
STANDALONE_DIR=	../salib
LIBBOOT=	${STANDALONE_DIR}/libboot.a


ALL=	boot satpboot

all: ${ALL}


${LIBBOOT}: /tmp
	cd ${STANDALONE_DIR}; make libboot.a
	
${ODRIVERS} ${DRIVERS}: savax.h
	cc -c -O ${COPTS} $*.c

# startups

srt0.o: /tmp
	cd ${STANDALONE_DIR}; make srt0.o
	cp ${STANDALONE_DIR}/srt0.o srt0.o

tpsrt0.o: /tmp
	cd ${STANDALONE_DIR}; make tpsrt0.o
	cp ${STANDALONE_DIR}/tpsrt0.o tpsrt0.o

relsrt0.o: /tmp
	cd ${STANDALONE_DIR}; make relsrt0.o
	cp ${STANDALONE_DIR}/relsrt0.o relsrt0.o

# bootable from tape

satpboot:	satpboot.o $(LIBBOOT)
	cd ${STANDALONE_DIR}; make relsrt0.o RELOC=${RELOC}\
		REL_BSS=${TP_REL_BSS}
	mv ${STANDALONE_DIR}/relsrt0.o relsrt0.o
	@sh vers.sh TapeBoot
	rm -f vers.o
	${CC} $(CFLAGS) -c vers.c
	ld -N -x -T ${RELOC} -B ${TP_REL_BSS} relsrt0.o satpboot.o\
		${LIBBOOT} vers.o 
#	../ENG/kernsyms a.out
	cp a.out b.out; strip b.out; dd if=b.out of=satpboot ibs=32 skip=1; rm b.out
	cat satpboot ../dii/pad.64k > satpboot.tmp
	dd if=satpboot.tmp of=satpboot.final bs=4k count=12
	rm satpboot.tmp

tpboot:	tpboot.o relsrt0.o libsa.a
	ld -N -B ${REL_BSS} -T ${RELOC} relsrt0.o tpboot.o libsa.a -lc
	cp a.out b.out; strip b.out; dd if=b.out of=tpboot ibs=32 skip=1; rm b.out

tpboot.o: boot.c ../h/param.h ../h/inode.h ../h/fs.h
tpboot.o: saio.h ../h/reboot.h ../h/vm.h 
	cp boot.c tpboot.c; chmod +w tpboot.c
	cc -c -O -DJUSTASK tpboot.c
	rm tpboot.c

tpcopy:	copy.o tpsrt0.o libsa.a
	ld  tpsrt0.o copy.o libsa.a -lc
	cp a.out b.out; strip b.out; \
		dd if=b.out of=tpcopy ibs=32 skip=1; rm b.out

tpformat: format.o tpsrt0.o confhpup.o libsa.a
	cp format.c tpformat.c; chmod +w tpformat.c
	cc -c -O -DJUSTEXIT tpformat.c
	rm tpformat.c
	ld tpsrt0.o tpformat.o confhpup.o libsa.a -lc
	cp a.out b.out; strip b.out; \
		dd if=b.out of=tpformat ibs=32 skip=1; rm b.out

# bootable from floppy or real disks

boot:	boot.o ${LIBBOOT}
	cd ${STANDALONE_DIR}; make relsrt0.o RELOC=${RELOC}\
		REL_BSS=${REL_BSS}
	mv ${STANDALONE_DIR}/relsrt0.o relsrt0.o
	@sh vers.sh Boot
	rm -f vers.o
	${CC} $(CFLAGS) -c vers.c
	ld -N -x -T ${RELOC} -B ${REL_BSS} relsrt0.o boot.o\
		${LIBBOOT} vers.o
	cp a.out b.out; strip b.out; dd if=b.out of=boot ibs=32 skip=1; rm b.out
	cat boot ../dii/pad.64k > boot.tmp
	dd if=boot.tmp of=boot.final bs=4k count=12
	rm boot.tmp

boot.flags:	boot boot.o relsrt0.o bootconf.o libsa.a
	cp boot boot.flags
	echo "idebug?w 100;sys_debug?w 100" | adb -w boot.flags
	dd if=boot.flags of=boot.flags.final bs=32 skip=1

bootconf.o: conf.c ../h/param.h ../h/inode.h ../s32/pte.h
bootconf.o: ../h/fs.h saio.h
	cp conf.c bootconf.c
	cc -c ${COPTS} -DBOOT bootconf.c
	rm bootconf.c

copy:	copy.o srt0.o conf.o libsa.a
	ld -o copy srt0.o copy.o conf.o libsa.a -lc

format:	format.o srt0.o confhpup.o libsa.a
	ld -o format srt0.o format.o confhpup.o libsa.a -lc

drtest:	drtest.o srt0.o confhpup.o libsa.a
	ld -o drtest srt0.o drtest.o confhpup.o libsa.a -lc

sum:	sum.o srt0.o conf.o libsa.a
	ld -o sum srt0.o sum.o conf.o libsa.a -lc

# bootstrap from ether

### not yet, rosin, not yet ###

# getting booted from disc

# utilities

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

clean:
	rm -f *.o *.exe *.i errs
	rm -f a.out b.out boot cat tpboot tpcopy copy tpformat
	rm -f boot[a-z]? boot[a-wyz][a-z].c conf[a-wyz][a-z].c
	rm -f format drtest core sboot bootconf.c

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...
