#
# This is the Makefile for creating the Apple II Setup disk
#
# Modification History
# ??-???-88	MSD	First try
# 23-Jan-89	MSD	Files in the :work: folder can be found
#			elsewhere in the project tree.  Also, the
#			file A2e.Blocks is part of the project and
#			will become the Apple //e Boot Blocks file.
# 24-Jan-91	MSD	We now build the Apple //e Boot Blocks from
#			real source files and the P8 object file.
#
# 11-Jun-91	MSD	Made ProDOS16 Image dependent on Makefile.
#			Changed max version of components to 4 so they'll
#			load on a Mark Twain.  Moved Logon to $00/6800.
#			Protocols now load in bank 2.
#
# 09-Jul-91	MSD	Changed max version for ATROM to 4 so it will load
#			on all ROMs.
#
# 01-Apr-92	MSD	Added EtherTalk driver to ProDOS16 Image.
#
# 25-Nov-92	DAL	Changed 'cat' to 'catenate' (Mark must have had
#			an alias for that).
#


image		=	:work:"ProDOS16 Image"
blocks		=	:work:"ProDOS16 Boot Blocks"
mi		=	:makeimage:
gsos		=	::
SD		=	{gsos}SystemDisk:
SDSystem	=	{SD}System:
SDDrivers	=	{SDSystem}Drivers:
Drivers		=	{gsos}Drivers:
GSProj		=	:::
Basic		=	{GSProj}Basic.System:
iie		=	:IIeBlocks:
Logon		=	:Logon:
Cons		=	:Console:


TheDisk				{blocks} 
				{image} 
				:work:"Apple //e Boot Blocks" 
				:work:P8 
				:work:Basic.System
	build.disk


:work:"Apple //e Boot Blocks"		{iie}Reloc 
					:work:P8 
					:Logon:BootLog8
	Catenate {iie}Reloc :work:P8 :Logon:BootLog8 > {Targ}
	echo "x" | Rez -o {Targ} -c pdos -t $70060800  dev:null || set status 0
	setfile -m . {Targ}					


{iie}Reloc			{iie}Reloc.o
	LinkIIGS -o {Targ} {iie}Reloc.o
	MakeBinIIGS {Targ}

{iie}Reloc.o			{iie}Reloc.aii {iie}P8Size {iie}LogonSize
	If "{MSDListFlag}"
		Set AsmOptions "-f -l -lo {iie}Reloc.lst"
	End
	AsmIIGS {AsmOptions} 
		-d P8Size=`catenate {iie}P8Size` 
		-d LogonSize=`catenate {iie}LogonSize` 
		{iie}Reloc.aii -o {Targ}
	
{iie}P8Size			:work:P8
	(Evaluate "`files -n -x b :work:P8`" =~ /[0-9]([0-9]+)1b/)  dev:null
	echo -n {1} > {Targ}

{iie}LogonSize			{Logon}BootLog8
	(Evaluate "`files -n -x b {Logon}BootLog8`" =~ /[0-9]([0-9]+)1b/)  dev:null
	echo -n {1} > {Targ}


{blocks}			:boot:boot
	duplicate -y :boot:boot {blocks}

:boot:boot			:boot:boot.o
	If "{MSDListFlag}"
		Set LnkOptions "-l > :boot:boot.map"
	End
	LinkIIGS -o :boot:boot :boot:boot.o {LnkOptions}
	MakeBinIIGS -org $800 :boot:boot

:boot:boot.o			:boot:boot.aii
	If "{MSDListFlag}"
		Set AsmOptions "-f -l -lo :boot:boot.lst"
	End
	AsmIIGS -o :boot:boot.o :boot:boot.aii {AsmOptions}


{image}				{mi}mi 
				Makefile 
				:fizzy:fizzy 
				:stub:stub 
				:work:p8 
				:logon:BootLog16 
				:work:ATP1.ATRom 
				:work:ATP2.ATRam 
				:work:ETBoot
	set ramorg `Evaluate 0x020000`
	makebiniigs -o :work:atram -org "{ramorg}" :work:atp2.atram
	(evaluate "`files -n -x b :work:atram`" =~ /[ ]+([0-9]+)1b/) > Dev:Null
	set romorg `evaluate {ramorg} + {1}`
	makebiniigs -o :work:atrom -org "{romorg}" :work:atp1.atrom
	makebiniigs -o :work:ETBoot.bin -org "{ramorg}" :work:ETBoot
	{mi}mi	{image} 
		:fizzy:fizzy,$1000,4
		:stub:stub,$2000,4,1
		:work:p8,$2000,4,2
		:Logon:BootLog16,$6800,4
		:work:atrom,"{romorg}",4,0,1
		:work:atram,"{ramorg}",4,0,1
		:work:ETBoot.bin,"{ramorg}",4,0,2
	unset ramorg romorg

{mi}mi				{mi}main.c.o
	if "`exists "{CLibraries}CInterface.o"`" && "`exists "{Clibraries}CRuntime.o"`"
		Set MyLibs "`quote	"{Libraries}"Stubs.o 
					"{CLibraries}"CRuntime.o 
					"{CLibraries}"StdCLib.o 
					"{CLibraries}"CInterface.o 
					"{Libraries}"Interface.o 
					"{Libraries}"ToolLibs.o`"
	else
		Set MyLibs "`quote	"{Libraries}"Stubs.o 
					"{Libraries}"Runtime.o 
					"{CLibraries}"StdCLib.o 
					"{Libraries}"Interface.o 
					"{Libraries}"ToolLibs.o`"
	end
	Link -w -t MPST -c "MPS " {mi}main.c.o 
		{MyLibs} 
		-o {mi}mi

{mi}main.c.o			{mi}main.c
	C {mi}main.c -o {mi}main.c.o

:fizzy:fizzy			:fizzy:fizzy.o
	If "{MSDListFlag}"
		Set LnkOptions "-l > :fizzy:fizzy.map"
	End
	LinkIIGS -o :fizzy:fizzy :fizzy:fizzy.o {LnkOptions}
	MakeBinIIGS -org $1000 :fizzy:fizzy

:fizzy:fizzy.o			:fizzy:fizzy.aii
	If "{MSDListFlag}"
		Set AsmOptions "-f -l -lo :fizzy:fizzy.lst"
	End
	AsmIIGS -o :fizzy:fizzy.o :fizzy:fizzy.aii {AsmOptions}

:stub:stub			:stub:stub.o
	If "{MSDListFlag}"
		Set LnkOptions "-l > :stub:stub.map"
	End
	linkiigs -o :stub:stub :stub:stub.o {LnkOptions}
	makebiniigs -org $2000 :stub:stub

:stub:stub.o			:stub:stub.aii
	If "{MSDListFlag}"
		Set AsmOptions "-f -l -lo :stub:stub.lst"
	End
	AsmIIGS -o :stub:stub.o :stub:stub.aii {AsmOptions}

:logon:BootLog16		:logon:BootLog16.o 
				:console:console.o 
				:logon:DES.o
	If "{MSDListFlag}"
		Set LnkOptions "-l > :logon:BootLog16.map"
	End
	LinkIIGS -o :logon:BootLog16 
		:logon:BootLog16.o 
		:Console:Console.o 
		:logon:DES.o 
		{LnkOptions}
	MakeBinIIGS -org $6800 :logon:BootLog16

:Logon:BootLog8			{iie}P8Size 
				{Logon}BootLog8.o 
				{Cons}Console.o 
				{Logon}DES.o
	If "{MSDListFlag}"
		Set LnkOptions "-l > :logon:BootLog8.map"
	End
	LinkIIGS -o {Targ} 
		{Logon}BootLog8.o 
		{Cons}Console.o 
		{Logon}DES.o 
		{LnkOptions}
	Set P8Size `catenate {iie}P8Size`
	Set LogonORG `Evaluate 0x2000+{P8Size}`
	MakeBinIIGS -org {LogonORG} {Targ}

:logon:BootLog16.o		:logon:BootLog16.aii 
				:logon:logon.main 
				:logon:icon.aii 
				:console:console.equates 
				:console:cons.macros
	If "{MSDListFlag}"
		Set AsmOptions "-f -l -lo :logon:BootLog16.lst"
	End
	AsmIIGS -i :console: -o :logon:BootLog16.o :logon:BootLog16.aii {AsmOptions}

{Logon}BootLog8.o		{Logon}BootLog8.aii 
				{Logon}Logon.main 
				{Logon}Icon.aii 
				{Cons}console.equates 
				{Cons}Cons.macros
	If "{MSDListFlag}"
		Set AsmOptions "-f -l -lo :logon:BootLog8.lst"
	End
	AsmIIGS -i :console: -o {Targ} :logon:BootLog8.aii {AsmOptions}

:Console:Console.o		:Console:Console.aii 
				:Console:input.aii 
				:Console:strings.aii 
				:console:console.equates 
				:console:cons.macros
	If "{MSDListFlag}"
		Set AsmOptions "-f -l -lo :Console:Console.lst"
	End
	AsmIIGS -i :console: -o :Console:Console.o :Console:Console.aii {AsmOptions}

:logon:DES.o			:logon:DES.aii
	If "{MSDListFlag}"
		Set AsmOptions "-f -l -lo :logon:DES.lst"
	End
	AsmIIGS -o :logon:DES.o :logon:DES.aii {AsmOptions}

:work:P8			Always.Do.This
	Duplicate -y -d {SDSystem}P8 :work:P8

:work:Basic.System		Always.Do.This
	Duplicate -y -d {Basic}Basic.System :work:Basic.System

:work:ATP1.ATRom		Always.Do.This
	Duplicate -y -d {SDDrivers}ATP1.ATRom :work:ATP1.ATRom

:work:ATP2.ATRam		Always.Do.This
	Duplicate -y -d {SDDrivers}ATP2.ATRam :work:ATP2.ATRam

:work:ETBoot			Always.Do.This
	Duplicate -y -d {Drivers}ETalk:ETBoot :work:ETBoot


#
# This is a "false target" that forces some files in other places in the
# GSProjects project to be rebuilt if necessary.
#
Always.Do.This		
	set BootEcho "{echo}"
	set echo 0
	Directory ::Scripts:
	echo "t# Building ATP1.ATROM..."
	Build -s atrom
	echo "t# Building ATP2.ATRAM..."
	Build -s atram
	echo "t# Building ETalk..."
	Build -s etalk
	echo "t# Building P8..."
	Build -s p8
	Directory :::BASIC.System
	BuildProgram BASIC.System
	Directory ::GS.OS:NetBoot
	set echo "{BootEcho}"
	