#
#	This is the Makefile for the Modula-2 runtime library
#

#
#	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         = FALSE
MIPS        = TRUE
ARCH        = mips


# 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      = /usr/local/lib
# Directory for installing the passes of the compiler
PASSESDIR   = /usr/local/lib/mod
# Directory for installing the .def files we provide
DEFSDIR     = /usr/local/defs
# Directory for installing the man pages for mod and p2m2
MANDIR      = /usr/man/manl
# Directory for installing the binaries mod and p2m2
BINDIR      = /usr/local/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  = /pandora_a1/m2/m2-$(ARCH)/lib

# 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 -p creates intermediate directories as needed
MKDIR       = mkdir -p

RDIST       = rdist -c -h
LOCALHOST        = localhost:

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


REMOTEDIR = '[.m2.lib]'

.SUFFIXES:
.SUFFIXES: .o .mod .def .c .a .m

CC = cc
CFLAGS = -O

MOD = ../mod/mod
MODFLAGS = -a -g -O -C -B../lib

MC = mc

DEFS = Storage.def math.def longmath.def parameters.def strings.def unix.def \
	ASCII.def x.def \
	InOut.def MathLib0.def RealInOut.def Terminal.def TextIO.def
PDEFS = SYSTEM.def Memory.def IO.def BitOperations.def
COMMONOBJS = runtime.o mem.o count.o NAM.o capitalize.o
OBJS = mcoroutine.o $(COMMONOBJS)

MOBJS =	math.o longmath.o parameters.o strings.o unix.o ASCII.o x.o \
	InOut.o MathLib0.o RealInOut.o Terminal.o TextIO.o
IOOBJS = iocvtl.o ioptab.o iomult.o iowc.o iowid.o iowle.o iowlf.o iows.o\
	iowud.o iowuio.o iowuix.o iocvtr.o iowrf.o iowre.o
IOMOBJS = ioimp.o

#
#	To automatically update your local VMS node, just remove all
#	of the following comment characters ("^#") and comment out
#	the current definition of the target all.
#

.def.mod:
	touch $*.mod

.mod.o:
	$(MOD) -c ${MODFLAGS} $*.mod
.c.o:
	$(CC) -c ${CFLAGS} $*.c

.a.o:
	as -o $*.o $*.a
	$(CP) $*.o prof

.m.o:
	$(MC) $*.m
	$(CP) $*.o prof

all:	libmod.a

testf: testf.o iomult.o ioimp.o iocvtf.o ioftab.o
	$(MOD) -g -o testf testf.o iomult.o ioimp.o iocvtf.o ioftab.o
truntime.o:	truntime.c
	tcc -c truntime.c
testf.o:	testf.mod
	$(MOD) -c -r -g -C testf.mod
testmult64: testmult64.o iomult64.o ioimp.o
	$(MOD) -g -o testmult64 testmult64.o iomult64.o ioimp.o
testmult64.o:	testmult64.mod
	$(MOD) -c -r -g -C testmult64.mod
testmult: testmult.o iomult.o ioimp.o
	$(MOD) -g -o testmult testmult.o iomult.o ioimp.o
testmult.o:	testmult.mod
	$(MOD) -c -r -g -C testmult.mod
ioptab.a:	genptab ioptab.bc
	genptab <ioptab.bc >ioptab.a
genptab:	genptab.mod
	$(MOD) -o genptab -r -g -C genptab.mod
genptabin:	genptabin.mod
	$(MOD) -o genptabin -r -g -C genptabin.mod
ioptab.bc:	ioptab.bcin
	bc < ioptab.bcin >ioptab.bc
ioptab.bcin:	genptabin
	genptabin > ioptab.bcin
testio:	testio.o iolib
	$(MOD) -g -o testio testio.o iolib
testio.o:	testio.mod
	$(MOD) -c -r -g -C testio.mod
timerf.o:	timerf.mod
	$(MOD) -c -r -g -C timerf.mod
timerf:	timerf.o iolib
	$(MOD) -g -o timerf timerf.o iolib
timei.o:	timei.mod
	$(MOD) -c -r -g -C timei.mod
timei:	timei.o iolib
	$(MOD) -g -o timei timei.o iolib
timef.o:	timef.mod
	$(MOD) -c -r -g -C timef.mod
timef:	timef.o iolib
	$(MOD) -g -o timef timef.o iolib
rande.o:	rande.mod
	$(MOD) -c -r -g -C rande.mod
rande:	rande.o iolib
	$(MOD) -g -o rande rande.o iolib
randrf.o:	randrf.mod
	$(MOD) -c -r -g -C randrf.mod
randrf:	randrf.o iolib
	$(MOD) -g -o randrf randrf.o iolib
randf.o:	randf.mod
	$(MOD) -c -r -g -C randf.mod
randf:	randf.o iolib
	$(MOD) -g -o randf randf.o iolib
iolib:	$(IOOBJS) $(IOMOBJS)
	-$(RM) iolib
	ar cr iolib $(IOOBJS) $(IOMOBJS)
	ranlib iolib

libmod.a:	$(OBJS) $(MOBJS)
	-$(RM) libmod.a
	ar cr libmod.a $(OBJS) $(MOBJS)
	ranlib libmod.a
libmod_p.a:	$(OBJS) $(MOBJS)
	-$(RM) prof/libmod_p.a libmod_p.a
	cd prof; ar cr libmod_p.a $(OBJS) $(MOBJS)
	$(CP) prof/libmod_p.a libmod_p.a
	ranlib libmod_p.a

udiv.o:	udiv.c
	as -o udiv.o udiv.c
	$(CP) udiv.o prof
udiv.mar: udiv.c
	@echo "Please update $@ and copy it to $(REMOTENODE)$(REMOTEDIR)."
coroutine.mar: coroutine.c
	@echo "Please update $@ and copy it to $(REMOTENODE)$(REMOTEDIR)."
descrip.mms: Metafile
	@echo "Please update $@ and copy it to $(REMOTENODE)$(REMOTEDIR)."
coroutine.o:	coroutine.c
	as -o coroutine.o coroutine.c
	$(CP) coroutine.o prof
mcoroutine.o: mcoroutine.s
	cc -c mcoroutine.s
mcoroutine.s: mcoroutine.c
	@echo "Please update mcoroutine.s appropriately

clean:
	-$(RM) *.pcd *.o prof/*.o

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

quickinstall: ${DESTDIR}$(LIBDIR) COPYDEFS
	$(RDIST) libmod.a $(LOCALHOST)$(DESTDIR)$(LIBDIR)/libmod.a
install: ${DESTDIR}$(LIBDIR) ${DESTDIR}$(LIBDIR)/libmod.a COPYDEFS


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

${DESTDIR}$(LIBDIR)/libmod.a: libmod.a
	$(RDIST) libmod.a $(LOCALHOST)$(DESTDIR)$(LIBDIR)/libmod.a

${DESTDIR}$(LIBDIR)/libmod_p.a: libmod_p.a
	$(RDIST) libmod_p.a $(LOCALHOST)$(DESTDIR)$(LIBDIR)/libmod_p.a

COPYDEFS:
	-test -d $(DESTDIR)$(DEFSDIR) || $(MKDIR) $(DESTDIR)$(DEFSDIR)
	$(RDIST) $(DEFS) $(PDEFS) $(LOCALHOST)$(DESTDIR)$(DEFSDIR)

testdir:
	ln -s ../mod/mod mod
	ln -s ../mod2/mod2.0 mod2.0
	ln -s ../imc/mod2.2 mod2.2


checkin:
	ci -l -f -m"WSL/WRL Checkin before VMS changes"\
	-s"WSL/WRL/Release" *.def *.c *.mod Makefile descrip.mms *.mar

vmscopy:
	dcp -v *.def *.c *.mod Makefile descrip.mms *.mar \
	$(REMOTENODE)$(REMOTEDIR)
