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

set alibnam amiga.lib
set fdflags -nv
set vcflags +warpos -amiga-align

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 "join     : "
    which join
  echo noline "list     : "
    which list
  echo noline "fd2libWOS: "
    which fd2libWOS
  echo noline "vc       : "
    which vc
failat 20

echo "*NCompiling $alibnam for WarpOS/PowerPC. This may take some time..."

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

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

  list   >t:mkfds lformat="fd2libWOS $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="fd2libWOS $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="fd2libWOS $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="fd2libWOS $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="fd2libWOS $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 "*NAssembling LVOs..."
  vc -c t:#?.asm

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

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

echo "*NJoining everything together..."
  join #?.o T:#?.o to T:$alibnam

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

unset vcflags
unset fdflags

set instto T:

which >nil: ask
if not warn
  ask "*NInstall $alibnam to vlibwos: (y/n)?"
  if warn
    set instto vlibwos:
    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
