#
#	This is the Makefile for the mod and pc top-level driver programs
#

#
#	WARNING: This Makefile is derived from the corresponding Metafile.
#	Don't even try to edit this file.  Instead, edit the Metafile, then
#	do a ``make Makefile''.
#
#	If you alter Metafile.defines in the top-level Modula-2 directory,
#	then you should do a ``make Makefiles'' to rederive all Makefiles
#	in all directories.


########################## Common Definitions ###############################

# Defines for conditional processing

VAX         = TRUE
MIPS        = FALSE
ARCH        = vax


# Top-level directory for installation.  Define as /tmp/ to test installation.
# Note that if you define DESTDIR, it must have a trailing /.
DESTDIR     = 
# Directory for installing libmod.a
LIBDIR      = /mit/watchmaker/vaxlib
# Directory for installing the passes of the compiler
PASSESDIR   = /mit/watchmaker/vaxlib/m2
# Directory for installing the .def files we provide
DEFSDIR     = /mit/watchmaker/vaxlib/m2
# Directory for installing the man pages for mod and p2m2
MANDIR      = /mit/watchmaker/man/manl
# Directory for installing the binaries mod and p2m2
BINDIR      = /mit/watchmaker/bin

# Name of Modula-2 driver program
MODBINNAME  = mod
# Name of Pascal driver program
PCBINNAME   = wrlpc
# Name of Pascal to Modula-2 converter program
P2M2BINNAME = p2m2
# Name of Modula-2 statement-level profiler
MODPROFBINNAME = modprof
# Name of Modula-2 preprocessor
PREPBINNAME = prep

# Name of directory in which Modula-2 library, compiler passes reside
TESTLIBDIR  = /mit/watchmaker/vaxlib/m2

# Defines for VMS
REMOTENODE = ophion::


# Defines for various utilities.  You may not have all these flags if you
# aren't running a recent release.  So set them according to your system's
# capabilities before trying to install anything.


# rm -f forces removal without asking question or reporting file not found
RM          = rm -f

# cp -p preserves modification data, etc.
CP          = cp -p

MKDIR       = mkdir

RDIST       = $(CP)
LOCALHOST   =

########################## End of Definitions ###############################


CFLAGS=	-O
CC= cc

all:	mod imod wrlpc iwrlpc

mod:	mod.c Makefile
	${CC} -o mod -DLIBDIR='"${TESTLIBDIR}"' \
		-DPASSESDIR='"${TESTLIBDIR}"' \
		-DDEFSDIR='"${TESTLIBDIR}"' \
		-DPASCAL=0 -DMODULA2=1 $(CFLAGS) mod.c
imod:	mod.c Makefile
	${CC} -o imod -DLIBDIR='"${DESTDIR}${LIBDIR}"' \
		-DPASSESDIR='"${DESTDIR}${PASSESDIR}"' \
		-DDEFSDIR='"${DESTDIR}${DEFSDIR}"' \
		-DPASCAL=0 -DMODULA2=1 $(CFLAGS) mod.c

wrlpc:	mod.c Makefile
	${CC} -o wrlpc -DLIBDIR='"${TESTLIBDIR}"' \
		-DPASSESDIR='"${TESTLIBDIR}"' \
		-DPASCAL=1 -DMODULA2=0 $(CFLAGS) mod.c

iwrlpc:	mod.c Makefile
	${CC} -o iwrlpc -DLIBDIR='"${DESTDIR}${LIBDIR}"' \
		-DPASSESDIR='"${DESTDIR}${PASSESDIR}"' \
		-DPASCAL=1 -DMODULA2=0 $(CFLAGS) mod.c

Makefile: Metafile ../Metafile.defines
	mv Makefile Makefile.bak
	../prep/prep -Dvax=$(VAX) -Dmips=$(MIPS) <Metafile > Makefile

quickinstall: ${DESTDIR}$(BINDIR) ${DESTDIR}$(PASSESDIR)
	install -c -s imod ${DESTDIR}$(BINDIR)/$(MODBINNAME)
	$(RM) ${DESTDIR}$(PASSESDIR)/mod
	ln -s ${DESTDIR}$(BINDIR)/$(MODBINNAME) ${DESTDIR}$(PASSESDIR)/mod
	install -c -s iwrlpc ${DESTDIR}$(BINDIR)/$(PCBINNAME)
install: ${DESTDIR}$(BINDIR) ${DESTDIR}$(PASSESDIR) \
		${DESTDIR}$(BINDIR)/$(MODBINNAME) \
		${DESTDIR}$(PASSEDIR)/mod \
		${DESTDIR}$(BINDIR)/$(PCBINNAME)

${DESTDIR}$(BINDIR):
	-test -d $@ || $(MKDIR) $@

${DESTDIR}$(PASSESDIR):
	-test -d $@ || $(MKDIR) $@

${DESTDIR}$(BINDIR)/$(MODBINNAME): imod
	install -c -s imod ${DESTDIR}$(BINDIR)/$(MODBINNAME)

${DESTDIR}$(PASSEDIR)/mod:
	$(RM) ${DESTDIR}$(PASSESDIR)/mod
	ln -s ${DESTDIR}$(BINDIR)/$(MODBINNAME) ${DESTDIR}$(PASSESDIR)/mod

${DESTDIR}$(BINDIR)/$(PCBINNAME): iwrlpc
	install -c -s iwrlpc ${DESTDIR}$(BINDIR)/$(PCBINNAME)

vmscopy:
	dcp -v mod.c descrip.mms $(REMOTEDIR)

descrip.mms : Makefile
	@echo "Make sure you update $@ and copy it to $(REMOTEDIR)."

clean:
	-$(RM) *.o imod iwrlpc

checkin:
	ci -l -f  -m"WSL/WRL Release 28 Apr 1988"\
	-s"WSL/WRL/Release" mod.c Makefile  descrip.mms
