24 lines
1.5 KiB
Bash
Executable File
24 lines
1.5 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
cd "$(dirname "$0")/.."
|
|
for t in clang lld-link llvm-ar python3 objdump; do command -v "$t" >/dev/null || { echo "Missing $t" >&2; exit 1; }; done
|
|
mkdir -p build/cross/diag
|
|
rm -f build/cross/diag/IPXDIAG.EXE
|
|
out=$PWD/build/cross/diag
|
|
# COFF short import records, IMPORT_NAME_UNDECORATE strips x86 stdcall decoration.
|
|
python3 - "$out" <<'PY'
|
|
import pathlib,struct,sys
|
|
p=pathlib.Path(sys.argv[1]);
|
|
for dll, exports in {'KERNEL32.dll':{'ExitProcess':4,'GetStdHandle':4,'WriteFile':20},'WSOCK32.dll':{'WSAStartup':8,'WSACleanup':0,'WSAGetLastError':0,'socket':12,'closesocket':4,'getsockopt':20,'bind':12,'getsockname':12}}.items():
|
|
for name, n in exports.items():
|
|
data=f'_{name}@{n}\0{dll}\0'.encode('ascii')
|
|
(p/(name+'.imp.obj')).write_bytes(struct.pack('<HHHHIIHH',0,0xffff,0,0x14c,0,len(data),0,3<<2)+data)
|
|
PY
|
|
rm -f "$out/imports.lib"
|
|
llvm-ar rcs "$out/imports.lib" "$out"/*.imp.obj
|
|
clang --target=i686-pc-windows-msvc -march=i386 -mno-sse -mno-sse2 -ffreestanding -fno-builtin -fno-stack-protector -Os -Wall -Wextra -c clients/windows/diag/ipxdiag.c -o "$out/ipxdiag.obj"
|
|
lld-link /entry:start /subsystem:console,4.0 /osversion:4.0 /nodefaultlib /machine:x86 /safeseh:no /dynamicbase:no /nxcompat:no /timestamp:0 /out:"$out/IPXDIAG.EXE" "$out/ipxdiag.obj" "$out/imports.lib"
|
|
objdump -p "$out/IPXDIAG.EXE" > "$out/imports.txt"
|
|
python3 cross/verify-pe.py "$out/IPXDIAG.EXE" exe
|
|
printf 'Diagnostic built: %s\n' "$out/IPXDIAG.EXE"
|