# (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. 
# SCCS Info: @(#)Makefile	1.21 5/10/90

DEFOBJS =	predefined.do checking_table.do  \
		inferredtype.do stdenv.do positions.do posmap.do \
		interpform.do listuff.do \
		errors.do typecheck.do \
		coercions.do filedef.do common.do cload.do \
		root.do main.do findfile.do pathload.do unix.do \
		pathreadobj.do load.do terminalio.do objectio.do \
		codegen.do loadprog.do cwd.do \
		printobj.do type_inference.do typestate_inference.do \
		parse.do initparse.do unixstat.do annotate.do \
		initfindfile.do disassembler.do formaterror.do getfile.do \
		window.do cwindow.do fdhandlers.do profile.do absformat.do \
		typestate.do distributed.do safewindow.do safewindowinit.do \
		safewindowgen.do terminalinits.do

CDS	=	predefined.cd interpform.cd filedef.cd inferredtype.cd \
		cload.cd unix.cd main.cd load.cd objectio.cd codegen.cd \
		root.cd stdenv.cd printobj.cd coercions.cd posmap.cd \
		parse.cd initparse.cd unixstat.cd positions.cd \
		window.cd cwindow.cd fdhandlers.cd errors.cd profile.cd \
		listuff.cd distributed.cd

TABLES	=	builtin_exception.table operator.table opcode.table

include ../make/includefile

# Set GENHROOT to something other than the floor system root in order to
# install into a new system tree (used by precompilerboot target in root
# make file)

GENHROOT =	$(HROOT)
GENBIN =	$(GENHROOT)/bin

# parameterize the .d.do rule so we can bootstrap with the standalone parser
.d.do:	$<
	$(STANDALONE) $*$(DEFSUFFIX)
STANDALONE =
DEFSUFFIX =

all:	$(CDS) $(TABLES) compiledefs

install:	$(TABLES) install-cdfiles install-dofiles
install-cdfiles: cddir $(CDS)
	cp $(CDS) $(CDDIR)
install-dofiles: compiledefs
	cp $(DEFOBJS) $(GENBIN)

# Following target runs 'fixdefs' on all the definitions modules,
# which may have been originally compiled without fixdefing.  The
# following kluge is used to make sure we fixdef things in the correct
# order: (1) move all the .do files to another temporary directory;
# (2) use 'make -n defobjs' to get the correctly ordered list of
# module names; (3) move the .do files back; and (4) run fixdefs

fixdefs:
	@-mkdir .dosave 2>/dev/null; 
	@-rm -f .dosave/* 2>/dev/null
	@mv *.do .dosave
	@dlist=`make -n defobjs` ; echo $$dlist > .dlist
	@mv .dosave/* .
	@rmdir .dosave
	@dlist=`cat .dlist` ; rm .dlist ; \
		echo env $(HERMENV) $(HERMI) $(CACHE) fixdefs $$dlist ; \
		env $(HERMENV) $(HERMI) $(CACHE) fixdefs $$dlist

boot:	$(CDS) $(TABLES)
	$(MAKE) defobjs HROOT=$(HROOT) MTYPE=$(MTYPE) \
		STANDALONE="sleep 1; env $(HERMENV) $(HERMES)" DEFSUFFIX=".d"

cdfiles: $(CDS)

cddir:
	@- if [ ! -d $(CDDIR) ] ; then mkdir $(CDDIR) ; fi

predefined.cd: predefined.d
	$(CHGRAM) predefined.d | \
	  sed -e '/char___ 95/ s/\(.*\)/\/\* \1 \*\//' >predefined.cd

opcodes.hd: greencard
	awk -f opcodes.awk greencard >opcodes.hd

interpform.d: interpform.dd opcodes.hd
	$(CPP) $(HCPPFLAGS) interpform.dd >interpform.d

annontate.do: annontate.d common.do

initparse.do: initparse.d load.do objectio.do cwd.do parse.do

unixstat.do: unixstat.d predefined.do unix.do

annotate.do: annotate.d predefined.do common.do

codegen.do: codegen.d predefined.do load.do stdenv.do unix.do annotate.do

cwd.do: cwd.d predefined.do

objectio.do: objectio.d common.do

loadprog.do: loadprog.d objectio.do parse.do posmap.do

load.do: load.d predefined.do

terminalio.do: terminalio.d predefined.do

filedef.do: filedef.d parse.do

errors.do: errors.d predefined.do positions.do type_inference.do

parse.do: parse.d predefined.do posmap.do errors.do

formaterror.do: formaterror.d predefined.do errors.do common.do absformat.do \
	inferredtype.do posmap.do

getfile.do: getfile.d predefined.do unix.do

posmap.do: posmap.d predefined.do positions.do

stdenv.do: stdenv.d predefined.do common.do terminalio.do objectio.do \
	load.do cwd.do

typecheck.do: typecheck.d predefined.do checking_table.do \
	inferredtype.do errors.do stdenv.do

coercions.do: coercions.d predefined.do positions.do

common.do: common.d predefined.do 

cload.do: cload.d predefined.do common.do

root.do: root.d predefined.do  cload.do common.do 

unix.do: unix.d predefined.do 

findfile.do: findfile.d common.do  unix.do

initfindfile.do: initfindfile.d findfile.do unix.do cwd.do

pathload.do: pathload.d stdenv.do findfile.do

pathreadobj.do: pathreadobj.d stdenv.do findfile.do

main.do: main.d common.do root.do stdenv.do unix.do

interpform.do: interpform.d predefined.do

listuff.do:	interpform.do

inferredtype.do: inferredtype.d predefined.do

positions.do: positions.d predefined.do

checking_table.do: checking_table.d predefined.do type_inference.do \
	typestate_inference.do

type_inference.do: type_inference.d predefined.do

typestate_inference.do: typestate_inference.d predefined.do

libinit.do: libinit.d objectio.do load.do

printobj.do: printobj.d common.do

disassembler.do: disassembler.d predefined.do interpform.do stdenv.do

window.do: window.d predefined.do common.do stdenv.do cload.do terminalio.do

fdhandlers.do: fdhandlers.d predefined.do unix.do

cwindow.do: cwindow.d predefined.do unix.do

profile.do: profile.d predefined.do

absformat.do: absformat.d predefined.do inferredtype.do errors.do posmap.do

typestate.do: typestate.d stdenv.do coercions.do checking_table.do \
	inferredtype.do errors.do

distributed.do: distributed.d common.do

safewindow.do: terminalio.do

safewindowinit.do: safewindow.do cload.do main.do

safewindowgen.do: safewindow.do terminalio.do common.do

terminalinits.do: predefined.do unix.do terminalio.do

# tables of enumeration values

opcode.table: interpform.d
	awk "`sed -e s/TYPENAME/opcode/ getenum.awk`" interpform.d \
		> opcode.table

operator.table: predefined.d
	awk "`sed -e s/TYPENAME/operator/ getenum.awk`" predefined.d \
		> operator.table

builtin_exception.table: predefined.d
	awk "`sed -e s/TYPENAME/builtin_exception/ getenum.awk`" predefined.d \
		> builtin_exception.table

#
# cleanup
#

clean:
	rm -rf core *~ *~*~ *% *.cd *.do *.o opcodes.hd interpform.d \
	   .installed_do .installed_cd $(TABLES)
clean-dofiles:
	rm -rf *.do
clean-cdfiles:
	rm -rf *.cd
