# File: bsps/Makefile
# Purpose: Makefile for bsps directory
# Author: Phil Bunce (pjb@carmel.com)
# Revision History:
#	981031	Start of revision history

include $(LSIPKG)/defines.mk


DRIVERS   = d4001.c d4003.c d4011.c d4101.c d4102.c
SUPPORT1  = iceif.c printd.c imon.c
SUPPORT2  = 400x.c 401x.c
KERNELS   = k4001.s
OTHERS    = Makefile iceif.h README accesstst.s defs.h i4102.s

TARGETS4101 = k4101 d4101
TARGETS4011 = k4011 d4011 k4011-4k
TARGETS4102 = k4102 d4102 i4102
TARGETS64388 = k64388

ALLTARGETS = $(TARGETS4101) $(TARGETS4011) $(TARGETS4102) \
	$(TARGETS64388) accesstst.ocm accesstst.o
ALLTARGS = k4101.x d4101.x k4011.x d4011.x k4011-4k.x k4102.x d4102.x \
	k64388.x

ALLENVS = pmon 4101 4101-rom 4102 4102-rom 4011 4011-rom 64388

ALLOBJS = $(DVROBJS) $(DRIVERS:.c=.o) $(DRIVERS:.c=) $(KERNELS:.s=) \
	  $(KERNELS:.s=.o) $(SUPPORT1:.c=.o) $(SUPPORT2:.c=.o) mxops.o \
	  vers.o

nothing:
	@echo Please specify the intended execution environment.
	@echo "usage: make <env>"
	@echo envs: all 4101 4011 4102 64388

all: 4101 4011 4102 64388

# These 2 targets are really just intended for testing.
allbe : be.flg
	$(MAKE) TFLAG=-EB $(ALLENVS)
allle : le.flg
	$(MAKE) TFLAG=-EL $(ALLENVS)

clean:
	@$(RMF) $(ALLOBJS:.o=.rec) $(ALLOBJS) $(ALLTARGETS) \
	$(ALLTARGS:.x=.rec) $(ALLTARGS:.x=.tmp) $(ALLTARGS:.x=.lk) \
	$(ALLTARGS:.x=.map) $(ALLTARGS:.x=.o) be.flg le.flg

CFILES  = $(DRIVERS) $(SUPPORT1) $(SUPPORT2) $(CSTARTUP)
ASFILES = $(KERNELS) $(ASSTARTUP)
TL = $(LSIPKG)/tape.lst
tape: revhistory
	@mklst bsps $(CFILES) $(ASFILES) $(OTHERS) version >> $(TL)

be.flg le.flg :
	$(MAKE) clean
	@echo "$@" > $@

zipfile:
	csh -c zip `dt '+%y%m%d%H'`.zip $(CFILES) $(ASFILES) $(OTHERS) \
	version mbd.c kmbd.s feaccess.s

newrev:
	@newversion $(NVSW)

revhistory : $(CFILES) $(ASFILES) $(OTHERS)
	@newversion $(NVSW)

depend:
	@csh -c makedepend -I$(LSIPKG)/include -DPMCC $(CFILES) \
	$(ASFILES)
	@perl $(FIXDEPENDS) Makefile


###### for kernels
KERNLINK = $(TFLAG) -crt0 -prom -syms -T bfc00000
# The bfc00000 has been chosen because it will force the kernel
# code (in ROM) to run from non-cacheable space. This is required because
# the kernel doesn't flush the caches. It has no data or bss sections.

###### for drivers
DVROBJS   = $(SUPPORT1:.c=.o) mxops.o vers.o
DVRFLAGS  = $(TFLAG) -driver -srec


4011 : $(TARGETS4011)
4101 : $(TARGETS4101)
4102 : $(TARGETS4102)
64388 : $(TARGETS64388)
pmon 4101-rom 4011-rom 4102-rom :
	@echo The programs in this directory cannot be built for $@.


################### kernels
k4001 : k4001.s
	pmcc $(KERNLINK) -o $@ k4001.s
k4101 : ../lib/k4101.s
	pmcc $(KERNLINK) -o $@ ../lib/k4101.s
k4011 : ../lib/k4011.s
	pmcc $(KERNLINK) -o $@ ../lib/k4011.s
k4011-4k : ../lib/k4011.s
	pmcc $(KERNLINK) -DR4KEXCEPTIONS -o $@ ../lib/k4011.s
k4102 : ../lib/k4102.s
	pmcc $(KERNLINK) -o $@ ../lib/k4102.s
k64388 : ../lib/k64388.s
	pmcc $(KERNLINK) -o $@ ../lib/k64388.s

#################### drivers
d4001 : $(DVROBJS) d4001.o 400x.o
	pmcc $(DVRFLAGS) -o $@ $(DVROBJS) d4001.o 400x.o
d4003 : $(DVROBJS) d4003.o 400x.o
	pmcc $(DVRFLAGS) -o $@ $(DVROBJS) d4003.o 400x.o
d4011 : $(DVROBJS) d4011.o 401x.o
	pmcc $(DVRFLAGS) -o $@ $(DVROBJS) d4011.o 401x.o
d4101 : $(DVROBJS) d4101.o 400x.o
	pmcc $(DVRFLAGS) -o $@ $(DVROBJS) d4101.o 400x.o
d4102 : $(DVROBJS) d4102.o 400x.o
	pmcc $(DVRFLAGS) -o $@ $(DVROBJS) d4102.o 400x.o

#################### access routine example
# an ocm access routine for serialice1.dll
accesstst.ocm : ../accesstst.s
	pmcc $(TFLAG) -crt0 -o accesstst ../accesstst.s
	$(RMF) accesstst.o accesstst.map accesstst accesstst.tmp
	rdsrec -m accesstst.rec > accesstst.ocm
	$(RMF) accesstst.rec accesstst.lk

# an ocm access routine for IMON driver
accesstst.o : ../accesstst.s
	pmcc $(TFLAG) -c -DLABEL=accesstst ../accesstst.s

#################### ejtag init modules
i4102 : i4102.s
	pmcc -crt0 -T 0 -o $@ i4102.s

#################### files
mxops.o : ../mon/mxops.c
	pmcc $(TFLAG) -G 0 -c -o $@ ../mon/mxops.c
vers.c : version
	mkmsg vers -f version > vers.c

