#
#	File:		Build
#
#	Contains:	Script to build Gus
#
#	Version:	Gus 1.0
#
#	Written by: Andy Nicholas, Jim Murphy, Dave Lyons, Mike Neil
#				Based on Finder 7.x's build script
#
#	Copyright:	 1993-1996 by Apple Computer, Inc., All Rights Reserved.
#
#	Build -EmulatorGS						Build Gus.rsrc, put it in the projects folder
#											Also build the EmulatorGS shared Library for Metrowerks
#											and put it into the Projects folder also...
#
#	Build									build Gus, no debug, Symantec C++ compiler
#	Build -makemake							build Gus, but rebuild the makefile first
#	Build -makemake -nomake					build Makefile only
#	Build -debug							build Gus, with debug code
#	Build -mrc								build Gus, use MrC, assembly emulator abd memory accessors
#   Build -xlc								build Gus, use xlc, assembly emulator and memory accessors
#	Build -moto								build Gus, use Motorola compiler, assembler emulator and memory accessors
#	Build -nonames							build Gus, don't use macsbug names
#	Build -sym								build Gus, generate Gus.sym file 
#											(this option can't be used with GCC)
#	Build -scm								build Gus, use scm options: GCC, no macsbug names,
#											 no symbols, remove existing objects
#	Build -opt								build Gus, full optimizations
#
#   --- Where do my objects and targets go? -----------------------------------------------------
#
#	Build									into	Objects					Targets
#	Build -scm								into	Objects.scm				Targets.scm
#
#	Build -debug							into	Objects.debug			Targets.debug
#	Build -gcc								into	Objects.gcc				Targets.gcc
#   Build -mrc								into	Objects.mrc				Targets.mrc
#   Build -xlc								into	Objects.xlc				Targets.xlc
#	Build -sym								into	Objects.sym				Targets.sym
#
#	Build -debug -gcc						into	Objects.debug.gcc		Targets.debug.gcc
#	Build -debug -xlc						into	Objects.debug.xlc		Targets.debug.xlc
#	Build -debug -sym						into	Objects.debug.sym		Targets.debug.sym
#
#	--- How -ObjectsFolder, -TargetsFolder and -Suffix work: ------------------------------------
#
#	NOTE: The shell variable {GUSObjects} controls the path that contains both the Objects and
#		  Targets folders.
#
#	Build -ObjectsFolder MyObjects			into	MyObjects					Targets
#	Build -TargetsFolder MyTargets			into	Objects						MyTargets
#	Build -Suffix xyz						into	Objects.xyz					Targets.xyz
#
#	Build -sym -ObjectsFolder MyObjects		into	MyObjects.sym				Targets.sym
#	Build -sym -TargetsFolder MyTargets		into	Objects.sym					MyTargets.sym
#	Build -sym -Suffix xyz					into	Objects.xyz.sym				Targets.xyz.sym
#
#   --- What optional code is included in Gus? --------------------------------------------------
#
#	Build -Quickdraw		includes	All the current GS Quickdraw patches
#	Build -AppleTalk		includes	All the current AppleTalk protocol patches
#
#   --- NOTES -----------------------------------------------------------------------------------
#
#   SIXTYEIGHTK is on all the time for both GCC and MPW C.  It shouldn't be passed on the lines to
#	the compiler if you're compiling this for POWERPC.
#
#   Now, by default, we build without optimizations on. Use -opt to get default optimizations for
#   a particular compiler.
#
#   ---------------------------------------------------------------------------------------------
#
#	Change History (most recent first):
#
#	   <101>   18-Nov-96	JM3		Nuke uses of USESROUTINEDESCRIPTORS and GENERATE68KINLINES since
#									those are OLDROUTINENAMES things, and aren't doing anything.
#	   <100>	11/11/96	andy	Pass -rtti off to MrCpp
#		<99>   21-Oct-96	JM3		Nuke MiscCIncludes. Nobody uses them, and likely never will.
#		<98>	8-Aug-96	JM3		Added build target for AppleTalk multinode resource (kinda'
#									broken - only builds once). Pass AppleTalk conditional on to
#									Rez. Added a "-traceback" option so you can build optimized but
#									still get names. Nuked a bunch of soon to be obsolete AppleTalk
#									files.
#		<97>   21-Jul-96	JM3		Nuke support for PPCC 'cause it's obsolete.
#		<96>	10/25/95	DAL		Added ToolboxSound.c.
#		<95>	10/25/95	DAL		Changed main entry of IconLDEF to "ICONLDEF".
#		<94>	10/23/95	DAL		Added Icon.LDEF stuff.
#		<93>	10/23/95	DAL		Added multi-pane Preferences stuff (in new subproject).
#		<92>	 9/25/95	JM3		Ummm, not quite. This time for sure.
#		<91>	 9/25/95	JM3		Added a target specially for the version so we can actually
#									get the engineering versions into the 'vers' resource in the
#									final output.
#		<90>	 9/15/95	DAL		Successful build echoes MakeTargets instead of the wrong stuff
#									that it used to echo. -- Jim fixed options for Symantec -opt
#									build.
#		<89>	  9/9/95	DAL		Added AboutBox.c, Preferences.c, DisksHumanInterface.c and
#									Clipboard.c.
#		<88>	 8/24/95	andy	Change gus.c to Gus.c for MattA
#		<87>	 8/21/95	andy	Add MoreQuickdraw.cp
#		<86>	 8/21/95	andy	Add MoreStrings.cp
#		<85>	 8/16/95	andy	Move Exceptions to Base
#		<84>	9-Aug-95	JM3		Added an auto-versioning mechanism (taken from MacsBug). Moved
#									all of the make-related files into a "Make" sub-project.
#		<83>	9-Aug-95	JM3		Fix handling of the -sym option so we can pass the appropriate
#									option to the compiler, assembler, or linker (they do sometimes
#									differ). Now pass -traceback to MrC when -sym is on.
#		<82>	  8/9/95	DAL		For SCpp, change -J to -char unsigned.
#		<81>	 4/26/95	andy	Add -Q inlining for xlC
#		<80>	 4/20/95	andy	GSMemoryPrimatives -> GSMemoryPrimitives
#		<79>	 4/18/95	andy	Remove inline816.c now that we never build with GCC, assembly
#									memory accessors rule today, and inline816.c has become
#									GSMemory.c
#		<78>	  4/5/95	andy	Change -cfront to -cplus for moto compiler
#		<77>	  4/5/95	andy	Change uppercase -I to lowercase -i to make mcc happy (this
#									breaks xlC, though, sigh)
#		<76>	  4/4/95	andy	Support Motorola compiler
#		<75>	 2/21/95	andy	Turn on profiling menu only if it's asked for
#		<74>	 2/11/95	DAL		Removed the -drag option...it's always a feature now.
#		<73>	 2/11/95	DAL		Messed with SCpp options.  Use the options for both debug and
#									non-debug builds.  Use -b3 to put strings inline (helps
#									:Debug:GSNameSpace.c especially).
#		<72>	 1/30/95	andy	Add -d GSSound=1
#		<71>	 1/14/95	andy	Add GSDoubleHiresTable.c and GSHiresTable.c
#		<70>	12/12/94	andy	Add Exceptions.cp and LittleStreams.cp
#		<69>	 12/9/94	andy	Enable profiling
#		<68>	 12/9/94	andy	Add DisksUnshrink.cp to dependencies
#		<67>	 12/8/94	DAL		Export "Projects" just like ObjectsPath and TargetsPath.
#		<66>	 12/8/94	andy	
#		<66>	 12/7/94	andy	Add -dialect cplus to mrc and ppcc builds, change symantec to
#									use SCpp
#		<65>	 12/5/94	andy	Pass linksymbolswitches on to EmulatorGS build
#		<64>	 12/2/94	DAL		Added GSC030Sound.c.o.
#		<63>	 12/1/94	andy	Support building EmulatorGS
#		<62>	11/30/94	andy	Add DoubleHiRes.c to the build
#		<61>	10/26/94	andy	Newer, cooler PPClink generates PEF an xcoff at the same time
#		<60>	 10/6/94	andy	Move position of CopCodes.a so that ppc links again
#		<59>	 10/2/94	andy	Remove the "hasPPCMemory" ifdefs, use the C memory accessors
#									-and- the PPC memory accessors. This prevents a great loss of
#									time when load is called and we used to have to plow through
#									GSMemoryGlue.a (100+ instructions) to get to a single lhbrx
#									instruction. (ie, removed GSMemoryGlue.a from the build)
#		<58>	 9/30/94	DAL		Renamed two M68K-build files to GSMemory_M68K.a and
#									Emulate816_M68K.a.
#		<57>	 9/28/94	DAL		Added Joystick.c.
#		<56>	 9/21/94	andy	Re-order PowerPC build files so that Dispatcher.a is aligned by
#									PPCLink (maybe)
#		<55>	 9/16/94	andy	Add an Emulator target that builds as a shared library
#		<54>	 8/26/94	DAL		Added GS_ADB.c.
#		<53>	 8/13/94	andy	Add GSRect.c
#		<52>	 8/12/94	andy	Add GSSlice.c
#		<51>	  8/8/94	andy	Add the accurate dispatcher back because the non-accurate
#									dispatches is about 10% faster than the "all-purpose"
#									dispatcher. drat.
#		<50>	  8/4/94	andy	Remove the accurate dispatcher, no longer needed
#		<49>	 7/18/94	DAL		Added DragLib.xcoff for PPCC builds.
#		<48>	 7/15/94	DAL		Set OLDROUTINENAMES=0.
#		<47>	 4/27/94	andy	Add support for AccurateDispatch.s and Accurate816.s, and
#									re-arrange the link order of some files for the PowerPC link so
#									that we don't get branch-out-of-range errors any more
#		<46>	 4/23/94	DAL		Added Ensoniq.c and -ic Sound. (After much head-scratching, also
#									added :Sound: to -srcdirs...thanks, Andy!)
#		<45>	 4/22/94	andy	Start building with -typecheck now available in PPCAsm 1.1d1e1
#									so that I don't type 'cmpl' when I meant to type 'cmpli' in the
#									PowerPC assembly sources
#		<44>   18-Apr-94	JM3		Rolled in Mike's new video files. EXPSHR is no longer supported, since
#									the fast code is always on.
#		<43>	2-Apr-94	JM3		Ha! I did break something. PowerPC builds get cfrgs again. Kinda'
#									useful, if you ask me. Oh, in the last checkin in enabled AppleTalk
#									files again for both 68K and PowerPC.
#		<42>	1-Apr-94	JM3		AppleTalk and Drag support now get their own Targets and Objects
#									directories. Removed some redundant declarations of POWERPC=1 and
#									SIXTYEIGHTK=1. Let's see what I broke...
#		<41>	  3/7/94	andy	Add GSMemoryFuncs.s to PowerPC build
#		<40>	  2/3/94	DAL		At the end, spit out the command line to launch the built
#									application.
#		<39>	  2/3/94	andy	Don't blow away the ADefineSwitches when building for PowerPC
#		<38>	  2/2/94	JM3		Made the PPCC build actually run the compiler out of our project
#									hierarchy. It was easier than we thought.
#		<37>	  2/1/94	andy	Break CDefineSwitches into CDefineSwitches and CIncludeSwitches
#		<36>	  2/1/94	andy	Pass SymbolSwitches to the Linker
#		<35>	  2/1/94	andy	Support build with IBM xlc
#		<34>	 1/31/94	andy	Change Video.c to GSVideo.c so that Video.h doesn't collide with
#									the Mac toolbox video.h
#		<33>	 1/23/94	andy	Add COPcodes.s to the PowerPC build
#		<32>	 1/16/94	andy	Do the makesym after the makepef so the build is finished sooner
#		<31>	 1/15/94	DAL		Added -m68k option.
#		<30>	 1/13/94	andy	Change order of file dependencies for PowerPC so that the
#									dispatcher is linked BEFORE the emulator (it actually matters
#									for performance (branch predicting, etc.))
#		<29>	  1/2/94	andy	Pass lowercase -d, not uppercase -d to lame PPCC
#		<28>	12/22/93	andy	Fix Makefile checkout (project named wrong)
#		<27>	12/16/93	DAL		Add :Disks:DiskStuff.c. Require function prototypes in MPW C.
#		<26>   12-dec-93	JM3		Fixed PPC default options to include the required stuff when we build
#									with debug.
#		<25>	12/12/93	DAL		Dave added "-b" to MPW C options to force string constants inline
#									(and he forgot to mention that one too - jm3).
#		<24>	12/11/93	DAL		Dave moved Debug.c into Debug subproject, added GSNameSpace.c. (but
#									forgot to mention it here, so I did - jm3).
#	    <23>	 12/7/93	DAL		Added file Printing.c.
#		<22>	 12/5/93	andy	Remove OptionIsCustomFlag
#		<21>	11/29/93	andy	Use the libraries in the Libraries subproject
#		<20>   28-Nov-93	JM3		Fixed MakeSYM to use -o, -i and -r.
#		<19>   27-Nov-93	JM3		Added support to disable PPC Asm memory code and the PPC Asm emulator
#									(-noppcmemory and -noppcemulator). Added support for Mike's fast SHR
#									code with -expshr.
#		<18>	27-Nov-93	JM3		Doh. Changed PPCIncludes to the proper PPCCIncludes. Now it works.
#		<17>	26-Nov-93	JM3		First support added for PowerPC. Build -ppc creates a Gus with
#									no optimizations using the Asm emulator and memory accessors.
#		<16>	19-Nov-93	DAL		Moved Video.c into Video subproject.
#
#		// numbers below are not Projector revision numbers
#
#		<10>    7/29/93		JCM		Duh. Now if -appletalk isn't passed we don't compile any of the
#									AppleTalk code at all. Thanks Mike.
#
#		 <9>	 6/2/93		JCM		-sym now works for assembly code.
#
#		 <8>	 6/1/93		JCM		The AppleTalk stuff is now a subproject of Gus, so I've reworked
#									everything associated with it (including all of the new files).
#									The file 'appletalk.c' that was at the top level of the Gus project
#									is now obsolete and should be deleted (it's been removed from the
#									project).
#									Asm code is now built with '-case obj' to preserve case in the
#									object files.
#		 <7>	3/25/93		aen		Symantec (sc) support
#		 <6>	3/13/93		aen		Changed VirtualGSBug to GUSBUG
#		 <5>	 3/7/93		JCM		Added -AppleTalk to enable my patches to the protocol layers.
#		 <4>	 3/3/93		aen		Re-ordered the Makemake stuff so that 816.c's dependencies are
#									done first.  This puts the load calls into 816, where they can
#									do the most good.
#		 <3>	 3/1/93		aen		Added -quickdraw to enable my patches to the rom.
#		 <2>	2/26/93		aen		Made -gcc -debug not run gcc's optimizer, added -GCCIncludes
#									and -LCCIncludes.
#		 <1>	2/21/93		aen		New today.
#
#	To Do:
#

Alias Usage 'Echo "### usage: {0} [-debug] [-gcc | -mrc | -sc | -xlc] [-makemake] [-nomake] [-noppcmemory] [-noppcemulator] [-time] [-sym] [-nonames] [-clobber] [-ignore] [-gccincludes | -scincludes] [-appletalk] [-m68k] and other stuff" > Dev:StdErr; Exit 1'

# process command line

#
# This is here for Moto's MCC
#
Set PPCCIncludes ":Includes:Public:"
Export PPCCIncludes

Set BuildProject "Gus"
Set OldExit {Exit}

Set SCM 0
Set DoMakemake 0
Set Clobber 0
Set Symbols 0
Set Optimize 0
Set Names 1
Set DoMake 1
Set DoMakeOut 1
Set Ignore 0
Set NoDoIt 0
Set Profile 0

Set Quickdraw 0
Set AppleTalk 0
Set Drag 1
Set hasPPCMemory 1
Set hasPPCEmulator 1
Set has68KStuff 0

Set GCC 0
Set	MRC 0
Set	XLC 0
Set Moto 0
Set Symantec 0
Set MPW 0
Set PowerPC 0

Set ASymbolOnOption		"-sym on"
Set ASymbolOffOption	"-sym off"
Set CSymbolOnOption		"-sym on"
Set CSymbolOffOption	"-sym off"
Set CEmbeddedNamesOption ""
Set LinkSymbolOnOption	"-sym on"
Set LinkSymbolOffOption	"-sym off"

#
# Default location for our objects and targets
#
Set DefaultObjectsName "Objects"
Set DefaultTargetsName "Targets"
Set UserSuffix ""

#
# BuildFlags are used to echo the selected build flags when building;
# CustomFlags keep track of flags defined with -d FlagName
# MakeOptions are passed to Make (of course)
#
Set BuildFlags  ""				# Used to echo build flags
Set CustomFlags ""
Set MakeOptions ""

#
# Set up a collection of variables that deal with our versioning mechanism.
#

Set CustomVersion		0
Set GusVersionLong 		0
Set GusVersionString 	""
Set GusVersionEngString	""
Set	GusVersionYear			""

Set development			0x20
Set alpha 				0x40
Set beta 				0x60
Set final 				0x80

Loop	
	Break If {#} == 0
	Set Parameter "{1}"
	Shift

	Set BuildFlags "{BuildFlags}{Parameter} "

	# ---------------------------------------
	# Flags relating to the build process
	# ---------------------------------------
	If "{Parameter}" =~ /-nodoit/ && {NoDoIt}
		Set NoDoIt 1
	Else If "{Parameter}" =~ /-emulatorgs/
		Set EmulatorGS 1
		Set PowerPC 1
	Else If "{Parameter}" =~ /-ignore/ && {Ignore}
		Set Ignore 1
	Else If "{Parameter}" =~ /-nomake/
		Set DoMake 0
	Else If "{Parameter}" =~ /-makemake/
		Set DoMakemake 1
	Else If "{Parameter}" =~ /-clobber/
		Set Clobber 1
	# ---------------------------------------
	# Flags relating to how Gus is built 
	# (debug, sym, scm, gcc, sc)
	# ---------------------------------------
	Else If "{Parameter}" =~ /-profile/ && {profile}
		Set Profile 1
	Else If "{Parameter}" =~ /-sym/ && {Symbols}
		Set Symbols 1
	Else If "{Parameter}" =~ /-opt/ && {Optimize}
		Set Optimize 1
	Else If "{Parameter}" =~ /-nonames/
		Set Names 0
	Else If "{Parameter}" =~ /-names/ && {Names}
		Set Names 1
	Else If "{Parameter}" =~ /-gcc/
		Set GCC 1
		Set PowerPC 0
	Else If "{Parameter}" =~ /-mrc/
		Set MRC 1
		Set PowerPC 1
		Set CSymbolOnOption		"-sym on -traceback"
		Set GSSound 1
	Else If "{Parameter}" =~ /-xlc/
		Set XLC 1
		Set PowerPC 1
		Set CSymbolOnOption 	"-g -qdbxextra"
		Set CSymbolOffOption 	""
		Set GSSound 1
	Else If "{Parameter}" =~ /-moto/
		Set Moto 1
		Set PowerPC 1
		Set CSymbolOnOption 	"-g"
		Set CSymbolOffOption 	""
		Set GSSound 1
	Else If "{Parameter}" =~ /-symantec/
		Set Symantec 1
		Set PowerPC 0
	Else If "{Parameter}" =~ /-debug/
		Set Debug 1
	Else If "{Parameter}" =~ /-traceback/
		Set CEmbeddedNamesOption "-traceback"
	Else If "{Parameter}" =~ /-scm/
		Set SCM 1
		Set GCC 1
		Set Names 0
		Set Clobber 1
	# ---------------------------------------
	# Flags related to major sets of patches
	# to Gus and other conditional code
	# ---------------------------------------
	Else If "{Parameter}" =~ /-quickdraw/
		Set Quickdraw 1
	Else If "{Parameter}" =~ /-gssound/
		Set GSSound 1
	Else If "{Parameter}" =~ /-appletalk/
		Set AppleTalk 1
	Else If "{Parameter}" =~ /-noppcmemory/
		Set hasPPCMemory 0
	Else If "{Parameter}" =~ /-noppcemulator/
		Set hasPPCEmulator 0
	Else If "{Parameter}" =~ /-m68k/
		Set has68KStuff 1
	# ---------------------------------------
	# Custom flags
	# ---------------------------------------
	Else If "{Parameter}" =~ /-d/
		If {#} == 0
			Echo "### {0} - Encountered -d without an argument." > Dev:StdErr
			Usage
		End
		
		Set CustomFlags "{CustomFlags} -d {1}=1"
		Set BuildFlags "{BuildFlags}{1} "
		Shift
	Else If "{Parameter}" =~ /-TargetsFolder/
		If {#} == 0
			Echo "### {0} - Encountered -TargetsFolder without an argument." > Dev:StdErr
			Usage
		End

		Set DefaultTargetsName "{1}"
		set BuildFlags "{BuildFlags}{1} "
		Shift
	Else If "{Parameter}" =~ /-ObjectsFolder/
		If {#} == 0
			Echo "### {0} - Encountered -ObjectsFolder without an argument." > Dev:StdErr
			Usage
		End

		Set DefaultObjectsName "{1}"
		set BuildFlags "{BuildFlags}{1} "
		Shift
	Else If "{Parameter}" =~ /-Suffix/
		If {#} == 0
			Echo "### {0} - Encountered -Suffix without an argument." > Dev:StdErr
			Usage
		End

		Set UserSuffix ".{1}"
		set BuildFlags "{BuildFlags}{1} "
		Shift
	Else
		Echo "### {0} - Cant make sense of {Parameter}." > Dev:StdErr
		Usage
	Else If "{Parameter}" =~ /-version/ && {#}  1 && {CustomVersion}
		Set 3 0 ; Set 4 "" ; Set 5 "" ; Set 6 ""	# may not get parsed
		If "{2}" =~ /[0-9A-Za-z-]*([0-9]+)1.([0-9])2(.([0-9])3)*(([dabDAB])4([0-9]+)5(()0,1)6)0,1/
			Set GusVersionString "{2}"
			Set GusVersionMajor 0x0"{1}"
			Set GusVersionMinor 0x"{2}{3}"
			If "{4}" =~ /d/
				Set GusVersionStage {development}
			Else If "{4}" =~ /a/
				Set GusVersionStage {alpha}
			Else If "{4}" =~ /b/
				Set GusVersionStage {beta}
			Else If "{4}" == ""
				Set GusVersionStage {final}
			Else
				Echo "### Impossible version number problems" > Dev:StdErr
				Exit 1
			End
			Set GusVersionIncrement 0x0"{5}"
			Set GusVersionLong "{GusVersionMajor},{GusVersionMinor},{GusVersionStage},{GusVersionIncrement}"
		Else
			Echo "### Cant parse {2} as a version number. "> Dev:StdErr
			Exit 1
		End
		Shift
		Set CustomVersion 1
	End
End

#
# Turn off GSSound if we're not using the PowerPC emulator
#
if "{hasPPCEmulator}" == 0
  	Set GSSound 0
end

#
# If they've implicitly chosen the Symantec C compiler, let's record that fact for tests below.
#
If {PowerPC}
	Set Symantec 1
End


#
# Check for dependencies between different types of builds (can't build GCC & Symbols)
#
If ({Symbols} && {GCC})
	Echo "### Can't build symbol file and use GCC" > Dev:StdErr
	Usage
End

If ({SCM} && {Symbols})
	Echo "### Can't build SCM and use symbols (SCM uses GCC)" > Dev:StdErr
	Usage
End

If ({SCM} && {Debug})
	Echo "### Can't build SCM and Debug" > Dev:StdErr
End

#
# One of these compilers -MUST- exist, and shouldn't be prefixed with a period
#
# Setup the compiler, but use the regular Linker instead of the incremental linker 
# if we're doing an SCM build
#
Set ResourceCompiler	":Tools:Rez"


If {EmulatorGS}
	Set Suffix 			"{Suffix}EmulatorGS"
	Set CCompiler 		":Tools:MrC"
	Set Linker			":Tools:PPCLink"
	Set Assembler		":Tools:PPCAsm"
	Set Commands		"`directory`Tools:,{Commands}"
	Export Commands
End

If {MRC}
	Set Suffix 			"{Suffix}MrC"
	Set CCompiler 		":Tools:MrCpp"
	Set Linker			":Tools:PPCLink"
	Set Assembler		":Tools:PPCAsm"
	Set Commands		"`directory`Tools:,{Commands}"
	Export Commands
End

If {Moto}
	Set Suffix 			"{Suffix}Moto"
	Set CCompiler 		":Tools:mcc"
	Set Linker			":Tools:PPCLink"
	Set Assembler		":Tools:PPCAsm"
	Set Commands		"`directory`Tools:,{Commands}"
	Export Commands
End

If {XLC}
	Set Suffix 			"{Suffix}xlc"
	Set CCompiler 		":Tools:remote xlc"
	Set Assembler		":Tools:PPCAsm"
	Set Linker			":Tools:remote ld"
End

If {Symantec}
	Set Suffix 			"{Suffix}Symantec"
	Set CCompiler 		":Tools:SCpp"
	Set Assembler		"Asm"
	Set Linker			"Link"
End

If {GCC}
	Set Suffix 			"{Suffix}GCC"
	Set CCompiler 		"gC"
	Set Assembler		"Asm"
	Set Linker			"Link"
End

#
# Set up the names of the Objects and Targets folders
#
Set Objects "{DefaultObjectsName}"
Set Targets "{DefaultTargetsName}"

#
# Everything after the compiler name gets a dot
#
If {has68KStuff}
	Set Suffix "{Suffix}.M68K"
End

If {Optimize}
	Set Suffix "{Suffix}.opt"
End
	
If {Debug}
	Set Suffix "{Suffix}.debug"
End

If {Symbols}
	Set Suffix "{Suffix}.sym"
End

If {AppleTalk}
	Set Suffix "{Suffix}.atlk"
End

#
# Add the user suffix at the end of the suffix we've built
# (Note that 'UserSuffix' already includes a '.')
#
Set Suffix "{Suffix}{UserSuffix}"

#
# Set up our objects and targets paths
#
Set ObjectsPath 	":{Objects}:{Suffix}:"
Set ObjectsFolder 	":{Objects}:"
Set TargetsPath 	":{Targets}:{Suffix}:"
Set TargetsFolder	":{Targets}:"
Export TargetsPath
Export ObjectsPath
Export Projects
Export Suffix

Set Obj "{ObjectsPath}"
Set TargetObj "{TargetsPath}"

Set QD 				":Quickdraw:"
Set AT 				":AppleTalk:"
Set Projects 		":Projects:"
Set M68K 			":M68K:"

Set ATalkCSources "{AT}AppleTalkGS.c	
				   {AT}IRQ.c			
				   {AT}SYS.c			
				   {AT}LAP.c"

Set DefaultADefineSwitches		""
Set DefaultCCompilerSwitches	"-mf"
Set DefaultCDefineSwitches		""
Set DefaultRDefineSwitches		"-i :Includes:RIncludes:"
Set DefaultLinkSwitches			"-sym off"

#
# If we're doing an SCM build we'll be clobbering everything in {ObjectsPath} and {TargetsPath}
# so we're forced to rebuild everything cleanly
#
If {Clobber}
	Delete -i -y "{ObjectsPath}"
	Delete -i -y "{TargetsPath}Gus"
	Delete -i -y "{TargetsPath}Gus.sym"
End

#
# Both the ObjectsPath and the TargetsPath are composed of a pathname that -should-
# exist under most circumstances.  If it doesn't exist, then try to create each segment
# of the pathname to both paths.
#
Set Exit 0

#
# Both the ObjectsPath and the TargetsPath are composed of a pathname that -should-
# exist under most circumstances.  Only try creating the "Objects" folder and the immediate
# subfolder which holds this compiler's objects
#
If `Exists "{ObjectsPath}"`
	NewFolder "{ObjectsFolder}"  Dev:Null
	NewFolder "{ObjectsPath}" 	 Dev:Null
End

If `Exists "{TargetsPath}"`
	NewFolder "{TargetsFolder}"  Dev:Null
	NewFolder "{TargetsPath}" 	 Dev:Null
End

Set Exit {OldExit}

#
# Export variables for Makemake
#
Export TargetsPath
Export ObjectsPath
Export Projects
Export Suffix
Export Names
Export Symbols

#
# Here's our cool engineering release versioning mechanism. If you don't override the
# default project version (with a -version), your local builds will generate a Gus
# version of the form "1.0d(ABC)en" where "ABC" == your initials, and "n" is your own
# engineering version number. The engineering revision is self-maintaining and will
# reset if a newer revision of Gus is created (that is, "GusVersion.h" was found to
# have been updated).
#

If {CustomVersion}
	If "{UserInitials}" == ""
		Set TrimmingName "{User}"		
		Loop
			If "{TrimmingName}" =~ /([a-z])1[a-z.]*[ -]()2/
				Set UserInitials {UserInitials}{1}
				Set TrimmingName "{2}"
			Else If "{TrimmingName}" =~ /([a-z])1[a-z.]*/
				Set UserInitials {UserInitials}{1}
				Break
			End
		End
	End

	Set VersFile ":GusVersion.h"
	Set RevFile ":Make:ProjectVersion"
	Set EngFile ":Make:LocalEngineeringVersion"

	Set TheCurVers "`Search /#define GusVersionString/ "{VersFile}" -q`"

	If !"`Exists "{RevFile}"`"
		Echo "{TheCurVers}" > "{RevFile}"
	Else
		Set SavedVers "`catenate "{RevFile}"`"
		If "{SavedVers}" != "{TheCurVers}"
			Echo -n "{TheCurVers}" > "{RevFile}"
			Delete "{EngFile}" -y -i 
		End
	End

	Set TheRev 1

	If !"`Exists "{EngFile}"`"
		Echo -n '1' > "{EngFile}"
	Else
		Set TheRev `Evaluate `catenate "{EngFile}"` + 1`
		Echo -n "{TheRev}" > "{EngFile}"
	End	
	Set GusVersionEngString "({UserInitials})e{TheRev}"

End

If "`Date`" =~ /, , ([0-9]+)1 /
	Set GusVersionYear "{1}""{GusVersionYear}"
End

# ========================================================================================================================
#		Say that the build is about to begin
# ========================================================================================================================


#
# Tell which Gus we're going to build
#
Echo "#"
Echo "# Build project:	{BuildProject} 1.0{GusVersionEngString}"
Echo "# Build flags:		{BuildFlags}"
Echo "# Started at:		`date`" >Dev:StdErr
Echo "#"

#
# --- Create the Makefile using Makemake ------------------
#
If {DoMakemake}

	If `Exists :Make:Makefile`""  ""
		Set Info "`ProjectInfo -s :Make:Makefile`"
		If "{Info}"  "" && "{Info}" !~ /,[0-9a-z]+[*+]'/
			Set Exit 0
			Confirm "Makefile is not modifiable.  Do you want to try to check it out?"
			Set ConfirmStatus {Status}
			Exit 2 If {ConfirmStatus}  0
			Set CheckOutErrors "{SystemFolder}CheckOutErrors"
			CheckOut -project GusProjMake -m :Make:Makefile  "{CheckOutErrors}"
			If {Status}  0
				Alert "Couldnt check out Makefile:  `Catenate "{CheckOutErrors}"`"
				Delete -i "{CheckOutErrors}"
				Exit 2
			End
			Delete -i "{CheckOutErrors}"
			Set Exit {OldExit}
		End
	End

#
# For the various compilers we occasionally need to use different sets of libraries.
#
	Set EmulatorGSLibs 
		":Libraries:InterfaceLib.xcoff"

	Set MrCLibs 
	    ":Libraries:PPCCRuntime.xcoff 
		:Libraries:StdCRuntime.xcoff 
		:Libraries:InterfaceLib.xcoff 
		:Libraries:StdCLib.xcoff 
		:Libraries:DragLib.xcoff 
		:Libraries:MathLib.xcoff"

	Set MotoLibs 
	    ":Libraries:PPCCRuntime.xcoff 
		:Libraries:StdCRuntime.xcoff 
		:Libraries:InterfaceLib.xcoff 
		:Libraries:StdCLib.xcoff 
		:Libraries:DragLib.xcoff 
		:Libraries:MathLib.xcoff"

	Set xlcLibs 
		":Libraries:StdCRuntime.xcoff 
		:Libraries:InterfaceLib.xcoff 
		:Libraries:StdCLib.xcoff 
		:Libraries:MathLib.xcoff 
		:Libraries:IBMCRunTimeSupport04.xcoff"

	Set MPWLibs 
	    ":Libraries:StdCLib.o 
	    :Libraries:Runtime.o 
	    :Libraries:Interface.o"

	Set XCOFFDeps 
			":PowerPC:Dispatch.a 
			:PowerPC:Emulate816.a 
			:PowerPC:GSMemory.a 
			:PowerPC:COPcodes.a 
			:PowerPC:AccurateDispatch.a 
			:PowerPC:Accurate816.a 
			:PowerPC:AccurateGSMemory.a 
			:PowerPC:GSMemoryPrimitives.a 
			:PowerPC:GSMemoryFuncs.a 
			:PowerPC:DispatchTables.a 
			816.c 
			GSMemoryFuncs.c 
			GSMemory.c 
			GSMemoryPrimitives.c 
			gs.c 
			Gus.c 
			AboutBox.c 
			Clipboard.c 
			:Preferences:ListControl.c 
			:Preferences:Preferences.c 
			:Preferences:MultiPaneDlgs.c 
			:Preferences:Utilities.c 
			:Video:GSVideo.c 
			:Video:GSText.c 
			:Video:GSHiRes.c 
			:Video:GSHiResTable.c 
			:Video:GSDoubleHiRes.c 
			:Video:GSDoubleHiResTable.c 
			:Video:GSSuperHiRes.c 
			:Sound:Ensoniq.c 
			:Sound:ToolboxSound.c 
			:Sound:GSC030Sound.c 
			:Disks:DiskStuff.c 
			:Disks:DisksHumanInterface.c 
			:Disks:Unshrink.cp 
			:Base:Exceptions.cp 
			:Base:MoreStrings.cp 
			:Base:MoreQuickdraw.cp 
			:Disks:LittleStreams.cp 
			Printing.c 
			patches.c 
			drag.c 
			:Debug:Debug.c 
			:Debug:GSNameSpace.c 
			{QD}GSRegions.c 
			{QD}GSSlice.c 
			{QD}GSRect.c 
			GS_ADB.c 
			Joystick.c 
			{ATalkCSources}"


#
# Which set of include files should we use?
#
	Set PrivateCIncludes 	":Includes:Private:"
	Set UniversalAIncludes 	":Includes:AIncludes:"
	Set UniversalCIncludes 	":Includes:Public:"
	Set UniversalRIncludes 	":Includes:RIncludes:"
	Export PrivateCIncludes
	Export UniversalAIncludes
	Export UniversalCIncludes
	Export UniversalRIncludes

	:Tools:Makemake 
		-noall -nosys -nomacro -nodoth -nodotr -nosrcs -nolibs 
		-noprivate -nostd -nouniversal 
		C="{CCompiler}" 
		LINK="{Linker}" 
		ASM="{Assembler}" 
		ADefineSwitches="{DefaultADefineSwitches}" 
		CDefineSwitches="{DefaultCDefineSwitches}" 
		CCompilerSwitches="{DefaultCCompilerSwitches}" 
		RDefineSwitches="{DefaultRDefineSwitches}" 
		LinkSwitches="{DefaultLinkSwitches}" 
		Obj={Obj} 
		AOptions='{ADefineSwitches}' 
		COptions='{CCompilerSwitches} {CDefineSwitches} {PlatformSwitches} {CIncludeSwitches}' 
		CTAGS= POST= SETFILEOPTS= 
		-pre :Make:Make.prefile 
		-objdir {Obj} 
		-srcdirs ": {QD} {AT} :Base: :Video: :Disks: :Debug: :PowerPC: :M68K: :Sound: :Preferences:" 
		-ia : -ir : -ic : 
		-ia :M68K: 
		-ic {QD} 
		-ic {AT} -ia {AT}
		-ic :Base: 
		-ic :Video: 
		-ic :Disks: 
		-ic :Preferences: 
		-ic :Debug: 
		-ic :Sound: 
		-is :PowerPC: 
		-t {Obj}Gus.dump.c.o 	
			-customonly '{C} Gus.dump.c -o "{ObjectsPath}Gus.dump.c.o" -dumpc "{ObjectsPath}PrecompiledHeaders" {CDefineSwitches}'ntt'{PlatformSwitches}'ntt'-i :Includes:Public: {MacsbugSwitches}' 
			Gus.dump.c 
		-t {TargetObj}Gus 
			-r '{RDefineSwitches}'"ntt"'{PlatformSwitches}' 
			-f '-c "Gus!" -t "APPL" -m . -d . -a iB' 
			-fcustom 'If {Symbols}; Move -y '""{Obj}Gus.code.SYM" "{TargetObj}Gus.SYM"; Setfile -c sDeb "{TargetObj}Gus.SYM"; End" 
			-o {TargetObj}Gus 
			Main.r 
			{Obj}Gus.code 
			{Obj}Gus.rsrc 
			{Obj}GusVersion.rsrc 
		-t {TargetObj}Gus.MrC 
			-customonly "Duplicate -y -d "{Obj}Gus.MrC.pef" "{TargetObj}Gus.MrC" ntDuplicate -y -r "{Obj}Gus.rsrc" "{TargetObj}Gus.MrC"" 
			{Obj}Gus.MrC.pef 
			{Obj}Gus.rsrc 
			{Obj}GusVersion.rsrc 
		-t {TargetObj}Gus.Moto 
			-customonly "Duplicate -y -d "{Obj}Gus.Moto.pef" "{TargetObj}Gus.Moto" ntDuplicate -y -r "{Obj}Gus.rsrc" "{TargetObj}Gus.Moto"" 
			{Obj}Gus.Moto.pef 
			{Obj}Gus.rsrc 
			{Obj}GusVersion.rsrc 
		-t {TargetObj}Gus.xlc 
			-customonly "remote /usr/bin/mac/makepef "{Obj}Gus.xlc.xcoff" -ft APPL -fc Gus! -l InterfaceLib.xcoff=InterfaceLib -l MathLib.xcoff=MathLib -l StdCLib.xcoff=StdCLib -o "{Obj}Gus.pef"ntDuplicate -y -d "{Obj}Gus.pef" "{TargetObj}Gus.ppc" ntDuplicate -y -r "{Obj}Gus.rsrc" "{TargetObj}Gus.ppc"nt"'If {Symbols}; remote /usr/bin/mac/makesym -i : -r  "{ObjectsPath}Gus.xlc.xcoff" -o "{TargetsPath}Gus.ppc.xSYM";End' 
			{Obj}Gus.xlc.xcoff 
			{Obj}Gus.rsrc 
			{Obj}GusVersion.rsrc 
		-t {Obj}Gus.MrC.pef 
			-o {Obj}Gus.MrC.pef 
			-l '{LinkSwitches}' 
			Gus.dump.c 
			{XCOFFDeps} 
			{MrCLibs} 
		-t {Obj}Gus.Moto.pef 
			-o {Obj}Gus.Moto.pef 
			-l '{LinkSwitches}' 
			{XCOFFDeps} 
			{MotoLibs} 
		-t {Obj}GusLib.xcoff 
			-o {Obj}GusLib.xcoff 
			-l '{GusLibLinkSwitches}' 
			"{Projects}Gus PPC .exp" 
			:PowerPC:EmulatorImports.c 
		-t {Projects}EmulatorGS 
			-o {Projects}EmulatorGS 
			-l '{EmulatorGSLinkSwitches}' 
			:PowerPC:Dispatch.a 
			:PowerPC:Emulate816.a 
			:PowerPC:GSMemory.a 
			:PowerPC:COPcodes.a 
			:PowerPC:AccurateDispatch.a 
			:PowerPC:Accurate816.a 
			:PowerPC:AccurateGSMemory.a 
			:PowerPC:GSMemoryPrimitives.a 
			:PowerPC:GSMemoryFuncs.a 
			:PowerPC:DispatchTables.a 
			{Obj}GusLib.xcoff 
			{EmulatorGSLibs} 
		-t {Obj}Gus.xlc.xcoff 
			-o {Obj}Gus.xlc.xcoff 
			-l '-bE:Gus.exports -bloadmap:'{Obj}'Gus.map'"ntt"
			{XCOFFDeps} 
			{xlcLibs} 
		-t {Obj}Gus.code 
			-l '{LinkSwitches} -c "RSED" -t "rsrc" -d -mf' 
			-o {Obj}Gus.code 
			Gus.dump.c 
			{Obj}GusLib.o 
			{MPWLibs} 
		-t {Obj}Gus.rsrc 
			-r '{RDefineSwitches}' 
			-rcustom 'Duplicate -y -r "{ObjectsPath}Gus.rsrc" "{Projects}Gus.rsrc"'
			-o {Obj}Gus.rsrc 
			Gus.r 
			RomRez.r 
			Bundle.r 
			{Obj}Icon.LDEF 
			{Obj}AppleTalkMultinode.rsrc 
		-t {Obj}GusVersion.rsrc 
			-customonly "Rez GusVersion.r {RDefineSwitches} -append -o {Obj}Gus.rsrc" 
			GusVersion.r 
			$OUTOFDATE 
		-t {Obj}Gus.Profile.rsrc 
			-r '{RDefineSwitches}' 
			-rcustom 'Duplicate -y -r "{ObjectsPath}Gus.Profile.rsrc" "{Projects}Gus.Profile.rsrc"'
			-o {Obj}Gus.Profile.rsrc 
			Gus.r 
			RomRez.r 
			Bundle.r 
			{Obj}Icon.LDEF 
			{Obj}AppleTalkMultinode.rsrc 
		-t {Obj}GusLib.o 
			-l '{LinkSwitches} -d -mf' 
			-o {Obj}GusLib.o 
			816.c 
			GSMemoryFuncs.c 
			GSMemory.c 
			GSMemoryPrimitives.c 
			gs.c 
			Gus.c 
			AboutBox.c 
			Clipboard.c 
			:Preferences:ListControl.c 
			:Preferences:Preferences.c 
			:Preferences:MultiPaneDlgs.c 
			:Preferences:Utilities.c 
			:M68K:GSMemory_M68K.a 
			:M68K:Dispatcher.a 
			:M68K:Emulate816_M68K.a 
			:Video:GSVideo.c 
			:Video:GSText.c 
			:Video:GSHiRes.c 
			:Video:GSHiResTable.c 
			:Video:GSDoubleHiRes.c 
			:Video:GSDoubleHiResTable.c 
			:Video:GSSuperHiRes.c 
			:Sound:Ensoniq.c 
			:Sound:ToolboxSound.c 
			:Sound:GSC030Sound.c 
			:Disks:DiskStuff.c 
			:Disks:DisksHumanInterface.c 
			:Disks:Unshrink.cp 
			:Base:Exceptions.cp 
			:Base:MoreStrings.cp 
			:Base:MoreQuickdraw.cp 
			:Disks:LittleStreams.cp 
			Printing.c 
			patches.c 
			drag.c 
			:Debug:Debug.c 
			:Debug:GSNameSpace.c 
			{QD}GSRegions.c 
			{QD}GSSlice.c 
			{QD}GSRect.c 
			GS_ADB.c 
			Joystick.c 
			{ATalkCSources} 
		-t {Obj}AppleTalkMultinode.rsrc 
			-customonly 
				':Tools:Asm :AppleTalk:Protocols.a -o {Obj}AppleTalkMultinode.a.o -i :Includes:AIncludes: ; 
				:Tools:Link -o {Obj}AppleTalkMultinode.rsrc -t rsrc -c RSED 
				{Obj}AppleTalkMultinode.a.o -rt MNod=128 -m THE_LISTENER -ra locked' 
		-t {Obj}Icon.LDEF 
			-customonly 
				':Tools:SCpp :Preferences:IconLDEF.c -o {Obj}IconLDEF.c.o -mc68020 -b3 -char unsigned -d SYMANTEC68K=1 -d SYMANTEC=1 -i :Includes:Public: ; 
				 :Tools:Link -sym off -m ICONLDEF -d -rn -rt LDEF=2048 -o {Obj}Icon.LDEF {Obj}IconLDEF.c.o' 
			:Preferences:IconLDEF.c

	Duplicate -y -d :Makefile :Make:Makefile
	Delete :Makefile

End


#
# Convert the build flags into compiler switches and build the stuff.
#

Set BuildStatus 0

If {DoMake}

	If {PowerPC}
		Set DefineSwitches	"-d SIXTYEIGHTK=1"	
		Set ADefineSwitches	"-d SIXTYEIGHTK=1"
	Else
		Set DefineSwitches	"-d POWERPC=1"	
		Set ADefineSwitches	"-d POWERPC=1"
	End

	# Put in special things for release
	If {Debug}
		Set ADefineSwitches "{ADefineSwitches} -d DEBUG=1 -d GUSBUG=1"
		Set DefineSwitches "{DefineSwitches} -d DEBUG=1 -d GUSBUG=1"
	End

	# Profiling if it's asked for
	If {Profile}
		Set DefineSwitches "{DefineSwitches} -d PROFILING=1"
	End
	
	# Now make C and Rez specific switches
	Set CDefineSwitches "{DefineSwitches}"
	Set RDefineSwitches "{DefineSwitches}"
	Set RDefineSwitches "{{RDefineSwitches}} -d AppleTalk={{AppleTalk}} -d GusVersionEngString='"{GusVersionEngString}"' -d GusVersionYear='"{GusVersionYear}"' -d GusVersionLong={GusVersionLong} -d GusVersionString='"{GusVersionString}"'"

	# OLDROUTINENAMES = 0
	Set CDefineSwitches "{CDefineSwitches} -d OLDROUTINENAMES=0"

	# Names if they are asked for
	If {Names} && {PowerPC}
		Set ADefineSwitches "{ADefineSwitches} -d &MacsBugNames=1"
		Set CDefineSwitches "{CDefineSwitches} -mbg full"
	Else If {PowerPC}
		Set ADefineSwitches "{ADefineSwitches} -d &MacsBugNames=0"
		Set CDefineSwitches "{CDefineSwitches} -mbg off"
	End

	# symbols if they are asked for
	If {Symbols}
		Set LinkSwitches	"{LinkSwitches} -sym on"
	Else
		Set LinkSwitches	"{LinkSwitches} -sym off"
	End

	# Sound if it was asked for
	If {GSSound}
		Set CDefineSwitches "{CDefineSwitches} -d GSSound=1"
	End

	# Quickdraw patches if they are asked for
	If {Quickdraw}
		Set CDefineSwitches "{CDefineSwitches} -d QUICKDRAW=1"
	End

	# AppleTalk patches if they are asked for
	If {AppleTalk}
		Set CDefineSwitches "{CDefineSwitches} -d APPLETALK=1"
		Set ADefineSwitches "{ADefineSwitches} -d APPLETALK=1"
	Else
		Set ADefineSwitches "{ADefineSwitches} -d APPLETALK=0"
	End
	
	# 68K Stuff if it's asked for
	Set CDefineSwitches "{CDefineSwitches} -d has68KStuff={has68KStuff}"
	Set ADefineSwitches "{ADefineSwitches} -d has68KStuff={has68KStuff}"
	
	#
	# Set up for the compiler/assembler we're using.
	#
	# For PPCAsm, use typechecking is ON, the blocksize is 512K (1024 * 512) bytes
	# set the xcoff modtype field to single use
	#
	
	If {PowerPC}
		Set ADefineSwitches "{ADefineSwitches} -typecheck -blocksize 1024 -dialect PowerPC"

		If {hasPPCEmulator}
			Set CDefineSwitches "{CDefineSwitches} -d hasPPCEmulator=1"
			Set ADefineSwitches "{ADefineSwitches} -d hasPPCEmulator=1"
		Else
			Set ADefineSwitches "{ADefineSwitches} -d hasPPCEmulator=0"
		End
	End

	#
	# symbols if they are asked for
	#
	If {Symbols}
		Set ASymbolSwitches 	"{ASymbolOnOption}"
		Set CSymbolSwitches 	"{CSymbolOnOption} {CEmbeddedNamesOption}"
		Set LinkSymbolSwitches 	"{LinkSymbolOnOption}"
	Else
		Set ASymbolSwitches 	"{ASymbolOffOption}"
		Set CSymbolSwitches 	"{CSymbolOffOption} {CEmbeddedNamesOption}"
		Set LinkSymbolSwitches 	"{LinkSymbolOffOption}"
	End

	#
	# --- Start with no compiler switches.  Fill them out for each compiler ---------
	#
	Set CCompilerSwitches ""

	If {GCC} && {Debug}	
		Set CCompilerSwitches "-mc68020 "
		Set PlatformSwitches "-d GCC68K=1"
		If {Optimize}
			Set CCompilerSwitches "{CCompilerSwitches} -opt full -fomit-frame-pointer "
		End
	End

	If {Symantec}
		Set CCompilerSwitches "-mc68020 -b3 -char unsigned -loadc '{ObjectsPath}PrecompiledHeaders' "
		Set PlatformSwitches "-d SYMANTEC68K=1 -d SYMANTEC=1"
		If {Optimize}	
			Set CCompilerSwitches "{CCompilerSwitches} -opt all"
		End
	End

	If {EmulatorGS}
		Set GusLibLinkSwitches		" -dead off -xm sharedLibrary -@export ':Projects:Gus PPC .exp'"
		Set EmulatorGSLinkSwitches 	" -dead off -xm s -t shlb -c '????' -tocdataref on -mf -librename InterfaceLib.xcoff=InterfaceLib -librename GusLib.xcoff=Gus -export ppc_DoInstructions"
	End

	If {MrC}
		Set LinkSwitches " -w -xm e -c Gus! -t APPL -librename InterfaceLib.xcoff=InterfaceLib -librename DragLib.xcoff=DragLib -librename MathLib.xcoff=MathLib -librename StdCLib.xcoff=StdCLib -weaklib DragLib -packdata on -tocdataref on -mf"
		Set CCompilerSwitches "-align power -loadc '{ObjectsPath}PrecompiledHeaders' "
		Set PlatformSwitches "-rtti off -d MRCPOWERPC=1"
		If {Optimize}
			Set CCompilerSwitches "{CCompilerSwitches} -opt speed"
		End
	End

	If {Moto}
		Set LinkSwitches " -w -xm e -c Gus! -t APPL -librename InterfaceLib.xcoff=InterfaceLib -librename DragLib.xcoff=DragLib -librename MathLib.xcoff=MathLib -librename StdCLib.xcoff=StdCLib -weaklib DragLib -packdata on -tocdataref on -mf"
		Set CCompilerSwitches "-cplus -c -Apascalstr=1 -Achar=signed"
		Set PlatformSwitches "-d MOTOROLA -d MOTOROLAPOWERPC=1"
		If {Optimize}
			Set CCompilerSwitches "{CCompilerSwitches} -O"
		End
	End

	If {xlc}
		Set LinkSwitches ""
		Set LinkSymbolSwitches 	""
		Set CCompilerSwitches "-c -dpascal= -dpowerc=1 -d__wchar_t__ -qNOSTDINC -qcpluscmt -qansialias -qalign=mac68k -qmaxmem=16000 -qchars=signed -qmacpstr -qarch=ppc -qxflag=ntbtl -qenum=small "
		Set PlatformSwitches "-d XLCPOWERPC=1"
		If {Optimize}
			Set CCompilerSwitches "{CCompilerSwitches} -O3 -Q"
		End
	End
	
	#
	# Which set of include files should we use?
	#
	# Just 1 set at the moment...
	#

	Set CIncludeSwitches " -i :Includes:Public: -i :Includes:Private:"

	#
	# Setup the Make targets
	#
	If {EmulatorGS}
		If {MrC}
			Set MakeTargets "{MakeTargets} '{TargetsPath}Gus.MrC'"
		Else If {xlc}
			Set MakeTargets "{MakeTargets} '{TargetsPath}Gus.xlc'"
		Else If {Moto}
			Set MakeTargets "{MakeTargets} '{TargetsPath}Gus.Moto'"
		Else If {Symantec}
			Set MakeTargets "{MakeTargets} '{TargetsPath}Gus'"
		Else If {GCC}
			Set MakeTargets "{MakeTargets} '{TargetsPath}Gus'"
		Else
			Set MakeTargets "{MakeTargets} '{TargetsPath}Gus'"
		End
	Else
			if {Profile}
				Set MakeTargets "{MakeTargets} '{ObjectsPath}Gus.Profile.rsrc' '{Projects}EmulatorGS'"
			else
				Set MakeTargets "{MakeTargets} '{ObjectsPath}Gus.rsrc' '{Projects}EmulatorGS'"
			end
	End


# ========================================================================================================================
#		Build Gus!
# ========================================================================================================================

	#
	# Echo shell variables for convenience in re-executing MakeOut by hand.  Echo everything
	# at the same time because it's faster than echoing each line individually
	#
Echo "Set TargetsPath '{TargetsPath}';n
Set ObjectsPath '{ObjectsPath}';n
Set Symbols '{Symbols}';n
Export TargetsPath;n
Export ObjectsPath;n
Export Projects;n
Export Symbolsn" >:Make:MakeOut

	#
	# Make Gus
	#
	Make {MakeOptions} {MakeTargets} 
		-f :Make:Makefile 
		-d ADefineSwitches="{ADefineSwitches} {ASymbolSwitches} {CustomFlags}" 
		-d CDefineSwitches="{CDefineSwitches} {CSymbolSwitches} {CustomFlags}" 
		-d CCompilerSwitches="{CCompilerSwitches}" 
		-d CIncludeSwitches="{CIncludeSwitches}" 
		-d PlatformSwitches="{PlatformSwitches}" 
		-d RDefineSwitches="{DefaultRDefineSwitches} {{RDefineSwitches}}{CustomFlags}" 
		-d LinkSwitches="{LinkSwitches} {LinkSymbolSwitches}" 
		-d GusLibLinkSwitches="{GusLibLinkSwitches}"
		-d EmulatorGSLinkSwitches="{EmulatorGSLinkSwitches} {LinkSymbolSwitches}"
		-d Obj="'{ObjectsPath}'" 
		-d TargetObj="'{TargetsPath}'" 
		-d C="{CCompiler}" 
		-d LINK="{Linker}" 
		-d ASM="{Assembler}" 
		-d REZ="{ResourceCompiler}" 
		-d UniversalAInc="{UniversalAIncludes}" 
		-d UniversalRInc="{UniversalRIncludes}" 
		-d UniversalCInc="{UniversalCIncludes}" 
		-d PrivateCInc="{PrivateCIncludes}" 
		-d ROptions="-i {UniversalRIncludes}" 
		>> :Make:MakeOut || Set BuildStatus {Status}

	If {BuildStatus} == 0
		If {DoMakeOut}
			If {Ignore}
				Set Exit 0
			End
			If {NoDoIt}
				DoIt :Make:MakeOut || Set BuildStatus {Status}
			Else
				:Make:MakeOut || Set BuildStatus {Status}
			End
		End
	End
End

If {BuildStatus} == 0
	#
	# Emit the time we finished
	#
	Echo "#"
	Echo "# Finished at:		`date`" >Dev:StdErr
	Echo "#"
	Echo "{MakeTargets}"
	{BuildSuccess}
Else
	#
	# Emit the time we failed
	#
	Echo "#"
	Echo "# Error, stopped:	`date`" >Dev:StdErr
	Echo "#"
	{BuildFailure}
End
Exit {BuildStatus}
