
include ../Makeconf

TOOLDIR = $(HOME)/local/bin-$(ARCH)
CPP	= cpp 
AS      = $(TOOLDIR)/gas
LD      = $(TOOLDIR)/gld
DIS 	= $(TOOLDIR)/alist
IMAGE   = -a
PVC	= $(TOOLDIR)/pvc
STRIP   = $(TOOLDIR)/astrip
MAKEDEP = $(CPP) -MM -I../include
GASP	= $(TOOLDIR)/gasp.new -u
CAT	= cat

ECHO	= echo

LDOPT	= -Tstrip 0x200000 -Thdr -N

ASFLAGS	= -21164

# Source files:
#
#   This is the only block in which the list of source files should change.
#
#	SFILES - assembler source files
#	OFILES - output files
#


SFILES  = l4pal.S platform.S ipc.S pagefault.S memory.S thread.S memmap.S kdebug.S kernel.S

# Interrupt initialisation
ifdef INIT_INTERRUPTS
#ifdef CONFIG_EB164
#undef INIT_INTERRUPTS
#endif

ifdef CONFIG_MIATA
SFILES += sys_miata.S miata_memsize.S
endif

ifdef CONFIG_RUFFIAN
SFILES += sys_ruffian.S ruffian_memsize.S
endif
endif # INIT_INTERRUPTS

ifdef CONFIG_EB164
SIFLES += generic_memsize.S
endif

OFILES	= $(SFILES:.S=.o)


DEFINES		= -I../include $(CFLAGS)

.SUFFIXES:
.SUFFIXES: .S .s .c .o

.S.o:
	@(echo -n "Assembling $< ..."; \
	  nr=$<.$$$$; $(CPP) $(DEFINES) $< > /tmp/cpp_tmp.$$nr &&\
	  $(GASP) /tmp/cpp_tmp.$$nr > /tmp/gasp_tmp.$$nr &&\
	  $(AS) $(ASFLAGS) -o $*.o /tmp/gasp_tmp.$$nr &&\
	  rm /tmp/cpp_tmp.$$nr; echo " done.")

.c.o:
	$(CC) $(CCOPT) -c -o $*.o $<

l4pal: $(OFILES) 
	@echo -n "\nLinking ..."
	@$(LD) $(LDOPT) -o l4pal $(OFILES)
#	$(DIS) -f l4pal > l4pal.lis
	@echo " done."



#----------------------------------------------------------------------
# Version number generation ;-)
#

version.inc: $(SFILES) 
	@(if [ ! -e .version ]; then echo "0" > .version; fi)
	@(VERSION=`cat .version`; VERSION=`expr $$VERSION + 1`; echo $$VERSION > .version; \
	echo "Generate Build Version #"$$VERSION"" ;\
	echo "#define VERSION_TIME 	.ascii \""`date`\" > version.inc; \
	echo "#define VERSION_COMPILED 	.ascii \"Compiled by "$$USER"\"" >> version.inc ;\
	echo "#define VERSION_BUILD 	.ascii \"Build Release #"$$VERSION"\"" >> version.inc )

kernel.o:	version.inc


#----------------------------------------------------------------------


list:  l4pal
	$(DIS) -f l4pal > list

l4pal.nh: l4pal
	$(STRIP) l4pal $@

l4pal.map: l4pal
	$(DIS) -m l4pal > $@

l4pal.ent: l4pal
	$(DIS) -e l4pal | grep -v MSG_ > $@

pvc:  list l4pal.nh l4pal.ent l4pal.map
	(export PVC_PAL PVC_ENTRY PVC_MAP;      \
         PVC_PAL=l4pal.nh;                     \
         PVC_ENTRY=l4pal.ent;                  \
         PVC_MAP=l4pal.map;                    \
         cat pvc.cmd | $(PVC) > pvc.log;)

pvcia:  list l4pal.nh l4pal.ent l4pal.map
	(export PVC_PAL PVC_ENTRY PVC_MAP;      \
         PVC_PAL=l4pal.nh;                     \
         PVC_ENTRY=l4pal.ent;                  \
         PVC_MAP=l4pal.map;                    \
         $(PVC);)

clean:
	rm -f *~ *.o l4pal list *.lst

depend:
	@cat < /dev/null > makedep
	@(for i in $(SFILES); do echo $$i; \
	    $(MAKEDEP) $(DEFINES) $$i |						\
		awk '{ if ($$1 != prev) {if (rec != "") print rec;		\
		    rec = $$0; prev = $$1; }					\
		    else { if (length(rec $$2) > 78) { print rec; rec = $$0; }	\
		    else rec = rec " " $$2 } }					\
		    END { print rec }' | sed 's/\.o/\.o/'			\
		    >> makedep; done)
	@echo '/^# DO NOT DELETE THIS LINE/+1,$$d' > eddep
	@echo '$$r makedep' >> eddep
	@echo 'w' >> eddep
	@cp Makefile Makefile.bak
	@ed - Makefile < eddep
	@rm -f eddep makedep
	@echo '# DEPENDENCIES MUST END AT END OF FILE' >> Makefile
	@echo '# IF YOU PUT STUFF HERE IT WILL GO AWAY' >> Makefile
	@echo '# see make depend above' >> Makefile

# DO NOT DELETE THIS LINE
l4pal.o:	l4pal.S ../include/pal/predef.h ../include/pal/dc21164.h
l4pal.o:	../include/pal/macros.h ../include/pal/regdef.h ../include/pal/l4pal.h
l4pal.o:	  ../include/pal/palcalls.h ../include/pal/debug.h
l4pal.o:	../include/pal/gasp.h ../include/pal/platform.h
platform.o:	platform.S ../include/pal/predef.h ../include/pal/dc21164.h
platform.o:	../include/pal/platform.h ../include/pal/macros.h
platform.o:	../include/pal/regdef.h ../include/pal/l4pal.h
platform.o:	  ../include/pal/palcalls.h ../include/pal/gasp.h
platform.o:	../include/pal/handlers/sys_interrupts.h
platform.o:	  ../include/pal/handlers/sys_miata.h ../include/pal/pyxis.h
ipc.o:	ipc.S ../include/pal/predef.h ../include/pal/dc21164.h
ipc.o:	../include/pal/regdef.h ../include/pal/macros.h ../include/pal/l4pal.h
ipc.o:	  ../include/pal/palcalls.h ../include/pal/gasp.h ../include/pal/debug.h
ipc.o:	../include/pal/platform.h
pagefault.o:	pagefault.S ../include/pal/predef.h ../include/pal/dc21164.h
pagefault.o:	../include/pal/regdef.h ../include/pal/macros.h
pagefault.o:	../include/pal/l4pal.h ../include/pal/palcalls.h
pagefault.o:	../include/pal/gasp.h
memory.o:	memory.S ../include/pal/predef.h ../include/pal/dc21164.h
memory.o:	../include/pal/regdef.h ../include/pal/macros.h
memory.o:	../include/pal/l4pal.h ../include/pal/palcalls.h
memory.o:	../include/pal/gasp.h
thread.o:	thread.S ../include/pal/predef.h ../include/pal/dc21164.h
thread.o:	../include/pal/macros.h ../include/pal/regdef.h
thread.o:	../include/pal/platform.h ../include/pal/l4pal.h
thread.o:	  ../include/pal/palcalls.h ../include/pal/debug.h
thread.o:	../include/pal/gasp.h
memmap.o:	memmap.S ../include/pal/predef.h ../include/pal/dc21164.h
memmap.o:	../include/pal/regdef.h ../include/pal/macros.h
memmap.o:	../include/pal/l4pal.h ../include/pal/palcalls.h
memmap.o:	../include/pal/gasp.h
kdebug.o:	kdebug.S ../include/pal/predef.h ../include/pal/dc21164.h
kdebug.o:	../include/pal/macros.h ../include/pal/regdef.h
kdebug.o:	../include/pal/l4pal.h ../include/pal/palcalls.h
kdebug.o:	../include/pal/debug.h ../include/pal/gasp.h
kernel.o:	kernel.S ./version.inc ../include/pal/predef.h
kernel.o:	../include/pal/dc21164.h ../include/pal/platform.h
kernel.o:	../include/pal/macros.h ../include/pal/regdef.h
kernel.o:	../include/pal/l4pal.h ../include/pal/palcalls.h
kernel.o:	../include/pal/gasp.h ../include/pal/debug.h
sys_miata.o:	sys_miata.S ../include/pal/predef.h ../include/pal/dc21164.h
sys_miata.o:	../include/pal/macros.h ../include/pal/regdef.h
sys_miata.o:	../include/pal/platform.h ../include/pal/l4pal.h
sys_miata.o:	  ../include/pal/palcalls.h ../include/pal/debug.h
sys_miata.o:	../include/pal/gasp.h ../include/pal/pyxis.h
# DEPENDENCIES MUST END AT END OF FILE
# IF YOU PUT STUFF HERE IT WILL GO AWAY
# see make depend above
