72 lines
2.6 KiB
Bash
Executable File
72 lines
2.6 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Regenerate MinGW import libraries for the in-scope companion DLLs (T3).
|
|
# Conventions and derivation: docs/companion-conventions.md.
|
|
#
|
|
# --kill-at strips the @N decoration dlltool would otherwise read off the
|
|
# .def and write into the import name; applying it to a cdecl DLL would
|
|
# mislabel the import's ABI, so it is passed only for the stdcall entries
|
|
# below (arkkdm and Kinect10 both export under their plain, undecorated
|
|
# names despite being stdcall -- see docs/companion-conventions.md).
|
|
#
|
|
# Shipped companion DLLs come from the clean release layout in orig/. The
|
|
# Kinect10 runtime is external to that release; its independently-derived
|
|
# committed definition remains the source for that import library.
|
|
#
|
|
# Usage: tools/gen_importlibs.sh [clean_module_dir]
|
|
# Must be run with the i686 cross toolchain on PATH (source ./activate.sh).
|
|
|
|
set -euo pipefail
|
|
|
|
SELF_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
REPO_ROOT="$(cd "$SELF_DIR/.." && pwd)"
|
|
SRC_DIR="${1:-/home/athapa/kdm-re/orig}"
|
|
OUT_DIR="$REPO_ROOT/re/importlibs"
|
|
|
|
[ -d "$SRC_DIR" ] || { echo "gen_importlibs.sh: missing directory $SRC_DIR" >&2; exit 1; }
|
|
|
|
for tool in gendef i686-w64-mingw32-dlltool; do
|
|
command -v "$tool" >/dev/null 2>&1 || {
|
|
echo "gen_importlibs.sh: required tool '$tool' not found on PATH; source activate.sh first" >&2
|
|
exit 1
|
|
}
|
|
done
|
|
|
|
mkdir -p "$OUT_DIR"
|
|
|
|
declare -A CONV=( # name -> cdecl | stdcall
|
|
[libavs-win32]=cdecl
|
|
[libavs-win32-ea3]=cdecl
|
|
[libafp-win32]=cdecl
|
|
[libafputils-win32]=cdecl
|
|
[ess]=cdecl
|
|
[arkkdm]=stdcall
|
|
[arkkdmtest]=cdecl
|
|
[libacio]=cdecl
|
|
[Kinect10]=stdcall
|
|
)
|
|
|
|
WORK="$(mktemp -d)"
|
|
trap 'rm -rf "$WORK"' EXIT
|
|
|
|
for name in "${!CONV[@]}"; do
|
|
if [ "$name" = Kinect10 ]; then
|
|
cp "$OUT_DIR/$name.def" "$WORK/$name.def"
|
|
else
|
|
dll="$SRC_DIR/$name.dll"
|
|
[ -f "$dll" ] || { echo "gen_importlibs.sh: missing $dll" >&2; exit 1; }
|
|
cp "$dll" "$WORK/$name.dll"
|
|
(cd "$WORK" && gendef "$name.dll")
|
|
# gendef infers gameMain@4 from the function body even though the
|
|
# clean cdecl arkkdmtest export table names it gameMain.
|
|
[ "$name" != arkkdmtest ] ||
|
|
perl -0pi -e 's/^gameMain\@4\r?$/gameMain/m' "$WORK/$name.def"
|
|
fi
|
|
|
|
dlltool_flags=(-d "$WORK/$name.def" -l "$OUT_DIR/lib$name.dll.a" -D "$name.dll")
|
|
[ "${CONV[$name]}" = stdcall ] && dlltool_flags+=(--kill-at)
|
|
i686-w64-mingw32-dlltool "${dlltool_flags[@]}"
|
|
|
|
cp "$WORK/$name.def" "$OUT_DIR/$name.def"
|
|
echo "generated $OUT_DIR/lib$name.dll.a (${CONV[$name]}) from $WORK/$name.def"
|
|
done
|