sots-engine/tools/build-shim.sh

41 lines
1.9 KiB
Bash
Executable file

#!/usr/bin/env bash
# Build the shim (binkw32.dll) with the MinGW i686 cross toolchain and stage a deployable set.
# Runs on the build box (CT111). Env:
# BUILD_ID stamp for the log banner (default: git describe or "nogit", plus UTC time)
# DIST staging dir (default /srv/re-lab/shim/dist, == Z:\shim\dist on the game VM)
# REAL_DLL original binkw32.dll to compare export tables against (skipped if absent)
set -euo pipefail
cd "$(dirname "$0")/.."
BUILD_ID=${BUILD_ID:-$(git describe --always --dirty 2>/dev/null || echo nogit)-$(date -u +%Y%m%dT%H%MZ)}
DIST=${DIST:-/srv/re-lab/shim/dist}
REAL_DLL=${REAL_DLL:-/srv/re-lab/sots-game/binkw32.dll}
OBJDUMP=${OBJDUMP:-i686-w64-mingw32-objdump}
cmake --preset shim -DSHIM_BUILD_ID="$BUILD_ID"
cmake --build --preset shim
dll=build-shim/binkw32.dll
"$OBJDUMP" -p "$dll" > build-shim/exports.txt
# Export-table check: names must be byte-identical to the real DLL's (the exe imports by name).
names() { # the "[Ordinal/Name Pointer] Table" section only (the address table also lists +base[ rows)
"$OBJDUMP" -p "$1" | sed -n '/Ordinal\/Name Pointer\] Table/,/^$/p' | awk '/\+base\[/ { print $6 }' | sort
}
if [ -f "$REAL_DLL" ]; then
if diff <(names "$REAL_DLL") <(names "$dll") > build-shim/exports.diff; then
echo "exports: $(names "$dll" | wc -l) names, identical to $(basename "$REAL_DLL")"
else
echo "exports: MISMATCH vs $REAL_DLL:"; cat build-shim/exports.diff; exit 1
fi
else
echo "exports: $(names "$dll" | wc -l) names (no REAL_DLL to compare against)"
fi
mkdir -p "$DIST"
cp "$dll" src/shim/shim.cfg tools/deploy.ps1 tools/undeploy.ps1 "$DIST/"
# Per-milestone config variants (shim.cfg.<tag>) ship alongside the default one; a run copies
# the variant it wants over C:\SOTS\shim.cfg.
for cfg in src/shim/shim.cfg.*; do [ -e "$cfg" ] && cp "$cfg" "$DIST/"; done
echo "$BUILD_ID" > "$DIST/BUILD_ID"
echo "staged $BUILD_ID in $DIST"