/* (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.38 3/13/92*/

/* Standard included rules and definitions for Makefiles*/

/* use explicit shell - not default*/
SHELL	=	/bin/sh

#ifdef _MTYPE_bsdrt
ENV	=
#else
ENV	=	env
#endif

/* Most makes automatically define the following, but some do not... */
#ifdef _MTYPE_bsdrt
MAKE	=	make
#endif

/* 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

/* create a flag indicating whether this platform supports dynamic linking */
#if defined(_MTYPE_power) || defined(_MTYPE_sun4) || defined(_MTYPE_sun3)
#  define _DYNAMIC_LINKING_
#endif

/* always use $(HROOT) to refer to the root of the hermes directory */
/* tree... it defaults to the value set by make-makefiles, but in */
/* some recursive make's it needs to be redefined (see the */
/* "precompilerboot" target in the top-level makefile) */
HROOT	=	_HROOTDIR_
/* where we install files from the current compiler*/
BINDIR	=	$(HROOT)/bin
/* where we keep .c and .por files*/
CHBINDIR=	$(HROOT)/chbin
/* Override ALTNAME to build/use an alternative set of binaries*/
ALTNAME =	.
/* Where the machine-dependent binaries are stored*/
MBINDIR =	$(HROOT)/mbin/_MTYPE_/$(ALTNAME)
/* Where the machine-dependent C-object files are stored*/
MCHBINDIR =	$(HROOT)/mchbin/_MTYPE_/$(ALTNAME)
/* *.po files of the compiler*/
PROCDIR	=	$(BINDIR)
CHPROCDIR =	$(CHBINDIR)
/* *.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*/
HPARSE	=	$(MBINDIR)/hparse
/* the back end*/
HERMES	=	$(MBINDIR)/hermes
/* the .d to .cd file translator*/
CHGRAM	=	$(MBINDIR)/chgram
/* the assembler*/
ASM	=	$(MBINDIR)/asm
/* the object constructor*/
CONSTRUCT=	$(MBINDIR)/construct
/* hermes include files for c preprocessor*/
INCLUDE	=	$(HROOT)/include

/* Hermes compilation environment*/
#if defined(_MTYPE_power) || defined(_MTYPE_sun4) || defined(_MTYPE_sun3)
LOADPATH =	$(CHPROCDIR):$(PROCDIR):.
#else
LOADPATH =	$(PROCDIR):.
#endif
DEFPATH	=	.:$(DEFDIR)
LINKPATH=	.:$(PROCDIR)
ROOTPROG=	$(PROCDIR)/root.po
HERMENV	=	HROOTPROG=$(ROOTPROG) HPATH=$(DEFPATH) \
		HLOADPATH=$(LOADPATH) HLINKPATH=$(LINKPATH) \
		HROOTDIR=$(HROOT) HCOBJPATH=.:$(MCHBINDIR) HARCH=_MTYPE_

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

/* Command to compile a process module*/

/* We use the environment variable form of options setting for pcom so*/
/* that the options will be in effect when pcom is invoked via*/
/* makehermes and similar situations*/
PCOM =		pcom
PCOMCMD =	$(ENV) $(HERMENV) $(PCOMENV) $(PCOMSTRIPENV) \
		$(HERMES) $(CACHE) $(PCOM)
PCOMSTRIPENV =	PCOMstrip=
PCOMENV = 	

/* Command to compile a definitions module*/
DCOM =		dcom
DCOMCMD =	$(ENV) $(HERMENV) $(HERMES) $(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)


/* the MAKEHERMES program with its options*/
MAKEHERMES = makehermes
MAKEHERMESOPTS = 
MAKEHERMESENV =
MAKEHERMESCMD = $(ENV) $(HERMENV) $(PCOMENV) $(PCOMSTRIPENV) $(MAKEHERMESENV) \
	$(HERMES) $(MAKEHERMES) 

/* Alternatives for specific machines may be changed on the command line - e.g.*/
/* make ... RANLIB=true*/

/* Name of ranlib program
RANLIB =	ranlib

/* Additional libraries needed for specific architectures */
#ifdef _MTYPE_hpux
MACHLIBS =	-lBSD
#else
MACHLIBS =
#endif

/* HPUX needs -L spaces in -L options to loader (sigh!) */
#ifdef _MTYPE_hpux
LIBDIRS =	-L ../lib -L ../cherm -L ../cfunc -L ../fe -L ../li
#else
LIBDIRS =	-L../lib -L../cherm -L../cfunc -L../fe -L../li
#endif

/* 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*/
#ifdef _MTYPE_NeXT
CPPFLAGS =	-traditional $(INCDIRS) $(EXTRACPPFLAGS)
#else
CPPFLAGS =	$(INCDIRS) $(EXTRACPPFLAGS)
#endif

/* Flags when processing Hermes sources... suppress #line directives*/
HCPPFLAGS=	-P -Uunix $(CPPFLAGS)

/* C compiler flags - leave empty or set as appropriate*/
/* OPTFLAG: "-O" turns on C compiler optimization*/
OPTFLAG = -O
/* 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 =	
/* PROFFLAG: "-p" compiles in flat profiling support, "-pg" compiles */
/* in call-graph profiling support*/
PROFFLAG =	
/* Machine-specific extra C flags */
#ifdef _MTYPE_NeXT
/* use as bsd-like a compiler as we can get, and disable the assert macro, */
/* which appears to be broken with -traditional set */
MACHFLAGS = 	-traditional -bsd -DNDEBUG
#else
#ifdef _MTYPE_bsdrt
MACHFLAGS =	-Hnocpp
#else
MACHFLAGS =
#endif
#endif

CFLAGS =	$(DEBUGFLAG) $(TRACEFLAG) $(OPTFLAG) $(DBXFLAG) $(PROFFLAG) \
		$(MACHFLAGS) $(INCDIRS) $(EXTRACFLAGS) $(HANDCFLAGS)

/* C compiler*/
#ifdef _MTYPE_power
CC	=	bsdcc
#else
CC	=	cc
#endif

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

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

/* special load flags and libraries needed to support dynamic loading */
/* of chcoded hermes processes */ 
#if defined(_MTYPE_sun4) || defined(_MTYPE_sun3)
DLOADFLAGS =	-DDLOAD
DLOADLIBS  =	-ldl
#else
#  if defined(_MTYPE_power)
DLOADFLAGS =	-DDLOAD
DLOADLIBS  =	-bexport:$(HROOT)/chaux/exports.power
#  else
DLOADFLAGS =
DLOADLIBS  =
#  endif
#endif

/* support for chcoded .po files*/
CHCODE =	chcode
CHCODEOPTS =
STDCHCODEOPTS =	-verbose -comment -store=$(CHBINDIR)/skel -nostoreObj \
		-storeC=$(CHBINDIR)/src -load=.
COMPILECHCODEOPTS = -verbose -store=$(CHBINDIR) -storeObj=$(MCHBINDIR) \
		-load=$(CHBINDIR)/skel -storeC=$(CHBINDIR)/src -notransform
CHCODECMD =	$(ENV) $(HERMENV) $(HERMES) $(CHCODE) \
			$(CHCODEOPTS) $(STDCHCODEOPTS)
CHCOMPILECMD =	$(ENV) $(HERMENV) $(HERMES) $(CHCODE) \
			$(CHCODEOPTS) $(COMPILECHCODEOPTS)

GARBAGE	=	core a.out *.o *.a *.po *.do *.ao *.po.Z *.do.Z *.ao.Z *~ *.ln

/* add to following target by definining extra clean:: targets if needed */
clean::
	rm -f $(GARBAGE)

/*#########################################################################*/
/*#                               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 $<
