#
# $Header: makefile,v 10.0 86/07/21 14:52:50 bog Exp $
#

CFLAGS=	-O ${COPTS}  -sed asm.sed
COPTS=	-DDEBUG -DDEBUG2 -DDEBUG3 -I../../h -DM68020 -DM68010 -DSTANDALONE -DSA_TEST -DUSE_ERM -DJMP_ERM

# Absolute location of text segment (expected by CRM TBOOT).
RELOC=	20000
# Stack groweth down from here in all standalone executable images.
REL_BSS= 180000

STARTUPS= srt0.o tpsrt0.o relsrt0.o

SRCS=	mkfs.c cat.c cpio.c

# Constants related to the standalone library
STANDALONE_DIR=	../salib
LIBSA=	${STANDALONE_DIR}/libsa.a
RELSRT= relsrt0.o
ERMLIB=	../erm/erm.a
KERNSYMS = ../../ENG/kernsyms

ALL=	mkfs cat cpio


all: ${ALL}

#Startup objects - standard, tape-loaded and relocatable.

${LIBSA}:	/tmp
	cd ${STANDALONE_DIR}; make libsa.a

# bootable from tape

# Just in case:
#	cd ${STANDALONE_DIR}; make relsrt0.o RELOC=${RELOC}\
#		REL_BSS=${REL_BSS} DEFINES="${COPTS}"

# Downloadable mkfs.
mkfs:	mkfs.o ${LIBSA} ${STARTUPS}
	@vers mkfs
	rm -f vers.o
	${CC} $(CFLAGS) -c vers.c
	ld -N -x -T ${RELOC} -B ${REL_BSS} \
		${RELSRT} mkfs.o \
			${LIBSA} ${ERMLIB} ${ERMLIB} ${LIBSA} vers.o
	${KERNSYMS} a.out
	cp a.out mkfs
	strip a.out
	dd if=a.out of=mkfs.dl ibs=32 skip=1

# Downloadable cat (can you believe it??).
cat:	cat.o ${LIBSA} ${STARTUPS}
	@vers cat
	rm -f vers.o
	${CC} $(CFLAGS) -c vers.c
	ld -N -x -T ${RELOC} -B ${REL_BSS} \
		${RELSRT} cat.o \
			${LIBSA} ${ERMLIB} ${ERMLIB} ${LIBSA} vers.o
	${KERNSYMS} a.out
	cp a.out sa_cat
	strip a.out
	dd if=a.out of=cat.dl ibs=32 skip=1

# Downloadable cpio program (can you believe it??).
cpio:	cpio.o ${LIBSA} ${STARTUPS}
	@vers cpio
	rm -f vers.o
	${CC} $(CFLAGS) -c vers.c
	ld -N -x -T ${RELOC} -B ${REL_BSS} \
		${RELSRT} cpio.o \
			${LIBSA} ${ERMLIB} ${ERMLIB} ${LIBSA} vers.o
	${KERNSYMS} a.out
	cp a.out cpio
	strip a.out
	dd if=a.out of=cpio.dl ibs=32 skip=1

${STARTUPS}:	ALWAYS
	cd ${STANDALONE_DIR}; make ${STARTUPS} RELOC=${RELOC}\
		REL_BSS=${REL_BSS} DEFINES="${COPTS}"
	for srt in ${STARTUPS}; do cp ${STANDALONE_DIR}/$$srt . ; done

# bootstrap from ether

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

# getting booted from disc

# utilities

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

clean:
	rm -rf *.dl mkfs cpio sa_cat *.o

lint:
	lint ${COPTS} -hxbn ${SRCS}

#
#	    grep -v 'possible pointer alignment' | \
#	    grep -v 'struct/union .* never defined'
#

install: ${ALL}

pad.64k:
	@echo "VALID LOGIC SYS" > pad1.tmp
	@/bin/cat pad1.tmp pad1.tmp > pad2.tmp ; /bin/cat pad2.tmp pad2.tmp > pad1.tmp
	@/bin/cat pad1.tmp pad1.tmp > pad2.tmp ; /bin/cat pad2.tmp pad2.tmp > pad1.tmp
	@/bin/cat pad1.tmp pad1.tmp > pad2.tmp ; /bin/cat pad2.tmp pad2.tmp > pad1.tmp
	@/bin/cat pad1.tmp pad1.tmp > pad2.tmp ; /bin/cat pad2.tmp pad2.tmp > pad1.tmp
	@/bin/cat pad1.tmp pad1.tmp > pad2.tmp ; /bin/cat pad2.tmp pad2.tmp > pad1.tmp
	@/bin/cat pad1.tmp pad1.tmp > pad2.tmp ; /bin/cat pad2.tmp pad2.tmp > pad1.tmp
	@mv pad1.tmp pad.64k
	@rm -f pad?.tmp

