
#PLATFORM=-DPMAX
#REL_PLATFORM=pmax

PLATFORM=-DSUN3
REL_PLATFORM=sun3

#PLATFORM=-DSUN4
#REL_PLATFORM=sun4

TOOLS=tools.$(REL_PLATFORM)
VERS=pcomp/version.ex

HOME=../..


C_SUBD=shared cleanup
P_SUBD=pcomp expgen scald/source expdiff
HOST_SUBD=pc ibm vax
EX=pcomp/pcomp.sex expgen/expgen.sex scald/source/comp.sex \
   expdiff/expdiff.ex cleanup/remove
KIT=validcompiler.*.ms *.v valid.index input.index scaldkit.* installation.time
PRODUCED= */*.ex */*.sex */*/*.ex */*/*.sex \
*/*.dbg */*/*.dbg */*.list */*/*.list */*.map */*/*.map \
shared/bigfile shared/lcshorten \
cleanup/remove cleanup/funclist */*.mk */*/*.mk $(KIT) \
expgen/expgenaccess scald/source/compaccess

final:
	for i in $(C_SUBD) ; do (\
	    cd $$i;\
	    make "PLATFORM=$(PLATFORM)" "REL_PLATFORM=$(REL_PLATFORM)" "RANLIB=$(RANLIB)" "DEBUG=$(DEBUG)"\
        ); done
	for i in $(P_SUBD) ; do (\
	    cd $$i;\
	    make "PLATFORM=$(PLATFORM)" "REL_PLATFORM=$(REL_PLATFORM)" "RANLIB=$(RANLIB)" "DEBUG=$(DEBUG)" "PFLAGS=$(PFLAGS)"\
        ); done


s32:	ALWAYS
	for i in $(C_SUBD) ; do (\
	    cd $$i;\
	    make "PLATFORM=$(PLATFORM)" "REL_PLATFORM=$(REL_PLATFORM)" "RANLIB=$(RANLIB)" \
        ); done
	for i in $(P_SUBD) ; do (\
	    cd $$i;\
	    make "PLATFORM=$(PLATFORM)"  "REL_PLATFORM=$(REL_PLATFORM)" -f makefile.s32\
        ); done


pmax:	ALWAYS
	for i in $(C_SUBD) ; do (\
	    cd $$i;\
	    make "PLATFORM=$(PLATFORM)" "REL_PLATFORM=$(REL_PLATFORM)" "RANLIB=$(RANLIB)" \
        ); done
	for i in $(P_SUBD) ; do (\
	    cd $$i;\
	    make "PLATFORM=$(PLATFORM)"  "REL_PLATFORM=$(REL_PLATFORM)" "PFLAGS=$(PFLAGS)" "PAUTH=/valid/release/$(REL_PLATFORM)/vsecure/authorize.o" pmax\
        ); done


vax:	ALWAYS
	(cd vax ; make)
ibm:	ALWAYS
	(cd ibm ; make)
pc:	ALWAYS
	(cd pc ; make)

clean:
	for i in $(C_SUBD) $(P_SUBD) $(HOST_SUBD) ; do (\
	    cd $$i;  make clean\
        ); done
	rm -f *.out *junk junk* *~ .emacs* */vopen.h scald/*/vopen.h */unixtime.h scald/*/unixtime.h
realclean:
	make clean
	rm -f $(PRODUCED) $(KIT)
nokit:
	rm -f $(KIT)

scaldkit.$(REL_PLATFORM): scaldkit
	sed -e 's/tools/tools.$(REL_PLATFORM)/' scaldkit >scaldkit.$(REL_PLATFORM)
input.index: scaldkit.$(REL_PLATFORM) $(VERS)
	echo "\"compiler\" \"new:\" \"`$(VERS)`\"" > input.index
	echo { >> input.index
	echo "(primary_file)" >> input.index
	sed -e 's/.* tools/tools/' -e 's/ .*//' scaldkit.$(REL_PLATFORM) >>input.index
	echo } >> input.index

$(TOOLS):
	ln -s $(HOME)/vroot $(TOOLS)

install: installation.time
installation.time: ${EX} scaldkit.$(REL_PLATFORM)
	find tools.$(REL_PLATFORM) -type f -exec rm -f {} ';'
	sh install.sh scaldkit.$(REL_PLATFORM) .
	touch installation.time
valid.index:	input.index installation.time
	@echo "I hope you're ROOT"
	mkindex
$(REL_PLATFORM).ms: valid.index
	@echo "Forcing a stop for manual intervention:"
	@echo "Now edit $(REL_PLATFORM).ms to indicate the block size!!"
	@false
kit:	$(VERS) $(TOOLS) installation.time valid.index $(REL_PLATFORM).ms
	sh submitkit.sh validcompiler `$(VERS)` $(REL_PLATFORM) */*.mk scald/*/*.mk
kit.sun4:
	make "PLATFORM=-DSUN4" "REL_PLATFORM=sun4" kit
kit.pmax:
	make "PLATFORM=-DPMAX" "REL_PLATFORM=dec3100" installation.time
	mkpmax validcompiler "validcompiler `$(VERS)`" pmax.data
ALWAYS:
	@true
