# Makefile for tm
#
VERSION=27

# -I flags for  .h files
IPATH = -I$(IDIR)
LIBPATH = $(LDIR)
PROG = tm
SETENVCOM=setenv

# Debug flags:
# may contain any combination of
# -g       generate debugging info for debugger
# -p       generate profiling code
# -DDEBUG  generate internal debugging code
# -DSTAT   generate statistics collection code
DBUG = -DSTAT

SUFFIX        = .y:

CFLAGS        = $(IPATH) $(DBUG) $(SYSCFLAGS) -D$(SYS)
LINTFLAGS     = $(SYSLINTFLAGS) $(IPATH) $(DBUG) -D$(SYS)
LDFLAGS	      = $(CFLAGS)

LIBS	      = $(LDIR)/libtmc.a

LINTLIBS      = $(LDIR)/llib-ltmc.ln

YFLAGS        = -v

TM            = tm

EXTHDRS	      =

DOC	      = README tm.1 CHANGES

DSFILES       = ds.ds tplelm.ds

TMFILES       = tplspec.t tmds.ct tmds.ht tmtplelm.ct tmtplelm.ht dsspec.t

TESTFILES     = test.ds testin goodout gooderr testsub

TMHDRS	      = tmtplelm.h tmds.h

HDRS	      = debug.h \
		refex.h \
		tmdefs.h \
		tmds.h \
		tmerror.h \
		tmexpr.h \
		tmfn.h \
		tmglobal.h \
		tmgram.h \
		tmlex.h \
		tmlibpath.h \
		tmmisc.h \
		tmstring.h \
		tmtplelm.h \
		tmtrans.h \
		tmvar.h \
		tmvers.h

LINKER	      = cc

MAKEFILE      = Makefile

OBJS	      = debug.o \
		refex.o \
		tm.o \
		tmds.o \
		tmerror.o \
		tmexpr.o \
		tmfn.o \
		tmglobal.o \
		tmgram.o \
		tmlex.o \
		tmlibpath.o \
		tmmisc.o \
		tmstring.o \
		tmtplelm.o \
		tmtrans.o \
		tmvar.o \
		tmvers.o

TMSRCS	      = tmds.c tmtplelm.c

YACCFILES     = tmgram.y

SRCS	      = debug.c \
		refex.c \
		tm.c \
		tmds.c \
		tmerror.c \
		tmexpr.c \
		tmfn.c \
		tmglobal.c \
		tmgram.c \
		tmlex.c \
		tmlibpath.c \
		tmmisc.c \
		tmstring.c \
		tmtplelm.c \
		tmtrans.c \
		tmvar.c \
		tmvers.c

JUNK          = sedlint y.output lint testerr testout index.sed \
		dsneed.t makelog testscr tm.1c

# Note: SRCS and HDRS must be placed after DSFILES and TMFILES
#       to ensure that they are more recent than them. Otherwise
#       tm would be needed to make tm...
DISTFILES = $(DSFILES) $(TMFILES) $(YACCFILES) $(SRCS) $(HDRS) $(MAKEFILE) \
    $(TESTFILES) $(DOC)

GENCFILES = $(TMHDRS) $(TMSRCS) tmgram.c tmlibpath.c tmvers.c

#++ 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 "test		Run tests."
	@echo "install		Install relevant files."
	@echo "clean		Free disk space."
	@echo "distfiles	List distribution files."
	@echo "setup		Adapt sources to local machine."
	@echo " ---"
	@echo "depend		Update dependencies in $(MAKEFILE)."
	@echo "doc		Format documentation."
	@echo "man		Format manual pages."

all: $(PROG)

tm:     $(OBJS) $(LIBS)
	$(LINKER) $(LDFLAGS) $(OBJS) $(CLIBLOC) $(LIBS) -o $(PROG)

install: $(PROG)
	cp $(PROG) $(BDIR)/$(PROG)
	strip $(BDIR)/$(PROG)

clean:
	rm -f $(OBJS) $(JUNK) $(PROG)

depend: $(GENCFILES)
	mkmf $(IPATH) -f $(MAKEFILE)

tmtplelm.h: tmtplelm.ht tplelm.ds tplspec.t
	$(TM) tplelm.ds tmtplelm.ht > tmtplelm.h

tmtplelm.c: tmtplelm.ct tplelm.ds tplspec.t
	$(TM) tplelm.ds tmtplelm.ct > tmtplelm.c

tmds.h: tmds.ht ds.ds dsspec.t
	$(TM) ds.ds tmds.ht > tmds.h

tmds.c: tmds.ct ds.ds dsspec.t
	$(TM) ds.ds tmds.ct > tmds.c

tmlibpath.c: $(MAKEFILE)
	echo 'char libpath[]="$(LIBPATH)";' > tmlibpath.c

tmvers.c: .
	echo 'char tmvers[] = "$(VERSION)";' > tmvers.c
	echo 'char tmdate[] = "'`date`'";' >> tmvers.c
	echo 'char tmhost[] = "$(HOSTNAME)";' >> tmvers.c

lint: $(SRCS) $(HDRS)
	lint $(LINTFLAGS) $(SRCS) $(LINTLIBS) > lint

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

index.sed: $(MAKEFILE)
	echo '/^rfre_/ d' > index.sed
	echo '/^fre_/ d' >> index.sed
	echo '/^app_/ d' >> index.sed
	echo '/^print_/ d' >> index.sed
	echo '/^new_/ d' >> index.sed
	echo '/^rdup_/ d' >> index.sed
	echo '/^room_/ d' >> index.sed
	echo '/^rdup_/ d' >> index.sed
	echo '/^fn/ d' >> index.sed

index: $(SRCS) $(HDRS) index.sed
	ctags -x $(SRCS) $(HDRS) | sed -f index.sed > index

man:
	nroff -man tm.1 > tm.1c

test: testin test.ds testsub goodout gooderr
	-sh -c './tm$(EXT) -v -dsl test.ds testin > testout 2> testerr'
	diff testout goodout
	diff testerr gooderr

setup:
	modmake local ../make.local $(MAKEFILE)
	rm -f tmgram.c

realdistfiles: $(DISTFILES)

distfiles:
	@csh -c 'make realdistfiles >& makelog'
	@echo $(DISTFILES) | tr ' ' '\012'

.y.c:
	yacc -d $(YFLAGS) $<
	mv y.tab.h $*.h
	mv y.tab.c $*.c

.y.o:
	yacc -d $(YFLAGS) $<
	mv y.tab.h $*.h
	cc $(CFLAGS) -o $*.o y.tab.c
	rm -f y.tab.c

# Dependencies not detected by 'mkmf'
tmgram.c : tmgram.y
###
debug.o: debug.h
refex.o: refex.h
tm.o: tmdefs.h tmvers.h tmds.h tmstring.h debug.h tmerror.h tmfn.h tmlex.h \
	tmmisc.h tmtplelm.h tmtrans.h tmvar.h tmglobal.h
tmds.o: tmdefs.h tmds.h tmstring.h debug.h tmglobal.h
tmerror.o: tmdefs.h tmds.h tmstring.h tmglobal.h debug.h tmerror.h
tmexpr.o: tmdefs.h tmds.h tmstring.h debug.h tmerror.h tmexpr.h tmglobal.h \
	tmmisc.h
tmfn.o: tmdefs.h refex.h tmds.h tmstring.h debug.h tmerror.h tmfn.h \
	tmglobal.h tmmisc.h tmvar.h
tmglobal.o: tmdefs.h tmds.h tmstring.h tmglobal.h
tmgram.o: tmdefs.h tmds.h tmstring.h debug.h tmerror.h tmglobal.h tmlex.h \
	tmmisc.h
tmlex.o: tmdefs.h tmds.h tmstring.h debug.h tmerror.h tmgram.h tmglobal.h \
	tmlex.h tmmisc.h
tmmisc.o: tmdefs.h debug.h tmmisc.h tmerror.h
tmstring.o: tmdefs.h debug.h tmds.h tmstring.h tmmisc.h tmerror.h
tmtplelm.o: tmdefs.h debug.h tmtplelm.h tmds.h tmstring.h tmglobal.h
tmtrans.o: tmdefs.h tmds.h tmstring.h debug.h tmfn.h tmexpr.h tmerror.h \
	tmglobal.h tmlibpath.h tmtplelm.h tmmisc.h tmtrans.h tmvar.h tmvers.h
tmvar.o: tmdefs.h tmds.h tmstring.h tmmisc.h debug.h tmerror.h tmvar.h \
	tmglobal.h
