#
# Main Makefile
#
# $Id: Makefile,v 5.4 1999/11/09 01:03:45 danielp Exp $
#
# Revision 5.0 99/01/11 danielp
#  Added rules for building boot disks.
#
# create a link called usermain to point to the current user directory.

include Makeconf

TOOLDIR		= $(HOME)/local/bin-$(ARCH)
#SYSGEN		= $(TOOLDIR)/sysgen
SYSGEN		= ../sysgendit/sysgen/sysgen
MAKE		= /usr/local/bin/make 
OBJSTRIP	= $(TOOLDIR)/objstrip
IMAGEDIR	= images
FLOPPYDEV	= /dev/rfd0a

l4image: lib/all libc/all usermain/all pal/all sigma0/all drivers/serial
	@echo "Generating L4 Image from PAL, Sigma0 and User"
	$(SYSGEN) -v -a -e0 pal/l4pal -e20000 -c sigma0/sigma0  -d -e22000 DIT -e24000 -r -c drivers/serial -e2A000 -r -b -c usermain/user -o l4image

sl4image: lib/all user/all pal/all sigma0/all
	@echo "Generating L4 Image from PAL, Sigma0 and User"
	$(SYSGEN) -v -a -e0 pal/l4pal -e20000 -c sigma0/sigma0  -d -e22000 DIT -e24000 -r -b -c user/user -r -c -e28000 user/simple -o l4image

# image for UX test
ul4image: lib/all user/all pal/all sigma0/all
	@echo "Generating L4 Image from PAL, Sigma0 and User"
	$(SYSGEN) -v -a -e0 pal/l4pal -e220000 -c sigma0/sigma0  -e222000 -c user/user -o ul4image


l4base: lib/all pal/all sigma0/all drivers/serial

boot: l4image
	scp l4image $$CVSLOGIN@os:/boot/alpha/

usermain/all:
	$(MAKE) -C usermain

pal/all:
	$(MAKE) -C pal

lib/all:
	$(MAKE) -C lib
#	(cd ../l4thread/src/alpha/; $(MAKE))

libc/all:
	 $(MAKE) -C lib/libc

drivers/serial:
	$(MAKE) -C drivers

# create boot block and boot disk for SRM
srmdisk: $(IMAGEDIR)/dbm/EB164DBM.CMP
	@printf "\nSRM boot disk creation.\nPress Return to continue, Ctrl-C to abort.\n"
	@read X
	@printf "Calculating boot block..\n"
	@$(OBJSTRIP) -v -p $(IMAGEDIR)/dbm/EB164DBM.CMP $(IMAGEDIR)/srm/mboot
	@printf "Building SRM root disk..\n"
	@cat $(IMAGEDIR)/srm/mboot $(IMAGEDIR)/dbm/EB164DBM.CMP > $(FLOPPYDEV)
	@printf "Done creating SRM debug console disk.\n"

# builds arc/AlphaBIOS/debug compatible boot disk
# must be FAT formatted.
# if you are using AlphaBIOS you must insert the appropiate rules to tell the 
# bios what to boot.
imagedisk: l4image
	@printf "\nBuilding L4/Alpha boot disk.. \nCopying AlphaBIOS image loader.."
	@mcopy $(IMAGEDIR)/arc/linload.exe a:linload.exe
	@mcopy $(IMAGEDIR)/arc/uxliload.exe a:uxliload.exe
	@printf "Copying 21164 debug console..\n"
	@mcopy $(IMAGEDIR)/dbm/EB164DBM.CMP a:ebdb
	@printf "Copying L4/Alpha image..\n"
	@mcopy l4image a:l4image
	@printf "Done creating boot disk.\n"

fatformat:
	@printf "\nFormatting HD disk. \nPress Return to continue, Ctrl-C to abort.\n"
	@read X
	@gunzip -c  $(IMAGEDIR)/arc/blankFAT.img.gz | dd of=$(FLOPPYDEV)
	@mformat -t 80 -h 2 -s 18 -l l4 a:
	@printf "Done Formatting disk.\n"

reloc: 
	cd ../l4relocate && \
	$(MAKE) clean && \
	$(MAKE) boot

sigma0/all:
	$(MAKE) -C sigma0

sysgendit:
	cd ../sysgendit/sysgen && \
		$(MAKE) clean && \
		$(MAKE)

clean:
	rm -Rrf *~ *.o l4image mboot bootm
	cd pal && \
	$(MAKE) clean
	cd lib && \
	$(MAKE) clean
	cd sigma0 && \
	$(MAKE) clean
	cd lib/libc && \
	$(MAKE) clean
	cd usermain && \
	$(MAKE) clean

depend:
	cd pal && \
	$(MAKE) depend

tags:
	cp /dev/null TAGS
	find . -name '*.S' | xargs -n 99 /usr/local/bin/etags --append -l asm
	find . -name '*.h' | xargs -n 99 /usr/local/bin/etags --append
	find . -name '*.S' -o -name '*.h' | xargs /usr/local/bin/etags --append --regex='/\.MACRO[ \t]+\([^ \t]+\)/\1/' -l none
	find . -name '*.S' -o -name '*.h' | xargs /usr/local/bin/etags --append --regex='/.*\.REG+\(.*\)/\1/' -l none

# DO NOT DELETE THIS LINE
