# Makefile for the boot monitor package.
#
CC=	exec cc
CC86=	exec cc

# ACK ANSI C compiler
CFLAGS=	-I.. -wo
STRIP=	-s
IRREL=	-m
LD=	$(CC) -s -r
LD86=	$(CC86) -s -r
HEAD=	/usr/lib/head.o
LIBS=
o=	o
s=	s
# end
## ACK K&R compiler
#CFLAGS=	-I..
#STRIP=
#IRREL=
#LD=	exec asld
#LD86=	exec asld
#HEAD=	/usr/lib/head.s
#LIBS=	/usr/lib/libc.a /usr/lib/end.s
#o=	s
#s=	x
## end

all:	bootblock boot masterboot installboot edparams # init

installboot.$o demolish bootimage.$o: image.h
boot.$o bootimage.$o: boot.h
rawfs.$o rawfs86.$o installboot.$o boot.$o bootimage.$o: rawfs.h

bootblock:	bootblock.$s
	$(LD86) bootblock.$s -o bootblock

masterboot:	masterboot.$s
	$(LD86) masterboot.$s -o masterboot

boot.$o:	boot.c
	$(CC86) $(CFLAGS) $(IRREL) -c boot.c

bootimage.$o:	bootimage.c
	$(CC86) $(CFLAGS) -c bootimage.c

rawfs86.$o:	rawfs.c rawfs.$o
	-ln rawfs.c rawfs86.c 2>/dev/null
	$(CC86) $(CFLAGS) -c rawfs86.c
	rm rawfs86.c
	-cmp -s rawfs.$o rawfs86.$o && rm rawfs86.$o && ln rawfs.$o rawfs86.$o

boot:	boothead.$s boot.$o bootimage.$o rawfs86.$o
	$(LD86) boothead.$s -i boot.$o bootimage.$o rawfs86.$o $(LIBS) -o boot
	@chmem =12000 boot >/dev/null

installboot:	installboot.$o rawfs.$o
	$(CC) $(STRIP) -i -o installboot installboot.$o rawfs.$o
	@chmem =12288 installboot >/dev/null

edparams:	edparams.c
	$(CC) $(CFLAGS) $(STRIP) $(IRREL) -i -o edparams edparams.c
	@chmem =32768 edparams >/dev/null

demolish:	demolish.c
	$(CC) $(CFLAGS) $(STRIP) -i -o demolish demolish.c
	@chmem =8192 demolish >/dev/null

init:	$(HEAD) init.c
	$(LD) $(HEAD) init.c $(LIBS) -o init

# Use e.g. 'make image image=/minix', to make an image elsewhere
image=image
PROGRAMS=	../kernel/kernel ../mm/mm ../fs/fs

image:	all
	cd ../kernel; exec make
	cd ../mm; exec make
	cd ../fs; exec make
	cd ../tools; exec make init
	installboot -image $(image) $(PROGRAMS) ../tools/init

floppy:	image
	@getlf "Insert a blank diskette in drive 0 and hit return"
	installboot -boot /dev/fd0 bootblock boot $(image)

net_image=net_image
AM_PROGS=	../amoeba/kernel/kernel ../amoeba/mm/mm ../amoeba/fs/fs

net:	all
	cd ../amoeba/kernel; exec make
	cd ../amoeba/mm; exec make
	cd ../amoeba/fs; exec make
	cd ../tools; exec make init
	installboot -image $(net_image) $(AM_PROGS) ../tools/init
	@getlf "Insert a blank diskette in drive 0 and hit return"
	installboot -boot /dev/fd0 bootblock boot $(net_image)

clean:
	rm -f *.bak *.$o

realclean:	clean
	rm -f bootblock installboot boot masterboot demolish edparams

tar:
	tar cvf monitor.tar Makefile boot.c boot.h bootblock.s \
		boothead.s bootimage.c image.h installboot.c masterboot.s \
		rawfs.c rawfs.h man config demolish.c edparams.c

dist:
	test -d cat || mkdir cat
	nroff -man man/README.nr | colcrt - > README
	nroff -man man/installboot.8 | colcrt - > cat/installboot.8
	nroff -man man/monitor.8 | colcrt - > cat/monitor.8
	nroff -man man/demolish.8 | colcrt - > cat/demolish.8
	#
	tar cf - Makefile boot.c boothead.s | compress -b13 > mon1.tar.Z
	tar cf - README boot.h bootimage.c image.h installboot.c masterboot.s \
			| compress -b13 > mon2.tar.Z
	tar cf - rawfs.c rawfs.h edparams.c man | compress -b13 > mon3.tar.Z
	tar cf - bootblock.s config demolish.c cat | compress -b13 > mon4.tar.Z
	for i in mon?.tar.Z; do uue $$i; rm $$i; done
	wc mon?.uue
