# (C) Copyright International Business Machines Corporation 23 January 
# 1990.  All Rights Reserved. 
#  
# See the file USERAGREEMENT distributed with this software for full 
# terms and conditions of use. 
# File: includefile
# Author: David F. Bacon
# SCCS Info: @(#)includefile	1.14 3/21/90

# Standard included rules and definitions for Makefiles

# Put an 'all' target here so it becomes the default if this file is
# included before any specific targets 
all:

# suffixes used by the hermes system
.SUFFIXES: .li .po .d .do .cd .ch .p .pp

# root of the hermes tree
HROOT	=	$(HROOTDIR)
# where we install files from the current compiler
BINDIR	=	$(HROOT)/bin
#  Machine type... should be redefined for any installation that needs
# to support multiple architectures in a single Hermes tree.
# Something like "MTYPE=foo" on the make command line will usually
# suffice.
MTYPE	=	.
# Where the machine-dependent binaries are stored
MBINDIR =	$(HROOT)/mbin/$(MTYPE)
# *.po files of the compiler
PROCDIR	=	$(BINDIR)
# *.do and other hermes objects for the compiler
DEFDIR	=	$(BINDIR)
# *.cd files for the compiler
CDDIR	=	$(HROOT)/interface/cd
# interface specs
INTERFACE=	$(HROOT)/interface

# the front end
HERMES	=	$(MBINDIR)/hermes
# the back end
HERMI	=	$(MBINDIR)/hermi
# the .d to .cd file translator
CHGRAM	=	$(MBINDIR)/chgram
# the assembler
ASM	=	$(MBINDIR)/asm
# hermes include files for c preprocessor
INCLUDE	=	$(HROOT)/include

# Hermes compilation environment
LOADPATH=	$(PROCDIR):.
DEFPATH	=	.:$(DEFDIR)
LINKPATH=	.:$(PROCDIR)
ROOTPROG=	$(PROCDIR)/root.po
HERMENV	=	HROOTPROG=$(ROOTPROG) HPATH=$(DEFPATH) \
		HLOADPATH=$(LOADPATH) HLINKPATH=$(LINKPATH) \
		HROOTDIR=$(HROOT)

# Following target invokes the 'clean' target, even if 'clean' has
# already been made earlier in this same make.
reclean:
	@$(MAKE) clean HROOT=$(HROOT) MTYPE=$(MTYPE)

# The program & object cacheing main filter
CACHE =		cache

# Command to compile a process module
PCOM =		pcom
PCOMCMD =	env $(HERMENV) $(HERMI) $(CACHE) $(PCOM) $(PCOMOPTS)
PCOMOPTS =

# Command to compile a definitions module
DCOM =		dcom
DCOMCMD =	env $(HERMENV) $(HERMI) $(CACHE) $(DCOM) $(DCOMOPTS)
DCOMOPTS =

# Following target builds all the process modules (.lo files) named in
# $(PROCOBJS).  All prerequisite files must already have been built
compileprocs:
	@plist=`$(MAKE) -n procobjs HROOT=$(HROOT) GENHROOT=$(GENHROOT)` ; \
		if [ "$$plist" ] ; then \
		  echo $(PCOMCMD) $$plist ; $(PCOMCMD) $$plist ; fi
procobjs:	$(PROCOBJS)

# Following target builds all the definitions modules (.do files)
# named in $(DEFOBJS).  All prerequisite files must already have been
# built.
compiledefs:
	@dlist=`$(MAKE) -n defobjs HROOT=$(HROOT) GENHROOT=$(GENHROOT)` ; \
		if [ "$$dlist" ] ; then \
		  echo $(DCOMCMD) $$dlist ; $(DCOMCMD) $$dlist ; fi
defobjs:	$(DEFOBJS)

# Change commentedness of following lines as appropriate if you are
# building on an iris workstation.
# Extra include directories needed on the iris
#IRISINCS =	-I/usr/include/sun -I/usr/include/bsd
IRISINCS =
# Extra libraries needed on the iris
#IRISLIBS =	-lsun -lbsd -lcfunc
IRISLIBS =
# Name of ranlib program... on iris, ranlib functionality is
# automatic, so just use 'true' 
RANLIB =	ranlib
#RANLIB =	true


# the C preprocessor
CPP	=	/lib/cpp
# where to look for include files... each entry prefixed by "-I"
INCDIRS =	-I$(INCLUDE) -I$(CDDIR)
# Flags when preprocessing C sources
CPPFLAGS =	$(INCDIRS) $(EXTRACPPFLAGS)
# Flags when processing Hermes sources... suppress #line directives
HCPPFLAGS=	-P $(CPPFLAGS)

# C compiler flags - leave empty or set as appropriate
# OPTFLAG: "-O" turns on C compiler optimization
OPTFLAG =
# DEBUGFLAG: "-DDEBUG" compiles in debugging support
DEBUGFLAG =	-DDEBUG
# TRACEFLAG: "-DTRACE" compiles in trace support
TRACEFLAG =	-DTRACE
# DBXFLAG: "-g" compiles in info for use by dbx
DBXFLAG =	-g
# PROFFLAG: "-p" compiles in flat profiling support, "-pg" compiles 
# in call-graph profiling support
PROFFLAG =	
# C compiler
CC	=	cc
CFLAGS	=	$(OPTFLAG) $(DEBUGFLAG) $(TRACEFLAG) $(DBXFLAG) \
		$(PROFFLAG) $(INCDIRS) $(LIBDIRS) $(EXTRACFLAGS) \
		$(HANDCFLAGS)

# lint
LINT	=	lint
LFLAGS	=	-abhuxz $(DEBUGFLAG) $(TRACEFLAG) $(INCDIRS) \
		$(LINTLIBS)

# C-Hermes
CHERM	=	m4 ../cherm/cherm2c.m4
CHERM2	=	sed -f ../cherm/cherm2c.sed

###############################################################################
#                                     Rules                                   #
###############################################################################

.d.do: $<
	$*

.pp.p:	$<
	$(CPP) $(HCPPFLAGS) $< | sed 's/@TYPEMARK@/#/g' > $@

.p.po:	$<
	$*

.d.cd: $<
	$(CHGRAM) $<  >$@

.ch.c: $<
	$(CHERM) $< | $(CHERM2) >$@

.c.o:
	$(CC) $(CFLAGS) -c $<
