.key fubar
.bra {
.ket }

echo "Fetching Envoy SFD files..."

copy appn:src/nipc/nipc_lib.sfd "" NOPRO
copy appn:src/envoy/envoy_lib.sfd "" NOPRO
copy appn:src/svc/svc_lib.sfd "" NOPRO
copy appn:src/services/services_lib.sfd "" NOPRO
copy appn:src/accounts/libs/accounts_lib.sfd "" NOPRO

list >t:bf{$$} #?.sfd lformat="do_sfd %m"
execute t:bf{$$}

if EXISTS libfiles
    echo "Deleting old files..."
    delete libfiles ALL QUIET FORCE
endif

makedir libfiles
echo "Copying stubs and LVO files..."
list >t:bc{$$} #?.sfd lformat="copy %m/lvo libfiles quiet"
list >t:bd{$$} #?.sfd lformat="copy %m/ram/#?/#?.asm libfiles quiet"
execute t:bc{$$}
execute t:bd{$$}

cd libfiles
echo "Generating makefile..."
echo >smakefile "# Makefile generated automagically. Don't edit by hand."
echo >>smakefile
echo >>smakefile "OBJS = " NOLINE
list >t:be{$$} #?.asm lformat="echo >>smakefile *" %m.o\*""
execute t:be{$$}
echo >>smakefile " "
echo >>smakefile "all : $(OBJS)"
echo >>smakefile " "
echo >>smakefile ".asm.o:"
echo >>smakefile "    hx68 -a $**.asm -o $**.o"
echo >>smakefile " "
echo "Building .o files..."
smake
if EXISTS envoy.lib
    delete envoy.lib force quiet
endif

assign from{$$}: ""

echo "Copying .o file to ram:"

makedir ram:el{$$}
copy #?.o ram:el{$$} quiet
cd ram:el{$$}

echo "Building envoy.lib (finally!)..."

list >t:bl{$$} #?.o lformat="oml envoy.lib Add %s"
execute t:bl{$$}
copy envoy.lib from{$$}:
copy envoy.lib envoy:lib
cd from{$$}:
delete ram:el{$$} all quiet force
assign from{$$}:

cd /

echo "Installing PROTOS and PRAGMA files..."

copy #?_lib/protos/#? envoy:include/clib quiet nopro
copy #?_lib/pragmas/#? envoy:include/pragmas quiet nopro
copy #?_lib/fd/#? envoy:fd quiet nopro

echo "Cleaning up..."
delete t:bf{$$} quiet
delete t:bl{$$} quiet
delete t:be{$$} quiet
delete t:bd{$$} quiet
delete t:bc{$$} quiet

