# makefile

VERSION = 1

DOC	=

TEST =

PROGS   = dtm

SKELFILES = make.local

MAKEFILE = Makefile

LINKER = cc

TM = tm

JUNK = tmp core makelog tags lint \
       testout Xdtm Xuetm Xutm Xextm

DISTOTHERS = dtm_atoms.c edtm_atoms.c

DISTFILES = $(DISTSRCS) $(DISTHDRS) $(DOC) $(MAKEFILE) $(TMFILES) \
	    $(DISTOTHERS) $(TEST)

CFLAGS = -I$(IDIR) -D$(SYS) $(SYSCFLAGS) -g

LINTFLAGS = -I$(IDIR) -D$(SYS)

LIBS = $(LDIR)/libcvr.a $(LDIR)/libtmc.a $(CLIBLOC)

.SUFFIXES:
.SUFFIXES: .out .o .c .h .e .r .f .y .l .s .p .ht .ct

#when entering make do a make all 
default: all

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

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

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

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

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

FULLDS = $(ESPRITDIR)/ds/fullglass.ds
KERNDS = $(ESPRITDIR)/ds/kernglass.ds

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

#  HOSTNAME : name of installation machine.
HOSTNAME=phoibos

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

# CLIBLOC : required C libraries
CLIBLOC =

LINTLIBLOC =

PASLIBLOC =

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

SYSLINTFLAGS = -hac
SYSCFLAGS =
SYSCPROFFLAGS =
SYSCDBUGFLAGS =
SYSPFLAGS =

# 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)
	ranlib $(LDIR)/$(MODULE)
#++ make module local end, do NOT touch this line. ++

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

# .h files dtmerated from tm modules
TMHDRS	      = tmcode.h 

HDRS	      = tmcode.h \
		dtmconfig.h \
		dtmconst.h \
		utils.h \
		codestorage.h \
		typecache.h

OBJS         = tmcode.o utils.o dtm.o codestorage.o typecache.o

# .c files dtmerated from tm modules
TMSRCS        = tmcode.c

SRCS          = dtm.c tmcode.c utils.c codestorage.c typecache.c

# distributed tm source files
TMFILES = dtmconfig.t tmcode.ct tmcode.ht

# distributed .h files
DISTHDRS      = dtmconfig.h \
		dtmconst.h \
		utils.h \
		codestorage.h

# distributed .c files
DISTSRCS      = dtm.c utils.c codestorage.c

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	: $(PROGS)

dtm: $(OBJS)
	$(LINKER) $(LDFLAGS) $(OBJS) $(LIBS) -o dtm

# make rules for testing
test:
	@echo 'Sorry no testing available'

# run program and check output

install:  dtm scripts 
	make bininstall 'MODULE=dtm'
	make includeinstall 'MODULE=dtm_atoms.c'
	make includeinstall 'MODULE=edtm_atoms.c'
	make includeinstall 'MODULE=DtmMain.c'
	cp Xdtm Xextm Xuetm Xutm $(BDIR)

scripts: Xdtm Xuetm Xutm Xextm

Xdtm:
	echo 'cat $$1.sf | uflat | dtm -i > $$1.c' > Xdtm
	echo 'echo $(CC): compiling...' >> Xdtm
	echo '$(CC) -O -I$(IDIR) -c $$1.c' >> Xdtm
	echo 'echo $(CC): linking...' >> Xdtm
	echo '$(CC) -L$(LDIR) $$1.o -lxwa -lXaw -lXmu -lXt -lX11 -o X$$1' >>Xdtm
	echo 'echo executing...' >> Xdtm
	echo 'X$$1' >> Xdtm
	chmod 755 Xdtm

Xextm:
	echo 'cat $$1.sf | uflat | dtm > $$1.c' > Xextm
	echo 'echo $(CC): compiling...' >> Xextm
	echo '$(CC) -O -I$(IDIR) -c $$1.c' >> Xextm
	echo 'echo $(CC): linking...' >> Xextm
	echo '$(CC) -L$(LDIR) $$1.o -lxwa -lXaw -lXmu -lXt -lX11 -o X$$1'>>Xextm
	echo 'echo executing...' >> Xextm
	echo 'X$$1' >> Xextm
	chmod 755 Xextm

Xuetm:
	echo 'cat $$1.sf | uflat | dtm -u -e > $$1.c' > Xuetm
	echo 'echo $(CC): compiling...' >> Xuetm
	echo '$(CC) -O -I$(IDIR) -c $$1.c' >> Xuetm
	echo 'echo $(CC): linking...' >> Xuetm
	echo '$(CC) -L$(LDIR) $$1.o -lxwa -lXaw -lXmu -lXt -lX11 -o X$$1'>>Xuetm
	echo 'echo executing...' >> Xuetm
	echo 'X$$1' >> Xuetm
	chmod 755 Xuetm

Xutm:
	echo 'cat $$1.sf | uflat | dtm -u > $$1.c' > Xutm
	echo 'echo $(CC): compiling...' >> Xutm
	echo '$(CC) -O -I$(IDIR) -c $$1.c' >> Xutm
	echo 'echo $(CC): linking...' >> Xutm
	echo '$(CC) -L$(LDIR) $$1.o -lxwa -lXaw -lXmu -lXt -lX11 -o X$$1' >>Xutm
	echo 'echo executing...' >> Xutm
	echo 'X$$1' >> Xutm
	chmod 755 Xutm


clean:
	rm -f $(OBJS) $(TMSRCS) $(TMHDRS) $(JUNK) $(PROGS)

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

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

# Non-standard make rules

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

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

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

.ht.h:
	$(TM) dtm.ds $< > $*.h

.ct.c:
	$(TM) dtm.ds $< > $*.c

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

# Dependencies not detected by 'mkmf'
$(TMHDRS) : dtm.ds dtmconfig.t
$(TMSRCS) : dtm.ds dtmconfig.t
###
dtm.o: dtmconst.h tmcode.h utils.h
tmcode.o: dtmconfig.h tmcode.h dtmconst.h
utils.o: dtmconst.h tmcode.h utils.h
codestorage.o: codestorage.h
typecache.o: dtmconst.h tmcode.h utils.h
