#
# This file is used to make the Scheme->C system for multiple processor types.
#

SRCDIR = /usr/local/src/schemetoc

NeXTDIR = ${SRCDIR}/next
NeXTBIN = /usr/local/bin
NeXTLIB = /usr/local/lib

MIPSDIR = /wrl/pmax/src/schemetoc
MIPSBIN = /wrl/pmax/bin
MIPSLIB = /wrl/pmax/lib

TITANDIR = /wrl/titan/src/schemetoc
TITANBIN = /wrl/titan/bin
TITANLIB = /wrl/titan/lib

VAXDIR = /wrl/vax/src/schemetoc
VAXBIN = /wrl/vax/bin
VAXLIB = /wrl/vax/lib

APOLLODIR = $(SRCDIR)/apollo
APOLLOBIN = $(SRCDIR)/bin.apollo
APOLLOLIB = $(SRCDIR)/lib.apollo

PRISMDIR = $(SRCDIR)/prism
PRISMBIN = $(SRCDIR)/bin.prism
PRISMLIB = $(SRCDIR)/lib.prism

SPARCDIR = ${SRCDIR}/sparc
SPARCBIN = ${SRCDIR}/bin.sparc
SPARCLIB = ${SRCDIR}/lib.sparc

SUN3DIR = ${SRCDIR}/sun3
SUN3BIN = ${SRCDIR}/bin.sun3
SUN3LIB = ${SRCDIR}/lib.sun3

I386DIR = ${SRCDIR}/i386
I386BIN = ${SRCDIR}/bin.i386
I386LIB = ${SRCDIR}/lib.i386

# This is a list of the machines/architectures that are currently supported. 
# These are also the names of the necessary makefile fragements.
MACHINES = APOLLO I386 MIPS NeXT PRISM SPARC SUN3 TITAN VAX

# Architecture specific directories and links to the source files are
# constructed by the following commands which follow:

no-target:
	@echo 'Use "make for<target>", where <target> is one of:'
	@echo '    $(MACHINES)'

forCPU:
	-mkdir ${CPUDIR}
	cp ${CPU} ${CPUDIR}
	echo "BINDIR = ${BINDIR}"  > ${CPUDIR}/makefile
	echo "LIBDIR = ${LIBDIR}" >> ${CPUDIR}/makefile
	cat makefile         	  >> ${CPUDIR}/makefile
	@-echo
	@-echo '***** /doc *****'
	-mkdir ${CPUDIR}/doc
	echo "SRCDIR = ${SRCDIR}/doc"  > ${CPUDIR}/doc/makefile
	cat doc/makefile	      >> ${CPUDIR}/doc/makefile
	-cd ${CPUDIR}/doc; make srclinks
	@-echo
	@-echo '***** /scrt *****'
	-mkdir ${CPUDIR}/scrt
	cat ${CPU} 			> ${CPUDIR}/scrt/makefile
	echo "SRCDIR = ${SRCDIR}/scrt" >> ${CPUDIR}/scrt/makefile 
	echo "CPUDIR = ${CPUDIR}/scrt" >> ${CPUDIR}/scrt/makefile
	echo "BINDIR = ${BINDIR}"      >> ${CPUDIR}/scrt/makefile
	echo "LIBDIR = ${LIBDIR}"      >> ${CPUDIR}/scrt/makefile
	cat scrt/makefile-tail         >> ${CPUDIR}/scrt/makefile
	-cd ${CPUDIR}/scrt; make srclinks
	@-echo
	@-echo '***** /scsc *****'
	-mkdir ${CPUDIR}/scsc
	cat ${CPU} 			> ${CPUDIR}/scsc/makefile
	echo "SRCDIR = ${SRCDIR}/scsc" >> ${CPUDIR}/scsc/makefile 
	echo "CPUDIR = ${CPUDIR}/scsc" >> ${CPUDIR}/scsc/makefile
	echo "BINDIR = ${BINDIR}"      >> ${CPUDIR}/scsc/makefile
	echo "LIBDIR = ${LIBDIR}"      >> ${CPUDIR}/scsc/makefile
	cat scsc/makefile-tail         >> ${CPUDIR}/scsc/makefile
	-cd ${CPUDIR}/scsc; make srclinks
	@-echo
	@-echo '***** /test *****'
	-mkdir ${CPUDIR}/test
	cat ${CPU} 			> ${CPUDIR}/test/makefile
	echo "SRCDIR = ${SRCDIR}/test" >> ${CPUDIR}/test/makefile 
	echo "CPUDIR = ${CPUDIR}/test" >> ${CPUDIR}/test/makefile
	echo "BINDIR = ${BINDIR}"      >> ${CPUDIR}/test/makefile
	echo "LIBDIR = ${LIBDIR}"      >> ${CPUDIR}/test/makefile
	cat test/makefile-tail         >> ${CPUDIR}/test/makefile
	-cd ${CPUDIR}/test; make srclinks

forMIPS:
	$(MAKE) "CPU = MIPS" "CPUDIR = ${MIPSDIR}" "SRCDIR = ${SRCDIR}" \
	     "BINDIR = ${MIPSBIN}" "LIBDIR = ${MIPSLIB}" forCPU

forTITAN:
	$(MAKE) "CPU = TITAN" "CPUDIR = ${TITANDIR}" "SRCDIR = ${SRCDIR}"  \
	     "BINDIR = ${TITANBIN}" "LIBDIR = ${TITANLIB}" forCPU

forVAX:
	$(MAKE) "CPU = VAX" "CPUDIR = ${VAXDIR}" "SRCDIR = ${SRCDIR}"  \
	     "BINDIR = ${VAXBIN}" "LIBDIR = ${VAXLIB}" forCPU

forAPOLLO:
	$(MAKE) "CPU = APOLLO" "CPUDIR = ${APOLLODIR}" "SRCDIR = ${SRCDIR}" \
	     "BINDIR = ${APOLLOBIN}" "LIBDIR = ${APOLLOLIB}" forCPU
	cd $(APOLLODIR)/scrt; ln -s $(SRCDIR)/mul-fix.perl mul-fix.perl

forPRISM:
	$(MAKE) "CPU = PRISM" "CPUDIR = ${PRISMDIR}" "SRCDIR = ${SRCDIR}" \
	     "BINDIR = ${PRISMBIN}" "LIBDIR = ${PRISMLIB}" forCPU

forSPARC:
	$(MAKE) "CPU = SPARC" "CPUDIR = ${SPARCDIR}" "SRCDIR = ${SRCDIR}" \
	     "BINDIR = ${SPARCBIN}" "LIBDIR = ${SPARCLIB}" forCPU


forSUN3:
	$(MAKE) "CPU = SUN3" "CPUDIR = ${SUN3DIR}" "SRCDIR = ${SRCDIR}" \
	     "BINDIR=${SUN3BIN}" "LIBDIR=${SUN3LIB}" forCPU

forI386:
	$(MAKE) "CPU = I386" "CPUDIR = ${I386DIR}" "SRCDIR = ${SRCDIR}" \
	     "BINDIR = ${I386BIN}" "LIBDIR = ${I386LIB}" forCPU

forNeXT:
	$(MAKE) "CPU = NeXT" "CPUDIR = ${NeXTDIR}" "SRCDIR = ${SRCDIR}" \
	     "BINDIR = ${NeXTBIN}" "LIBDIR = ${NeXTLIB}" forCPU

# The Scheme->C system is initially compiled from the C sources by the
# following:

port:
	cd scrt; $(MAKE) port
	cd scsc; $(MAKE) port

# A "private" working copy of the current compiler, libary, and interpreter
# is installed in a directory by the following command:

install-private:
	cd scrt; $(MAKE) "destdir = ${destdir}" install-private
	cd scsc; $(MAKE) "destdir = ${destdir}" install-private

# Clean out working files.

clean:
	rm -f *.BAK *.CKP SC-TO-C*
	cd doc; $(MAKE) clean
	cd scrt; $(MAKE) clean
	cd scsc; $(MAKE) clean
	cd test; $(MAKE) clean

# Clean up C source files generated from Scheme source.

clean-sc-to-c:
	cd scrt; $(MAKE) clean-sc-to-c
	cd scsc; $(MAKE) clean-sc-to-c
	cd test; $(MAKE) clean-sc-to-c

# Delete programs and libraries.

noprogs:
	cd scrt; $(MAKE) noprogs
	cd scsc; $(MAKE) noprogs
	cd test; $(MAKE) noprogs

# All binaries and documentation files are installed by the following command
# for access by all users.

install:
	cd scrt; $(MAKE) "BINDIR = ${BINDIR}" "LIBDIR = ${LIBDIR}" install
	cd scsc; $(MAKE) "BINDIR = ${BINDIR}" "LIBDIR = ${LIBDIR}" install
#	cd doc; $(MAKE) "BINDIR = ${BINDIR}" "LIBDIR = ${LIBDIR}" install

# All files which must be constructed are made by the following command:

all:
	cd scrt; $(MAKE) all
	cd scsc; $(MAKE) all

# Distribute "source" files required to make the Scheme->C system.

srcdist:
	rdist -c $(MACHINES) README makefile ${destdir}
	cd doc; $(MAKE) "destdir = ${destdir}/doc" srcdist
	-cd scbenchmark; $(MAKE) "destdir = ${destdir}/scbenchmark" srcdist
	cd scrt; $(MAKE) "destdir = ${destdir}/scrt" srcdist
	cd scsc; $(MAKE) "destdir = ${destdir}/scsc" srcdist
	-cd test; $(MAKE) "destdir = ${destdir}/test" srcdist
	-cd tools; $(MAKE) "destdir = ${destdir}/tools" srcdist

# Distribute "binary" files so that they may be installed on some other
# system.

bindist:
	rdist -c $(MACHINES) README makefile ${destdir}
	cd doc; $(MAKE) "destdir = ${destdir}/doc" bindist
	cd scrt; $(MAKE) "destdir = ${destdir}/scrt" bindist
	cd scsc; $(MAKE) "destdir = ${destdir}/scsc" bindist

# Write the tar tape for distribution.

TARFILES = CHANGES README $(MACHINES) makefile \
	   doc/[a-z]*.mss doc/[a-z]*.psf doc/[a-z]*.l doc/makefile \
	   gnuemacs/README gnuemacs/[a-z]* \
	   scrt/[a-z]*.sc scrt/[a-z]*.[chs] scrt/makefile-tail \
	   scrt/[a-z]*.asm \
	   scsc/[a-z]*.sc scsc/[a-z]*.c scsc/[a-z]*.sch scsc/makefile-tail \
	   test/[a-z]*.sc test/test54c.c test/makefile-tail \
	   cdecl/README cdecl/[a-z]* \
	   xlib/README xlib/[X-z]*

TARFLAGS = -cl

tartape:
	tar ${TARFLAGS} ${TARFILES}

tarlog:
	tar tvf ${TARTAPE} > ${TARLOG}
