Skip to content

Instantly share code, notes, and snippets.

@ZenLiuCN
Created March 10, 2025 05:04
Show Gist options
  • Save ZenLiuCN/a89e264472affa76158d897fffffb451 to your computer and use it in GitHub Desktop.
Save ZenLiuCN/a89e264472affa76158d897fffffb451 to your computer and use it in GitHub Desktop.
dll2a
#!/bin/sh
if [ $# -eq 0 ]; then
echo "ERROR:drop *.DLL file to script or pass as first argument"
exit 1
fi
dll_file="$1"
base_name=$(basename "$dll_file" .dll)
def_file="$base_name.def"
a_file="lib$base_name.a"
if [ ! -f "$dll_file" ]; then
echo "ERROR:file '$dll_file' not found"
exit 1
fi
check_tool() {
if ! command -v "$1" >/dev/null 2>&1; then
echo "ERROR:'$1' not found,install first."
exit 1
fi
}
if command -v gendef >/dev/null 2>&1; then
echo "generate .def file (gendef)..."
gendef "$dll_file" >/dev/null
else
check_tool pexports
echo "generate .def file (pexports)..."
pexports "$dll_file" > "$def_file"
fi
if [ ! -f "$def_file" ]; then
echo "ERROR:generate .def fail"
exit 1
fi
dlltool_name="dlltool"
#if file "$dll_file" | grep -q "x86-64"; then
# dlltool_name="x86_64-w64-mingw32-dlltool"
#elif file "$dll_file" | grep -q "Intel 80386"; then
# dlltool_name="i686-w64-mingw32-dlltool"
#fi
echo "generate .a import file ($dlltool_name)..."
if $dlltool_name -d "$def_file" -l "$a_file" -D "$dll_file"; then
echo "SUCCESS: $a_file"
else
echo "ERROR:generate .a fail"
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment