.key -sd/S

if not exists MakeALIB.script
  echo "Please change first to the script's directory!"
  quit
endif

if "<-sd>" EQ ""
  set lbmodel large data
  set alibnam libamiga.a
  set fdflags ""
  set vcflags +ppc -amiga-align -IPPC-CDROM:PPCRelease/PPC-Dev/include
else
  set lbmodel small data
  set alibnam libamigas.a
  set fdflags -sd
  set vcflags +ppc -amiga-align -IPPC-CDROM:PPCRelease/PPC-Dev/include -sd
endif

echo "Checking for required commands. Stopping if missing.*N"

failat 5
  echo noline "which    : "
    which which                 ;stop if missing. :-)
  echo noline "copy     : "
    which copy
  echo noline "delete   : "
    which delete
  echo noline "execute  : "
    which execute
  echo noline "ar       : "
    which ppc-amigaos-ar
  echo noline "list     : "
    which list
  echo noline "fd2lib   : "
    which fd2libPPC
  echo noline "vc       : "
    which vc
failat 20

echo "*NCompiling $alibnam with $lbmodel model. This may take some time..."

echo "*NCleaning T:..."
  delete t:($alibnam|#?.(s|o|dir)) quiet >nil:

echo "*NProcessing FDs..."      ; cia_lib.fd klappt nicht, da keine Base angegeben (?)

  list   >t:mkfds lformat="fd2libppc $fdflags -of *"Creating %%cs...*" -o t: %s%s" fd:(a(migaguide|sl)|b(att(clock|mem)|ullet)|c(ardres|o(lorwheel|mmodities|nsole)))#?.fd
  list  >>t:mkfds lformat="fd2libppc $fdflags -of *"Creating %%cs...*" -o t: %s%s" fd:(d(atatypes|isk(font|%)|os|tclass)|ex(ec|pansion)|g(adtools|raphics))#?.fd
  list  >>t:mkfds lformat="fd2libppc $fdflags -of *"Creating %%cs...*" -o t: %s%s" fd:(i(con|ffparse|n(put|tuition))|keymap|l(ayers|o(cale|wlevel)))#?.fd
  list  >>t:mkfds lformat="fd2libppc $fdflags -of *"Creating %%cs...*" -o t: %s%s" fd:(m(ath(ffp|ieee(doub(bas|trans)|sing(bas|trans))|trans)|isc))#?.fd
  list  >>t:mkfds lformat="fd2libppc $fdflags -of *"Creating %%cs...*" -o t: %s%s" fd:(nonvolatile|potgo|r(amdrive|e(altime|xxsyslib))|t(imer|ranslator)|utility|wb)#?.fd

  execute t:mkfds
  delete  t:mkfds quiet

echo "*NAssembling stubs..."
  vc $vcflags -c t:#?.s

echo "*NRemoving obsolete assembler sources..."
  delete t:#?.s quiet

  ;list >t:MakeALIB.batch t:#?.o LFORMAT "libr -a t:$alibnam *"%s%s*""
  ;execute t:MakeALIB.batch
  ;delete t:MakeALIB.batch quiet

echo "*NCompiling/Assembling support routines..."
  vc $vcflags -c #?.(c|s)

echo "*NJoining everything together..."
  ppc-amigaos-ar q t:$alibname t:*.o *.o

echo "*NCleaning up..."
  delete t:#?.o quiet

unset vcflags
unset fdflags
unset lbmodel

set instto T:

which >nil: ask
if not warn
  ask "*NInstall $alibnam to vlibppc: (y/n)?"
  if warn
    set instto vlibppc:
    failat 21
    copy >nil: t:$alibnam $instto
    if not fail
      delete t:$alibnam quiet
    endif
    failat 20
  endif
endif

if exists ${instto}${alibnam}
  echo "*N*N...poooh... $alibnam can be found in ${instto}."
else
  echo "*N*NInstallation error!"
endif

unset instto
unset alibnam
