.key program,opts

IF "<program>" EQ ""
  echo "Usage> Create filename [opts]"
  QUIT
ENDIF

echo
echo "Execute Create <program> <opts> --) Start"
avail >nil: flush  ; remove unused libraries and devices
assign work<$$>: "" ; logical directory of our CLI work

; step 1: look for the mother of all GST files, this shortens compile time
; NOTE- GST files do not come with SAS_C V6.0, you must create them
IF EXISTS RAD:total.gst          ; ALL Amiga headers inside this GST
 set SASGST RAD:total.gst
 SKIP step2
ENDIF
IF EXISTS SAS_C:total.gst
 set SASGST SAS_C:total.gst
 SKIP step2
ENDIF
; see if program's GST file exist
IF EXISTS work<$$>:<program>.gst
 cmpdate -o work<$$>:<program>.gst work<$$>:h/
 IF WARN
  echo "<program>.GST older than h files, must re-create <program>.GST"
  sc MAXERR=1 MAXWRN=1 MGST=work<$$>:<program>.gst NoObjName work<$$>:h/main.h
 ENDIF
 set SASGST work<$$>:<program>.gst
 SKIP step2
ENDIF
IF NOT EXISTS $SASGST
 echo "*e[32;43m                                       "
 echo "     Unable to find a GST file         "
 echo "                                       *e[0m"
 ask "Compile without a GST ? Y/N  (Y = default)"
 IF WARN
  SKIP endscript
 ENDIF
ENDIF

LAB step2
IF NOT EXISTS work<$$>:<program>
 echo "<program> does not exist"
 SKIP zapofiles
ENDIF

cmpdate -o work<$$>:<program> work<$$>:h/
IF WARN
 echo "<program> older than H files"
 SKIP zapofiles
ENDIF

cmpdate -o work<$$>:<program> work<$$>:cf/
IF WARN
 echo "<program> older than C files"
 SKIP makefiles
ENDIF

IF NOT EXISTS work<$$>:of
 echo "Object File's directory does not exist, making *"of*" directory"
 makedir work<$$>:of
 SKIP makefiles
ENDIF

cmpdate -o work<$$>:<program> work<$$>:of/
IF WARN
 echo "<program> older than Object files"
 SKIP slinkfiles
ENDIF

echo "All files appear to be updated, no action taken."
SKIP endscript

LAB zapofiles
echo "Deleting contents of *"of*" directory"
delete >nil: work<$$>:of/#?.o

LAB makefiles
echo "Compiling C files"
IF EXISTS $SASGST
 sc <opts> MAXWRN=1 MAXERR=1 GST=$SASGST MOD ObjName=work<$$>:of/ work<$$>:cf/#?.c
ELSE
 sc <opts> MAXWRN=1 MAXERR=1 MOD ObjName=work<$$>:of/ work<$$>:cf/#?.c
ENDIF

LAB slinkfiles
echo "Slinking <program>"
slink with work<$$>:<program>.lnk

LAB endscript  ; cleanup
unset SASGST
assign work<$$>:
echo "Execute Create <program> <opts> --) End"
echo
