#
#	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

#$IF vax THEN
VAX         = TRUE
MIPS        = FALSE
ARCH        = vax
#$ELSIF mips THEN
#VAX         = FALSE
#MIPS        = TRUE
#ARCH        = mips
#$ELSE
#ARCH        = unknown
#$END


# 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.

#$CONST rdistInstalled = TRUE
#$CONST cpPFlag = mips
#$CONST mkdirPFlag = mips
rdistInstalled = FALSE
cpPFlag = TRUE
mkdirPFlag = FALSE

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

#$IF cpPFlag THEN
# cp -p preserves modification data, etc.
CP          = cp -p
#$ELSE
#CP          = cp
#$END

#$IF mkdirPFlag THEN
## mkdir -p creates intermediate directories as needed
#MKDIR       = mkdir -p
#$ELSE
MKDIR       = mkdir
#$END

#$IF rdistInstalled THEN
#RDIST       = rdist -c -h
#LOCALHOST        = localhost:
#$ELSE
RDIST       = $(CP)
LOCALHOST   =
#$END

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

#
#	This is the Makefile for all short documentation
#

#$INCLUDE "../Metafile.defines"

REMOTEDIR = '[.m2.doc]'

DOCS= installation.f overview.f mod.f p2m2.f announcement.f pcode.doc.f \
	modprof.f sigplan84.f
OLDDOCS = array.f inline.f m+c+p.f 
VMSDOCS = vms_mod.txt vms_mod.f overview.txt refman.psf

all: docs
#all: docs vmsdocs

docs:		$(DOCS)
olddocs:	$(OLDDOCS)
vmsdocs:	$(VMSDOCS)

.SUFFIXES:
.SUFFIXES: .txt .f .l .d
.l.f:
	nroff -man $*.l > $*.f
.d.f:
	nroff -ms $*.d > $*.f

pcode.doc.f:
	tbl pcode.doc | nroff -ms >pcode.doc.f
sigplan84.f: sigplan84.d
	tbl sigplan84.d | nroff -ms > sigplan84.f

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

quickinstall: $(DESTDIR)$(MANDIR)
	$(RDIST) mod.l     $(LOCALHOST)$(DESTDIR)$(MANDIR)/$(MODBINNAME).l
	$(RDIST) p2m2.l    $(LOCALHOST)$(DESTDIR)$(MANDIR)/$(P2M2BINNAME).l
	$(RDIST) modprof.l $(LOCALHOST)$(DESTDIR)$(MANDIR)/$(MODPROFBINNAME).l

install: $(DESTDIR)$(MANDIR) \
	 $(DESTDIR)$(MANDIR)/$(MODBINNAME).l \
	 $(DESTDIR)$(MANDIR)/$(P2M2BINNAME).l \
	 $(DESTDIR)$(MANDIR)/$(MODPROFBINNAME).l

$(DESTDIR)$(MANDIR):
	-test -d $@ || $(MKDIR) $@

$(DESTDIR)$(MANDIR)/$(MODBINNAME).l: mod.l
	$(RDIST) mod.l     $(LOCALHOST)$(DESTDIR)$(MANDIR)/$(MODBINNAME).l

$(DESTDIR)$(MANDIR)/$(P2M2BINNAME).l: p2m2.l
	$(RDIST) p2m2.l    $(LOCALHOST)$(DESTDIR)$(MANDIR)/$(P2M2BINNAME).l

$(DESTDIR)$(MANDIR)/$(MODPROFBINNAME).l: modprof.l
	$(RDIST) modprof.l $(LOCALHOST)$(DESTDIR)$(MANDIR)/$(MODPROFBINNAME).l

# Would be nice to remove _ <bs> sequences

overview.txt: overview.f
	$(CP) overview.f overview.txt
vms_mod.l: mod.l
	@echo Be sure to update vms_mod.l to match mod.l
vms_mod.txt: vms_mod.f
	$(CP) vms_mod.f vms_mod.txt
	
vmscopy: $(VMSDOCS)
	dcp -v $(VMSDOCS) $(REMOTENODE)::$(REMOTEDIR)

clean:
	-$(RM) *.f *.txt

checkin:
	ci -l -q -m"Gatekeeper release 22 June 1990" \
	-s"Release" *.d *.doc *.l Makefile
