# tm Pascal support make file

VERSION = 1

# debugging flags
DBUG = -g
LDFLAGS	= -g

# program extention
# .ttp for GEMDOS
# .exe for MSDOS
EXT=

# Pascal compilation flags
PFLAGS = $(SYSPFLAGS) $(DBUG)

# Some names of programs
TM  = tm
LINKER = pc

LIBS = $(PLIBLOC)

MAKEFILE = Makefile

DOC	= tmpas.tex plot.ds demo.pt democonf.t README CHANGELOG

DEMOFILES = plot.ds democonf.t demo.pt demo.p

JUNK = tmp core makelog testsep$(EXT) testmass$(EXT) testout testtmp stamp.t \
    tmpas.aux tmpas.log tmpas.dvi tmpas.alw version.tex $(TMSRCS) $(TMHDRS) \
    $(OBJS) tmp.p

TESTFILES = test.ds testdata testconf.t

DISTFILES = $(TMMODULES) $(TESTFILES) $(TESTSRCS) $(DOC) $(MAKEFILE)

TMMODULES = pasgvar.pt pasvar.pt pascode.pt pastype.pt pasneed.t paslib.pt \
	    paslib.ht pascode.ht

TMSRCS      = testcode.p testmass.p demo.p

TMHDRS      = testcode.h testtype.h

TESTSRCS    = testmass.pt testcode.ht testcode.pt testmain.p testtype.ht

OBJS = demo.o \
		stringhandler.o \
		testcode.o \
		testmain.o \
		testmass.o

#++ make module local start, do NOT touch this line. ++
# Installation dependent make variables for ericv on HERMES 

# full path of the ESPRIT environment
ESPRITDIR = /home1/forfun

#  BDIR     : bin directory
BDIR = $(ESPRITDIR)/binA

#  IDIR     : include directory
IDIR = $(ESPRITDIR)/include

#  LDIR     : library directory
LDIR = $(ESPRITDIR)/libA


NFULLDS = $(ESPRITDIR)/ds/nfullgl.ds
NKERNDS = $(ESPRITDIR)/ds/nkerngl.ds

#  HOSTNAME : name of installation machine.
HOSTNAME=hermes

# SYS     : name of operating system or machine type
#     BSD	For generic BSD systems
#     AVIION	For generic DG_UX systems
#     HPUX	For all HP-UX systems
#     SUN	For all SUN systems
#     APOLLO	For all Apollo systems
SYS = AVIION

# CLIBLOC : required C libraries
CLIBLOC =

LINTLIBLOC =

PASLIBLOC =

# CBADADR : address that will cause a core-dump if read or written.
CBADADR = 0

SYSLINTFLAGS = -hpac
SYSCFLAGS = 
SYSCPROFFLAGS =
SYSCDBUGFLAGS =
SYSPFLAGS =
OFLAG= -O
# Collection of host dependent make rules.

### libinstall ###
# MODULE	- module to install
libinstall:
	cp $(MODULE) $(LDIR)/$(MODULE)

### includeinstall ###
# MODULE	- module to install
includeinstall:
	cp $(MODULE) $(IDIR)/$(MODULE)

### maninstall ###
# MAN		- manual page to install
maninstall:
	cp $(MAN) /usr/man/manl

### bininstall ###
# MODULE	- module to install
bininstall:
	cp $(MODULE) $(BDIR)/$(MODULE)
	strip $(BDIR)/$(MODULE)

### arlibinstall ###
# MODULE	- module to install
arlibinstall:
	cp $(MODULE) $(LDIR)/$(MODULE)

LINK.c=$(CC) 
#++ make module local end, do NOT touch this line. ++

help :
	@echo " Possible make targets:"
	@echo "all		Create local running programs."
	@echo "clean		Free disk space."
	@echo "distfiles	List distribution files."
	@echo "install		Install relevant files."
	@echo "setup		Adapt sources to local situation."
	@echo "test		Run tests."

#
all: test$(EXT)

# Add rules for the programs themselves here.

# Testing is done in two parts: once as one big program
# (resulting in executable 'testmass'), and once as two
# separately compiled programs (resulting in executable 'testsep').
test : testmass$(EXT) testsep$(EXT)
	./testmass$(EXT) <testdata > testtmp
	./testmass$(EXT) <testtmp > testout
	diff testtmp testout
	./testsep$(EXT) <testdata > testtmp
	./testsep$(EXT) <testtmp > testout
	diff testtmp testout

TESTSEPOBJS    = testcode.o testmain.o
testsep$(EXT): $(TESTSEPOBJS)
	$(LINKER) $(LDFLAGS) $(TESTSEPOBJS) $(LIBS) -o testsep$(EXT)

TESTMASSOBJS    = testmass.o
testmass$(EXT): $(TESTMASSOBJS)
	$(LINKER) $(LDFLAGS) $(TESTMASSOBJS) $(LIBS) -o testmass$(EXT)

# File containing date, time and version stamp
stamp.t: Makefile $(TMMODULES)
	echo '.set tmpasvers $(VERSION)' > stamp.t
	echo '.set tmpasdate "'`date`'"' >> stamp.t
	echo '.set tmpashost $(HOSTNAME)' >> stamp.t

install : stamp.t
	cat stamp.t pasneed.t > $(LDIR)/pasneed.t
	echo '.insert $$(libpath)$$(pathsep)pasneed.t' > instmp
	cat stamp.t instmp paslib.pt > $(LDIR)/paslib.pt
	cat stamp.t instmp pastype.pt > $(LDIR)/pastype.pt
	cat stamp.t instmp pasvar.pt > $(LDIR)/pasvar.pt
	cat stamp.t instmp pasgvar.pt > $(LDIR)/pasgvar.pt
	cat stamp.t instmp pascode.pt > $(LDIR)/pascode.pt
	rm -f instmp

clean:
	rm -f $(JUNK)

distfiles:
	@echo $(DISTFILES) | tr ' ' '\012'

setup:
	modmake local ../make.local $(MAKEFILE)

# Non-standard make rules

version.tex : $(MAKEFILE)
	echo "\\def\\version{$(VERSION)}" > version.tex

doc: version.tex $(DEMOFILES)
	latex \\batchmode\\input{tmpas}

index: $(HDRS) $(SRCS)
	ctags -wx $(HDRS) $(SRCS)

tags: $(HDRS) $(SRCS)
	ctags $(HDRS) $(SRCS)

depend: $(TMSRCS) $(TMHDRS)
	mkmf -I$(IDIR) -f $(MAKEFILE)

demo.p : plot.ds demo.pt democonf.t paslib.pt pascode.pt
	tm plot.ds demo.pt | expand > demo.p

testmass.p : testmass.pt testconf.t test.ds $(TMMODULES)
	$(TM) test.ds testmass.pt > testmass.p

testcode.p : testcode.pt testconf.t test.ds pascode.pt paslib.pt
	$(TM) test.ds testcode.pt > testcode.p

testtype.h : testtype.ht testconf.t test.ds pastype.pt
	$(TM) test.ds testtype.ht > testtype.h

testcode.h : testcode.ht testconf.t test.ds pascode.ht paslib.ht
	$(TM) test.ds testcode.ht > testcode.h

.p.o:
	ln $< $*.c
	cc -E -I$(IDIR) -D$(SYS) $*.c | sed -e '/^#/d' >tmp.p
	rm -f $*.c
	pc -c $(PFLAGS) tmp.p
	mv tmp.o $@
	rm -f tmp.p

###
testcode.o: testtype.h
testmain.o: testtype.h testcode.h
