# (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: Makefile
# Author: Andy Lowry
# SCCS Info: @(#)Makefile	1.30 6/18/90

include make/includefile

MBINS =	chgram hermes hermi asm sunwindow xwindow

# make variables to be propogated to inferior make's... there are a
# few diferent sets that are used in various situations
MAKEVARS =	HROOT=$(HROOT) MTYPE=$(MTYPE)
GENMAKEVARS =	HROOT=$(GENHROOT) MTYPE=$(MTYPE)

# HROOT should give the path name of the root directory for the hermes
# tree to be built
newversion:
	-if [ ! -d $(BINDIR) ] ; then mkdir $(BINDIR) ; fi
	-if [ ! -d $(HROOT)/mbin ] ; then mkdir $(HROOT)/mbin ; fi
	-if [ ! -d $(MBINDIR) ] ; then mkdir $(MBINDIR) ; fi

# HROOT should give the current working system root, GENHROOT should
# be the root of the system being generated
precompilerboot:
	@if [ ! -d $(BINDIR) ] ; then \
		$(MAKE) newversion $(GENMAKEVARS) ; fi
	$(MAKE) cleanbin cleanmbin $(GENMAKEVARS)
	( cd $(HROOT)/interface; \
		$(MAKE) clean-dofiles boot install-dofiles \
		$(MAKEVARS) GENHROOT=$(GENHROOT) )
	( cd $(HROOT)/hermes/defs ; \
		$(MAKE) clean boot \
		$(MAKEVARS) GENHROOT=$(GENHROOT) )
	( cd $(HROOT)/codegen/com ; \
		$(MAKE) clean boot-dofiles \
		$(MAKEVARS) GENHROOT=$(GENHROOT) )
	( cd $(HROOT)/hermes/ligen ; \
		$(MAKE) clean install \
		$(MAKEVARS) GENHROOT=$(GENHROOT) )
	( cd $(HROOT)/codegen/ligen ; \
		$(MAKE) clean install \
		$(MAKEVARS) GENHROOT=$(GENHROOT) )
	$(MAKE) update-lifiles $(MAKEVARS)

# HROOT should give working system root
# Following target generates the li sources that are included in 
# the source distribution
generate-lifiles:
	( cd $(HROOT)/hermes/ligen ; \
		$(MAKE) clean install $(MAKEVARS) )
	( cd $(HROOT)/codegen/ligen ; \
		$(MAKE) clean install $(MAKEVARS) )

# Following target updates any generated  .li source files that that
# have changed since last checked in to sccs
update-lifiles:
	- chmod +x $(HROOT)/update_sccs
	( cd $(HROOT)/hermes/liboot ; $(HROOT)/update_sccs *.li )
	( cd $(HROOT)/codegen/li ; $(HROOT)/update_sccs *.li )

# HROOT should give the root of the system being booted
boot:	miscboot interpboot compilerboot disasmboot toolsboot demoboot

# GENHROOT should be the root of the system being booted, HROOT should be
# a working floor system
newversionboot:
	@if [ ! -d $(GENHROOT)/bin) ] ; then \
		$(MAKE) newversion $(GENMAKEVARS) ; fi
	$(MAKE) cleanbin cleanmbin $(GENMAKEVARS)
	$(MAKE) miscboot $(GENMAKEVARS)
	$(MAKE) interpboot $(GENMAKEVARS)
	$(MAKE) precompilerboot $(MAKEVARS) GENHROOT=$(GENHROOT)
	$(MAKE) compilerboot $(GENMAKEVARS)
	$(MAKE) disasmboot $(GENMAKEVARS)
	$(MAKE) toolsboot $(GENMAKEVARS)
	$(MAKE) demoboot $(GENMAKEVARS)

# HROOT should be the root of the system being booted
interpboot:
	( cd $(HROOT)/lib ; \
		$(MAKE) clean all $(MAKEVARS) $(ALTFLAGS) )
	( cd $(HROOT)/fe ;  \
		$(MAKE) clean install-chgram $(MAKEVARS) $(ALTFLAGS) )
	( cd $(HROOT)/interface ; \
		$(MAKE) clean-cdfiles install-cdfiles $(MAKEVARS) \
		$(ALTFLAGS) )
	( cd $(HROOT)/cherm ; \
		$(MAKE) clean all $(MAKEVARS) $(ALTFLAGS) )
	( cd $(HROOT)/cfunc ; \
		$(MAKE) clean all $(MAKEVARS) $(ALTFLAGS) )
	( cd $(HROOT)/li ; \
		$(MAKE) clean pre-fe $(MAKEVARS) $(ALTFLAGS) )
	( cd $(HROOT)/fe ; \
		$(MAKE) install $(MAKEVARS) $(ALTFLAGS) )
	( cd $(HROOT)/li ; \
		$(MAKE) install $(MAKEVARS) $(ALTFLAGS) )
	( cd $(HROOT)/asm ; \
		$(MAKE) clean install $(CLEAN) $(MAKEVARS) $(ALTFLAGS) )
	@if [ "$(CLEAN)" ] ; then \
		$(MAKE) interpclean $(MAKEVARS) ; fi

# Following target cleans up the development directories after an
# interpreter build, to save disk space
interpclean:
	( cd $(HROOT)/lib ; $(MAKE) $(CLEAN) )
	( cd $(HROOT)/cherm ; $(MAKE) $(CLEAN) )
	( cd $(HROOT)/cfunc ; $(MAKE) $(CLEAN) )
	( cd $(HROOT)/li ; $(MAKE) $(CLEAN) )
	( cd $(HROOT)/fe ; $(MAKE) $(CLEAN) )
	( cd $(HROOT)/asm ; $(MAKE) $(CLEAN) )

sunwindow:
	( cd $(HROOT)/windows/sunview ; \
		$(MAKE) clean install $(CLEAN) $(MAKEVARS) )

xwindow:
	( cd $(HROOT)/windows/xwindow ; \
		$(MAKE) clean install $(CLEAN) $(MAKEVARS) )

# Make an alternate interpreter... set HROOT to the system rootdir,
# ALTNAME to a name identifying this intepreter, and ALTFLAGS to cc
# flags that will cause the interpreter you want to be built.  E.g.:
# for an optimized interpreter: 'make altinterp HROOT=/hermes ALTNAME=opt
# ALTFLAGS="OPTFLAG=-O3"'; for a quickcell debugging interpreter:
# 'make alterinterp HROOT=/hermes ALTNAME=qcdebug 
# ALTFLAGS="HANDCFLAGS=-DQCDEBUG=0"'
altinterp:	savestdinterp interpboot savealtinterp usestdinterp

savestdinterp:
	@if [ ! -d $(MBINDIR)/std ] ; then mkdir $(MBINDIR)/std ; fi
	( cd $(MBINDIR) ; cp $(MBINS) std )

savealtinterp:
	@if [ ! -d $(MBINDIR)/$(ALTNAME) ] ; \
		then mkdir $(MBINDIR)/$(ALTNAME) ; fi
	( cd $(MBINDIR) ; cp $(MBINS) $(ALTNAME) )

usestdinterp:
	( cd $(MBINDIR)/std ; cp $(MBINS) .. )

usealtinterp:
	( cd $(MBINDIR)/$(ALTNAME) ; cp $(MBINS) .. )

# make sure they specify ALTNAME If they invoke the above targets...
ALTNAME =	bogus altname

# HROOT should be root ofthe system being booted
compilerboot:	cleanbin \
		basiccompiler tccompiler tscompiler checkedcompiler

# bare bones compiler, and the cache to make life bearable.  pcom and
# dcom are both available, but there's no type checking, no type
# inferencing (so programs must be typemarked), and no typestate
# checking.  Definitions modules are not fixdef'ed.
basiccompiler:
	( cd $(HROOT)/interface ; \
		$(MAKE) clean-dofiles boot install-dofiles $(MAKEVARS) )
	( cd $(HROOT)/hermes/defs ; \
		$(MAKE) clean boot $(MAKEVARS) )
	( cd $(HROOT)/hermes/liboot ; \
		$(MAKE) clean install $(CLEAN) $(MAKEVARS) )
	( cd $(HROOT)/codegen/com ; \
		$(MAKE) clean boot-dofiles $(MAKEVARS) )
	( cd $(HROOT)/codegen/p1 ; \
		$(MAKE) clean install $(MAKEVARS) )
	( cd $(HROOT)/hermes/io ; \
		$(MAKE) clean boot install $(CLEAN) $(MAKEVARS) )
	( cd $(HROOT)/hermes ; \
		$(MAKE) clean tcboot basicinstall $(MAKEVARS) )
	( cd $(HROOT)/tools/cache ; \
		$(MAKE) clean boot install $(CLEAN) $(MAKEVARS) )
	( cd $(HROOT)/codegen/com ; \
		$(MAKE) all $(MAKEVARS) )
	( cd $(HROOT)/codegen/p2 ; \
		$(MAKE) clean all $(MAKEVARS) )
	( cd $(HROOT)/codegen/p3 ; \
		$(MAKE) clean install $(CLEAN) $(MAKEVARS) )
	@if [ "$(CLEAN)" ] ; then \
		$(MAKE) codegenclean $(MAKEVARS) ; fi

# Following target cleans up the codegen build directories after a
# normal build, to save disk space
codegenclean:
	( cd $(HROOT)/codegen/p1 ; $(MAKE) $(CLEAN) )
	( cd $(HROOT)/codegen/p2 ; $(MAKE) $(CLEAN) )
	( cd $(HROOT)/codegen/p3 ; $(MAKE) $(CLEAN) )

# type-checking compiler.  pcom does type checking and type
# inferencing.  dcom still does not do fixdef.
tccompiler:
	( cd $(HROOT)/interface/gentab ; \
		$(MAKE) clean install $(CLEAN) $(MAKEVARS) )
	( cd $(HROOT)/type/defs ; \
		$(MAKE) clean all $(MAKEVARS) )
	( cd $(HROOT)/type/common ; \
		$(MAKE) clean install $(CLEAN) $(MAKEVARS) )
	( cd $(HROOT)/type/bootstrap ; \
		$(MAKE) clean all $(MAKEVARS) )
	( cd $(HROOT)/hermes ; \
		$(MAKE) tsboot basicinstall $(MAKEVARS) )
	( cd $(HROOT)/type/checker ; \
		$(MAKE) clean install $(CLEAN) $(MAKEVARS) )
	@if [ "$(CLEAN)" ] ; then \
		( cd $(HROOT)/type/bootstrap ; $(MAKE) $(CLEAN) ) ; fi


# the full compiler, but the compiler itself has not been checked...
# violations may have gone undetected, and even barring that, no
# coercions have been generated in any of the compiler modules, so
# a great deal of storage will be wasted.  make 'compiler2' to correct
# this situation.
tscompiler:
	( cd $(HROOT)/hermes/absformat ; \
		$(MAKE) clean install $(CLEAN) $(MAKEVARS) )
	( cd $(HROOT)/hermes ; \
		$(MAKE) install $(MAKEVARS) )
	( cd $(HROOT)/typestate ; \
		$(MAKE) clean install $(MAKEVARS) )
	( cd $(HROOT)/hermes ; \
		$(MAKE) final install $(CLEAN) $(MAKEVARS) )

# Following target makes a fully checked and coerced compiler, given a
# fully functional but unchecked compiler.
checkedcompiler:
	( cd $(HROOT)/interface ; \
		$(MAKE) fixdefs install-dofiles $(MAKEVARS) )
	( cd $(HROOT)/hermes/defs ; \
		$(MAKE) fixdefs $(MAKEVARS) )
	( cd $(HROOT)/hermes/absformat ; \
		$(MAKE) clean install $(CLEAN) $(MAKEVARS) )
	( cd $(HROOT)/hermes ; \
		$(MAKE) clean install $(CLEAN) $(MAKEVARS) )
	( cd $(HROOT)/hermes/io ; \
		$(MAKE) clean install $(CLEAN) $(MAKEVARS) )
	( cd $(HROOT)/codegen/com ; \
		$(MAKE) fixdefs $(MAKEVARS) )
	( cd $(HROOT)/codegen/p3 ; \
		$(MAKE) clean install $(CLEAN) \
			$(MAKEVARS) LOADPATH=$(BINDIR) )
	( cd $(HROOT)/type/defs ; \
		$(MAKE) fixdefs $(MAKEVARS) )
	( cd $(HROOT)/type/common ; \
		$(MAKE) clean install $(CLEAN) $(MAKEVARS) )
	( cd $(HROOT)/type/checker ; \
		$(MAKE) clean install $(CLEAN) $(MAKEVARS) )
	( cd $(HROOT)/typestate ; \
		$(MAKE) procclean fixdefs install $(CLEAN) $(MAKEVARS) )
	@if [ "$(CLEAN)" ] ; then \
		( cd $(HROOT)/interface ; $(MAKE) $(CLEAN) ) ; fi

# HROOT should be the root of the system being booted

disasmboot:
	( cd $(HROOT)/disassembler ; \
		$(MAKE) clean install $(CLEAN) $(MAKEVARS) )

# HROOT should be the root of the system being booted

toolsboot:
	( cd $(HROOT)/tools/cache ; \
		$(MAKE) clean install $(CLEAN) $(MAKEVARS) )
	( cd $(HROOT)/tools/string ; \
		$(MAKE) clean install $(CLEAN) $(MAKEVARS) )
	( cd $(HROOT)/tools/make/defs ; \
		touch Makefile.deps ; $(MAKE) deps $(MAKEVARS) ; \
		$(MAKE) clean install $(MAKEVARS) )
	( cd $(HROOT)/tools/make ; \
		touch Makefile.deps ; $(MAKE) deps $(MAKEVARS) ; \
		$(MAKE) clean install $(CLEAN) $(MAKEVARS) )
	( cd $(HROOT)/tools/printobj ; \
		$(MAKE) clean install $(CLEAN) $(MAKEVARS) )
	( cd $(HROOT)/tools/tokenize ; \
		$(MAKE) clean install $(CLEAN) $(MAKEVARS) )
	( cd $(HROOT)/tools/shell ; \
		$(MAKE) clean install $(CLEAN) $(MAKEVARS) )
	( cd $(HROOT)/tools/unixcmd ; \
		$(MAKE) clean install $(CLEAN) $(MAKEVARS) )
	( cd $(HROOT)/tools/rmanager ; \
		touch Makefile.deps; $(MAKE) deps $(MAKEVARS) ; \
		$(MAKE) clean install $(CLEAN) $(MAKEVARS) )
	( cd $(HROOT)/tools/pipe ; \
		$(MAKE) clean install $(CLEAN) $(MAKEVARS) )
	( cd $(HROOT)/tools/pshell ; \
		$(MAKE) clean install $(CLEAN) $(MAKEVARS) )
	(cd $(HROOT)/tools/distrib ; \
		touch Makefile.deps ; $(MAKE) deps $(MAKEVARS) ; \
		$(MAKE) clean install $(CLEAN) $(MAKEVARS) )
	( cd $(HROOT)/tools/profile ; \
		$(MAKE) clean install $(CLEAN) $(MAKEVARS) )
	( cd $(HROOT)/windows ; \
		$(MAKE) clean install $(CLEAN) $(MAKEVARS) )

# HROOT should be the root of hte system being booted
demoboot:
	( cd $(HROOT)/demo ; \
		$(MAKE) deps cleanall install $(CLEAN) $(MAKEVARS) )

# HROOT should be the root of the system being booted
miscboot:
	@if [ ! -f $(BINDIR)/getdeps ] ; then \
		cp $(HROOT)/getdeps $(BINDIR) ; fi
	chmod +x $(BINDIR)/getdeps

# Remove everything from the binaries directories for the current
# hermes system (machine-dependent binaries only)
cleanmbin:
	( cd $(MBINDIR) ; rm -f * 2>/dev/null )

# Remove machine-independent binaries from the current system
cleanbin:
	( cd $(BINDIR) ; rm -f *.?o 2>/dev/null )

# Clean up all the build directories, without destroying any of the
# binaries
cleanbuild:
	rm -r $(CDDIR)
	( cd $(HROOT)/lib ; $(MAKE) clean $(MAKEVARS) )
	( cd $(HROOT)/cherm ; $(MAKE) clean $(MAKEVARS) )
	( cd $(HROOT)/cfunc ; $(MAKE) clean $(MAKEVARS) )
	( cd $(HROOT)/fe ; $(MAKE) clean $(MAKEVARS) )
	( cd $(HROOT)/li ; $(MAKE) clean $(MAKEVARS) )
	( cd $(HROOT)/asm ; $(MAKE) clean $(MAKEVARS) )
	( cd $(HROOT)/interface ; $(MAKE) clean $(MAKEVARS) )
	( cd $(HROOT)/interface/gentab ; $(MAKE) clean $(MAKEVARS) )
	( cd $(HROOT)/hermes ; $(MAKE) clean $(MAKEVARS) )
	( cd $(HROOT)/hermes/defs ; $(MAKE) clean $(MAKEVARS) )
	( cd $(HROOT)/hermes/liboot ; $(MAKE) clean $(MAKEVARS) )
	( cd $(HROOT)/hermes/ligen ; $(MAKE) clean $(MAKEVARS) )
	( cd $(HROOT)/hermes/io ; $(MAKE) clean $(MAKEVARS) )
	( cd $(HROOT)/hermes/absformat ; $(MAKE) clean $(MAKEVARS) )
	( cd $(HROOT)/codegen/com ; $(MAKE) clean $(MAKEVARS) )
	( cd $(HROOT)/codegen/p1 ; $(MAKE) clean cleansrc $(MAKEVARS) )
	( cd $(HROOT)/codegen/p2 ; $(MAKE) clean $(MAKEVARS) )
	( cd $(HROOT)/codegen/p3 ; $(MAKE) clean $(MAKEVARS) )
	( cd $(HROOT)/codegen/ligen ; $(MAKE) clean $(MAKEVARS) )
	( cd $(HROOT)/type/defs ; $(MAKE) clean $(MAKEVARS) )
	( cd $(HROOT)/type/common ; $(MAKE) clean $(MAKEVARS) )
	( cd $(HROOT)/type/bootstrap ; $(MAKE) clean $(MAKEVARS) )
	( cd $(HROOT)/type/checker ; $(MAKE) clean $(MAKEVARS) )
	( cd $(HROOT)/typestate ; $(MAKE) clean $(MAKEVARS) )
	( cd $(HROOT)/windows ; $(MAKE) clean $(MAKEVARS) )
	( cd $(HROOT)/windows/sunview ; $(MAKE) clean $(MAKEVARS) )
	( cd $(HROOT)/disassembler ; $(MAKE) clean $(MAKEVARS) )
	( cd $(HROOT)/tools/cache ; $(MAKE) clean $(MAKEVARS) )
	( cd $(HROOT)/tools/string ; $(MAKE) clean $(MAKEVARS) )
	( cd $(HROOT)/tools/make ; \
		touch Makefile.deps ; $(MAKE) clean $(MAKEVARS) )
	( cd $(HROOT)/tools/make/defs ; \
		touch Makefile.deps ; $(MAKE) clean $(MAKEVARS) )
	( cd $(HROOT)/tools/printobj ; $(MAKE) clean $(MAKEVARS) )
	( cd $(HROOT)/tools/tokenize ; $(MAKE) clean $(MAKEVARS) )
	( cd $(HROOT)/tools/shell ; $(MAKE) clean $(MAKEVARS) )
	( cd $(HROOT)/tools/unixcmd ; $(MAKE) clean $(MAKEVARS) )
	( cd $(HROOT)/tools/rmanager ; \
		touch Makefile.deps ; $(MAKE) clean $(MAKEVARS) )
	( cd $(HROOT)/tools/pipe ; $(MAKE) clean $(MAKEVARS) )
	( cd $(HROOT)/tools/pshell ; $(MAKE) clean $(MAKEVARS) )
	( cd $(HROOT)/tools/profile ; $(MAKE) clean $(MAKEVARS) )
	( cd $(HROOT)/tools/distrib ; \
		touch Makefile.deps ; $(MAKE) clean $(MAKEVARS) )
	( cd $(HROOT)/demo ; $(MAKE) clean $(MAKEVARS) )
