ECHO '+====================================================================+'
ECHO '+ Build ReDMCSB executable files for Apple IIGS                      +'
ECHO '+====================================================================+'
ECHO '+====================================================================+'··ReDMCSB:BUILD:MKMG.LOG
ECHO '+ Build ReDMCSB executable files for Apple IIGS                      +'··ReDMCSB:BUILD:MKMG.LOG
ECHO '+====================================================================+'··ReDMCSB:BUILD:MKMG.LOG

Directory REDMCSB:SOURCE

If "`Exists -f REDMCSB:SOURCE:EXEID65.TXT`" OR "`Exists -f REDMCSB:SOURCE:EXEID66.TXT`" OR "`Exists -f REDMCSB:SOURCE:EXEID67.TXT`" OR "`Exists -f REDMCSB:SOURCE:EXEID69.TXT`" OR "`Exists -f REDMCSB:SOURCE:EXEID70.TXT`"
ECHO '----- Convert CLib to OMF v2'
ECHO '----- Convert CLib to OMF v2'··ReDMCSB:BUILD:MKMG.LOG
MakeLibIIGS -p -l REDMCSB:MPW:Libraries:CIIGSLibraries:CLib -o REDMCSB:MPW:Libraries:CIIGSLibraries:CLibOMFv2 -c ··ReDMCSB:BUILD:MKMG.LOG
End

If "`Exists -f REDMCSB:SOURCE:EXEID68.TXT`"
ECHO '----------------------------------------------------------------------'
ECHO '- Build executable G20E\GRAPH21.BIN'
ECHO '----------------------------------------------------------------------'
ECHO '----------------------------------------------------------------------'··ReDMCSB:BUILD:MKMG.LOG
ECHO '- Build executable G20E\GRAPH21.BIN'··ReDMCSB:BUILD:MKMG.LOG
ECHO '----------------------------------------------------------------------'··ReDMCSB:BUILD:MKMG.LOG
ECHO '----- G20E\GRAPH21.BIN Compile GRAPH21.C'
ECHO '----- G20E\GRAPH21.BIN Compile GRAPH21.C'··ReDMCSB:BUILD:MKMG.LOG
CIIGS -DEXEID=68 -p -o ReDMCSB:OBJECT:G20E:GRAPH21.BIN:GRAPH21.OBJ GRAPH21.C··ReDMCSB:BUILD:MKMG.LOG
ECHO '----- G20E\GRAPH21.BIN Link GRAPH21'
ECHO '----- G20E\GRAPH21.BIN Link GRAPH21'··ReDMCSB:BUILD:MKMG.LOG
# Add -s -x parameters for LinkIIGS versions 1.1, 1.2 or 1.3
LinkIIGS -o ReDMCSB:OBJECT:G20E:GRAPH21.BIN:GRAPH21 -l -p -t S16 ReDMCSB:OBJECT:G20E:GRAPH21.BIN:GRAPH21.OBJ··ReDMCSB:BUILD:MKMG.LOG
ECHO '----- G20E\GRAPH21.BIN MakeBin GRAPH21'
ECHO '----- G20E\GRAPH21.BIN MakeBin GRAPH21'··ReDMCSB:BUILD:MKMG.LOG
MakeBinIIGS -o ReDMCSB:BUILD:G20E:GRAPH21.BIN -p -s ReDMCSB:OBJECT:G20E:GRAPH21.BIN:GRAPH21··ReDMCSB:BUILD:MKMG.LOG
End

If "`Exists -f REDMCSB:SOURCE:EXEID66.TXT`" OR "`Exists -f REDMCSB:SOURCE:EXEID65.TXT`"
ECHO '----------------------------------------------------------------------'
ECHO '- Prepare CLIB object files for G14ED'
ECHO '----------------------------------------------------------------------'
ECHO '----------------------------------------------------------------------'··ReDMCSB:BUILD:MKMG.LOG
ECHO '- Prepare CLIB object files for G14ED'··ReDMCSB:BUILD:MKMG.LOG
ECHO '----------------------------------------------------------------------'··ReDMCSB:BUILD:MKMG.LOG
# LinkIIGS 1.2 or 1.3 require standalone object files (outside of a library) to use OMF v2 format
ECHO '----- G14ED Convert START.OBJ to OMF v2'
ECHO '----- G14ED Convert START.OBJ to OMF v2'··ReDMCSB:BUILD:MKMG.LOG
Directory REDMCSB:MPW:Libraries:CIIGSLibraries
MakeLibIIGS -p -l ReDMCSB:OBJECT:G14ED:START:START.LIB -r Start.obj ··ReDMCSB:BUILD:MKMG.LOG
Directory ReDMCSB:OBJECT:G14ED:START
MakeLibIIGS -p -l ReDMCSB:OBJECT:G14ED:START:START.LIB -x Start.obj ··ReDMCSB:BUILD:MKMG.LOG
# The following object files must be extracted from the library because they contain segments that cannot be selected directly from the
# library because their names are not unique in the library ('~globals' and/or '~arrays') yet they need to be linked in a specific order
ECHO '----- G14ED Extract DATA.ROOT and convert to OMF v2'
ECHO '----- G14ED Extract DATA.ROOT and convert to OMF v2'··ReDMCSB:BUILD:MKMG.LOG
MakeLibIIGS -p -l REDMCSB:MPW:Libraries:CIIGSLibraries:CLibOMFv2 -x DATA.ROOT       ··ReDMCSB:BUILD:MKMG.LOG
ECHO '----- G14ED Extract CTYPE.ROOT and convert to OMF v2'
ECHO '----- G14ED Extract CTYPE.ROOT and convert to OMF v2'··ReDMCSB:BUILD:MKMG.LOG
MakeLibIIGS -p -l REDMCSB:MPW:Libraries:CIIGSLibraries:CLibOMFv2 -x CTYPE.ROOT      ··ReDMCSB:BUILD:MKMG.LOG
ECHO '----- G14ED Extract DEVCO.ROOT and convert to OMF v2'
ECHO '----- G14ED Extract DEVCO.ROOT and convert to OMF v2'··ReDMCSB:BUILD:MKMG.LOG
MakeLibIIGS -p -l REDMCSB:MPW:Libraries:CIIGSLibraries:CLibOMFv2 -x DEVCO.ROOT      ··ReDMCSB:BUILD:MKMG.LOG
ECHO '----- G14ED Extract DEVHANDLER.ROOT and convert to OMF v2'
ECHO '----- G14ED Extract DEVHANDLER.ROOT and convert to OMF v2'··ReDMCSB:BUILD:MKMG.LOG
MakeLibIIGS -p -l REDMCSB:MPW:Libraries:CIIGSLibraries:CLibOMFv2 -x DEVHANDLER.ROOT ··ReDMCSB:BUILD:MKMG.LOG
ECHO '----- G14ED Extract DEVSY.ROOT and convert to OMF v2'
ECHO '----- G14ED Extract DEVSY.ROOT and convert to OMF v2'··ReDMCSB:BUILD:MKMG.LOG
MakeLibIIGS -p -l REDMCSB:MPW:Libraries:CIIGSLibraries:CLibOMFv2 -x DEVSY.ROOT      ··ReDMCSB:BUILD:MKMG.LOG
ECHO '----- G14ED Extract DOPRNT.ROOT and convert to OMF v2'
ECHO '----- G14ED Extract DOPRNT.ROOT and convert to OMF v2'··ReDMCSB:BUILD:MKMG.LOG
MakeLibIIGS -p -l REDMCSB:MPW:Libraries:CIIGSLibraries:CLibOMFv2 -x DOPRNT.ROOT     ··ReDMCSB:BUILD:MKMG.LOG
ECHO '----- G14ED Extract ECVT.ROOT and convert to OMF v2'
ECHO '----- G14ED Extract ECVT.ROOT and convert to OMF v2'··ReDMCSB:BUILD:MKMG.LOG
MakeLibIIGS -p -l REDMCSB:MPW:Libraries:CIIGSLibraries:CLibOMFv2 -x ECVT.ROOT       ··ReDMCSB:BUILD:MKMG.LOG
ECHO '----- G14ED Extract FINDBUF.ROOT and convert to OMF v2'
ECHO '----- G14ED Extract FINDBUF.ROOT and convert to OMF v2'··ReDMCSB:BUILD:MKMG.LOG
MakeLibIIGS -p -l REDMCSB:MPW:Libraries:CIIGSLibraries:CLibOMFv2 -x FINDBUF.ROOT    ··ReDMCSB:BUILD:MKMG.LOG
ECHO '----- G14ED Extract IOPTABLE.ROOT and convert to OMF v2'
ECHO '----- G14ED Extract IOPTABLE.ROOT and convert to OMF v2'··ReDMCSB:BUILD:MKMG.LOG
MakeLibIIGS -p -l REDMCSB:MPW:Libraries:CIIGSLibraries:CLibOMFv2 -x IOPTABLE.ROOT   ··ReDMCSB:BUILD:MKMG.LOG
ECHO '----- G14ED Extract RUNTIME.ROOT and convert to OMF v2'
ECHO '----- G14ED Extract RUNTIME.ROOT and convert to OMF v2'··ReDMCSB:BUILD:MKMG.LOG
MakeLibIIGS -p -l REDMCSB:MPW:Libraries:CIIGSLibraries:CLibOMFv2 -x RUNTIME.ROOT    ··ReDMCSB:BUILD:MKMG.LOG
ECHO '----- G14ED Extract SYSUNIX.ROOT and convert to OMF v2'
ECHO '----- G14ED Extract SYSUNIX.ROOT and convert to OMF v2'··ReDMCSB:BUILD:MKMG.LOG
MakeLibIIGS -p -l REDMCSB:MPW:Libraries:CIIGSLibraries:CLibOMFv2 -x SYSUNIX.ROOT    ··ReDMCSB:BUILD:MKMG.LOG
Directory REDMCSB:SOURCE
# Linking CLIB module DEVFS.ROOT would link too many variables in the executables, these two files define only the required variables
ECHO '----- G14ED\START Compile DEVFS1.C'
ECHO '----- G14ED\START Compile DEVFS1.C'··ReDMCSB:BUILD:MKMG.LOG
CIIGS -DEXEID=66 -p -o ReDMCSB:OBJECT:G14ED:START:DEVFS1.OBJ REDMCSB:SOURCE:DEVFS1.C··ReDMCSB:BUILD:MKMG.LOG
ECHO '----- G14ED\START Compile DEVFS2.C'
ECHO '----- G14ED\START Compile DEVFS2.C'··ReDMCSB:BUILD:MKMG.LOG
CIIGS -DEXEID=66 -p -o ReDMCSB:OBJECT:G14ED:DUNGEON.MASTER:DEVFS2.OBJ REDMCSB:SOURCE:DEVFS2.C··ReDMCSB:BUILD:MKMG.LOG
End

If "`Exists -f REDMCSB:SOURCE:EXEID66.TXT`"
ECHO '----------------------------------------------------------------------'
ECHO '- Build executable G14ED\START'
ECHO '----------------------------------------------------------------------'
ECHO '----------------------------------------------------------------------'··ReDMCSB:BUILD:MKMG.LOG
ECHO '- Build executable G14ED\START'··ReDMCSB:BUILD:MKMG.LOG
ECHO '----------------------------------------------------------------------'··ReDMCSB:BUILD:MKMG.LOG
ECHO '----- G14ED\START Compile SWSH.C'
ECHO '----- G14ED\START Compile SWSH.C'··ReDMCSB:BUILD:MKMG.LOG
CIIGS -DEXEID=66 -p -o ReDMCSB:OBJECT:G14ED:START:SWSH.OBJ   REDMCSB:SOURCE:SWSH.C  ··ReDMCSB:BUILD:MKMG.LOG
ECHO '----- G14ED\START Link'
ECHO '----- G14ED\START Link'··ReDMCSB:BUILD:MKMG.LOG
Directory ReDMCSB:OBJECT:G14ED:START
# Add -s -x parameters for LinkIIGS versions 1.1, 1.2 or 1.3
LinkIIGS -o ReDMCSB:BUILD:G14ED:START -l -p -t S16 ¶
	-lseg main ¶
		START.OBJ(@main) ¶
		SWSH.OBJ(@main) ¶
		REDMCSB:MPW:Libraries:CIIGSLibraries:CLibOMFv2(_LCOMP) ¶
		REDMCSB:MPW:Libraries:CIIGSLibraries:CLibOMFv2(setjmp) ¶
		REDMCSB:MPW:Libraries:CIIGSLibraries:CLibOMFv2(c2pstr) ¶
		REDMCSB:MPW:Libraries:CIIGSLibraries:CLibOMFv2(PDosInt) ¶
		REDMCSB:MPW:Libraries:CIIGSLibraries:CLibOMFv2(CQuit) ¶
		RUNTIME.ROOT(_initargcv) ¶
		RUNTIME.ROOT(_RTExit) ¶
		RUNTIME.ROOT(_RTInit) ¶
		RUNTIME.ROOT(retPC) ¶
		RUNTIME.ROOT(exit) ¶
		REDMCSB:MPW:Libraries:CIIGSLibraries:CLibOMFv2(_LADD) ¶
		REDMCSB:MPW:Libraries:CIIGSLibraries:CLibOMFv2(_CALLFUNC) ¶
		REDMCSB:MPW:Libraries:CIIGSLibraries:CLibOMFv2(_LSUB) ¶
		REDMCSB:MPW:Libraries:CIIGSLibraries:CLibOMFv2(longjmp) ¶
		REDMCSB:MPW:Libraries:CIIGSLibraries:CLibOMFv2(_NewPtr) ¶
		REDMCSB:MPW:Libraries:CIIGSLibraries:CLibOMFv2(_EqualString) ¶
		REDMCSB:MPW:Libraries:CIIGSLibraries:CLibOMFv2(p2cstr) ¶
	-lseg:$0041 ~globals ¶
		START.OBJ(~globals) ¶
		RUNTIME.ROOT(~globals) ¶
	-lseg:$0041 ~arrays ¶
		START.OBJ(~arrays) ¶
		SWSH.OBJ(~arrays) ¶
		RUNTIME.ROOT(~arrays) ¶
		DEVFS1.OBJ(~arrays) ¶
	-lseg:direct DIRECT ¶
		REDMCSB:MPW:Libraries:CIIGSLibraries:CLibOMFv2(STACKMIN) ¶
	··ReDMCSB:BUILD:MKMG.LOG
Directory REDMCSB:SOURCE
End

If "`Exists -f REDMCSB:SOURCE:EXEID69.TXT`"
ECHO '----------------------------------------------------------------------'
ECHO '- Build executable G20E\START'
ECHO '----------------------------------------------------------------------'
ECHO '----------------------------------------------------------------------'··ReDMCSB:BUILD:MKMG.LOG
ECHO '- Build executable G20E\START'··ReDMCSB:BUILD:MKMG.LOG
ECHO '----------------------------------------------------------------------'··ReDMCSB:BUILD:MKMG.LOG
ECHO '----- G20E\START Convert STACK1K.OBJ to OMF v2'
ECHO '----- G20E\START Convert STACK1K.OBJ to OMF v2'··ReDMCSB:BUILD:MKMG.LOG
Directory REDMCSB:MPW:Libraries:CIIGSLibraries
MakeLibIIGS -p -l ReDMCSB:OBJECT:G20E:START:STACK1K.LIB -r Stack1K.obj ··ReDMCSB:BUILD:MKMG.LOG
Directory ReDMCSB:OBJECT:G20E:START
MakeLibIIGS -p -l ReDMCSB:OBJECT:G20E:START:STACK1K.LIB -x Stack1K.obj ··ReDMCSB:BUILD:MKMG.LOG
Directory REDMCSB:SOURCE
ECHO '----- G20E\START Assemble INITIIGS.ASM'
ECHO '----- G20E\START Assemble INITIIGS.ASM'··ReDMCSB:BUILD:MKMG.LOG
AsmIIGS             -p -o ReDMCSB:OBJECT:G20E:START:INITIIGS.OBJ INITIIGS.ASM··ReDMCSB:BUILD:MKMG.LOG
ECHO '----- G20E\START Compile SWSH.C'
ECHO '----- G20E\START Compile SWSH.C'··ReDMCSB:BUILD:MKMG.LOG
CIIGS   -DEXEID=69 -p -o ReDMCSB:OBJECT:G20E:START:SWSH.OBJ     SWSH.C      ··ReDMCSB:BUILD:MKMG.LOG
ECHO '----- G20E\START Compile SWSHIIGS.C'
ECHO '----- G20E\START Compile SWSHIIGS.C'··ReDMCSB:BUILD:MKMG.LOG
CIIGS   -DEXEID=69 -p -o ReDMCSB:OBJECT:G20E:START:SWSHIIGS.OBJ SWSHIIGS.C  ··ReDMCSB:BUILD:MKMG.LOG
ECHO '----- G20E\START Link'
ECHO '----- G20E\START Link'··ReDMCSB:BUILD:MKMG.LOG
Directory ReDMCSB:OBJECT:G20E:START
# Add -s -x parameters for LinkIIGS versions 1.1, 1.2 or 1.3
LinkIIGS -o ReDMCSB:BUILD:G20E:START -r -l -p -t S16 ¶
	-lseg main ¶
		INITIIGS.OBJ(@main) ¶
		SWSH.OBJ(@main) ¶
		SWSHIIGS.OBJ(@main) ¶
		REDMCSB:MPW:Libraries:CIIGSLibraries:CLibOMFv2(_LCOMP) ¶
		REDMCSB:MPW:Libraries:CIIGSLibraries:CLibOMFv2(strlen) ¶
		REDMCSB:MPW:Libraries:CIIGSLibraries:CLibOMFv2(PDosInt) ¶
		REDMCSB:MPW:Libraries:CIIGSLibraries:CLibOMFv2(strcpy) ¶
		REDMCSB:MPW:Libraries:CIIGSLibraries:CLibOMFv2(strncmp) ¶
		REDMCSB:MPW:Libraries:CIIGSLibraries:CLibOMFv2(_LSUB) ¶
	-lseg ~globals INITIIGS.OBJ(~globals) ¶
	-lseg:direct Direct STACK1K.OBJ ¶
	-lseg ~arrays ¶
		SWSH.OBJ(~arrays) ¶
		SWSHIIGS.OBJ(~arrays) ¶
	··ReDMCSB:BUILD:MKMG.LOG
Directory REDMCSB:SOURCE
End

# Build game executable files
If "`Exists -f REDMCSB:SOURCE:EXEID65.TXT`"
MKMGGAME.BAT G14ED DUNGEON.MASTER 65
End
If "`Exists -f REDMCSB:SOURCE:EXEID67.TXT`"
MKMGGAME.BAT G20E  DUNGEON.MASTER 67
End
If "`Exists -f REDMCSB:SOURCE:EXEID70.TXT`"
MKMGGAME.BAT G21E  DUNGEON.MASTER 70
End

ECHO '+====================================================================+'
ECHO '+ Build complete                                                     +'
ECHO '+====================================================================+'
ECHO '+====================================================================+'··ReDMCSB:BUILD:MKMG.LOG
ECHO '+ Build complete                                                     +'··ReDMCSB:BUILD:MKMG.LOG
ECHO '+====================================================================+'··ReDMCSB:BUILD:MKMG.LOG
