Files
TeslaRel410/restoration/source410/build410.sh
T
CydandClaude Fable 5 6b216d0643 source410: link campaign - entire engine compiles (152/152), first true link,
52-symbol unresolved ledger

build410.sh: merged-engine mass compile + BT TUs + tlib + authentic tlink32.
Engine closure fixes: boxtree/set/l4gauge/filestrm back-dates, lamp<->gaugrend
cycle broken (1995 form), APP.HPP Shutdown default, NetNub include path, DPL
vpx shim, SOS 32-bit lib arbitration (SOSDBXC/SOSMBXC; SOSMW*=16-bit), WATTCP
excluded (16-bit NetNub TSR side). UNRESOLVED-LEDGER.txt = the measured gap to
a linking BTL4OPT.EXE.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-19 08:46:05 -05:00

160 lines
6.3 KiB
Bash

#!/bin/bash
# build410.sh -- assemble BTL4OPT.EXE from the reconstructed 4.10 tree.
#
# Stages:
# 1. mass-compile the merged engine source (CODE/BT over CODE/RP over
# source410 backfills) into build410/obj/{munga,mungal4}/
# 2. compile the BT game TUs (CODE originals + source410) into
# build410/obj/{bt,btl4}/
# 3. tlib the four libs; prebuilt-1995 .obj fallbacks fill source gaps
# 4. tlink32 with the authentic OPT.MAK order; unresolved externals ->
# build410/UNRESOLVED.txt (the canonical remaining-work ledger)
#
# Usage: ./build410.sh [engine|bt|libs|link|all|status]
T=/c/VWE/TeslaRel410
TW=c:/VWE/TeslaRel410
export PATH="$T/BORLAND/BC45/BIN:$PATH"
C=$TW/CODE/BT
R=$TW/CODE/RP
S=$TW/restoration/source410
B=$T/restoration/build410
Bw=$TW/restoration/build410
INC="$S/override;$C/BT_L4;$C/BT;$C/MUNGA;$C/MUNGA_L4;$C/MUNGA_L4/SOS/BC4;$S/MUNGA;$S/MUNGA_L4;$R/MUNGA;$R/MUNGA_L4;$R/MUNGA_L4/NetNub;$R/MUNGA_L4/sos/bc4;$C/MUNGA_L4/LIBDPL;$C/MUNGA_L4/NETNUB;$C/MUNGA_L4/NETNUB/INCLUDE;$S/MUNGA_L4;$R/MUNGA_L4/libDPL;$R/MUNGA_L4/libDPL/dpl;$S/shim;$S/BT;$S/BT_L4;$TW/BORLAND/BC45/INCLUDE"
FLAGS="-c -DLBE4 -DDEBUG_LEVEL=0 -DDEBUG_STREAM=cout \
-b -r -ff -AT -k- -N- -v- -5 -a4 -V -Jg -x- -RT- -O2 -w-"
mkdir -p "$B"/obj/{munga,mungal4,bt,btl4} "$B"/lib
# compile one TU into a bucket; skip if the obj is newer than the source
cc() { # cc <bucket> <src>
local out="$B/obj/$1/$(basename "${2%.*}" | tr 'A-Z' 'a-z').obj"
[ -f "$out" ] && [ "$out" -nt "$2" ] && return 0
if bcc32 $FLAGS -I"$INC" -o"$(cygpath -w "$out" 2>/dev/null || echo $out)" "$2" \
> "$B/obj/$1/$(basename "${2%.*}").log" 2>&1; then
return 0
else
rm -f "$out"; return 1
fi
}
# merged engine source view: BT tree wins, RP fills, source410 backfills last
merged() { # merged <BTdir> <RPdir> [S410dir]
{ ls "$1"/*.CPP "$1"/*.cpp 2>/dev/null | sed 's/.*[\\/]//'
ls "$2"/*.CPP "$2"/*.cpp 2>/dev/null | sed 's/.*[\\/]//'
[ -n "$3" ] && ls "$3"/*.CPP 2>/dev/null | sed 's/.*[\\/]//'
} | tr 'A-Z' 'a-z' | sort -u
}
srcfor() { # srcfor <name.cpp> <BTdir> <RPdir> [S410dir]
case "$1" in
filestrm.cpp) echo "$3/FILESTRM.CPP"; return;; # BT pair = post-4.10 drift
l4vidper.cpp|l4tsdpl.cpp) return;; # not in mungal4.lib
esac
for d in "$2" "$4" "$3"; do # BT first, then source410, then RP
[ -z "$d" ] && continue
for f in "$d"/*.CPP "$d"/*.cpp; do
[ -f "$f" ] || continue
[ "$(basename "$f" | tr 'A-Z' 'a-z')" = "$1" ] && { echo "$f"; return; }
done
done
}
stage_engine() {
local ok=0 fail=0 failed=""
for lib in munga mungal4; do
local bd rd sd
if [ $lib = munga ]; then bd=$C/MUNGA; rd=$R/MUNGA; sd=$S/MUNGA; else bd=$C/MUNGA_L4; rd=$R/MUNGA_L4; sd=$S/MUNGA_L4; fi
for n in $(merged "$bd" "$rd" "$sd"); do
src=$(srcfor "$n" "$bd" "$rd" "$sd")
[ -z "$src" ] && continue
if cc $lib "$src"; then ok=$((ok+1)); else fail=$((fail+1)); failed="$failed $lib/$n"; fi
done
done
echo "ENGINE: $ok ok, $fail fail"
for f in $failed; do echo " FAIL $f"; done | head -60
for f in $failed; do echo "$f"; done > "$B/ENGINE-FAILURES.txt"
}
stage_bt() {
local ok=0 fail=0
for n in $(merged "$C/BT" /dev/null "$S/BT"); do
src=$(srcfor "$n" "$C/BT" /dev/null "$S/BT")
[ -z "$src" ] && continue
if cc bt "$src"; then ok=$((ok+1)); else fail=$((fail+1)); echo " FAIL bt/$n"; fi
done
for n in $(merged "$C/BT_L4" /dev/null "$S/BT_L4"); do
src=$(srcfor "$n" "$C/BT_L4" /dev/null "$S/BT_L4")
[ -z "$src" ] && continue
if cc btl4 "$src"; then ok=$((ok+1)); else fail=$((fail+1)); echo " FAIL btl4/$n"; fi
done
echo "BT: $ok ok, $fail fail"
}
stage_libs() {
cd "$B/lib"
for lib in munga mungal4 bt btl4; do
rm -f $lib.lib
ls "$B/obj/$lib"/*.obj >/dev/null 2>&1 || continue
: > $lib.rsp
for o in "$B/obj/$lib"/*.obj; do
printf '+..\obj\%s\%s &
' "$lib" "$(basename "$o")" >> $lib.rsp
done
# prebuilt-1995 fallbacks for TUs with no compiled obj
if [ $lib = munga ] || [ $lib = mungal4 ]; then
for o in $(find $R/MUNGA/opt $R/MUNGA_L4 -iname "*.obj" 2>/dev/null); do
n=$(basename "${o%.*}" | tr 'A-Z' 'a-z')
if [ ! -f "$B/obj/munga/$n.obj" ] && [ ! -f "$B/obj/mungal4/$n.obj" ]; then
case "$lib/$o" in
munga/*/MUNGA/*) printf '+%s &
' "$(cygpath -w "$o" | sed 's|\|\\|g')" >> $lib.rsp;;
mungal4/*/MUNGA_L4/*) printf '+%s &
' "$(cygpath -w "$o" | sed 's|\|\\|g')" >> $lib.rsp;;
esac
fi
done
fi
sed -i '$ s/ &$//' $lib.rsp
MSYS2_ARG_CONV_EXCL='*' tlib $lib.lib /P32 @$lib.rsp > $lib.tlib.log 2>&1
echo "$lib.lib: $(grep -c '^+' $lib.rsp) members ($(ls -la $lib.lib 2>/dev/null | awk '{print $5}') bytes)"
done
}
stage_link() {
cd "$B"
if [ ! -f obj/btl4/btl4.obj ] && [ -f probe_main.cpp ]; then
bcc32 $FLAGS -I"$INC" -oprobe_main.obj probe_main.cpp > probe_main.log 2>&1 || { echo "probe main FAILED (probe_main.log)"; return 1; }
MAIN=probe_main.obj
else
MAIN=obj/btl4/btl4.obj
fi
cat > link.rsp <<EOF2
$(cygpath -w $C/C0X32.OBJ)+
$MAIN,
btl4opt.exe,
btl4opt.map,
lib/munga.lib+
lib/mungal4.lib+
$(cygpath -w $R/MUNGA_L4/libDPL/LIBDPL.LIB)+
$(cygpath -w $R/MUNGA_L4/sos/SOSMWXCR.LIB)+
$(cygpath -w $R/MUNGA_L4/NetNub/lib/WATTCPLG.LIB)+
lib/bt.lib+
lib/btl4.lib+
$(cygpath -w $R/DPMI32.LIB)+
$(cygpath -w $R/CW32.LIB)
EOF2
tlink32 -Tpe -ax -m -L"$(cygpath -w $TW/BORLAND/BC45/LIB)" @link.rsp > link.log 2>&1
grep -i "undefined" link.log | sed "s/^.*Error: //" | sort -u > UNRESOLVED.txt
echo "link exit: $? ; unresolved: $(wc -l < UNRESOLVED.txt) (build410/UNRESOLVED.txt)"
}
case "${1:-all}" in
engine) stage_engine;;
bt) stage_bt;;
libs) stage_libs;;
link) stage_link;;
status) for d in munga mungal4 bt btl4; do echo "$d: $(ls "$B/obj/$d"/*.obj 2>/dev/null | wc -l) objs"; done;;
all) stage_engine; stage_bt; stage_libs; stage_link;;
esac