makedef: Extend the script for use with mingw tools as well

This is invoked by setting the NM and AR variables to the names of
those specific tools. The ARCH variable also needs to be provided,
to choose the symbol prefix (nm doesn't provide any option that
dumps the architecture easily).

Signed-off-by: Martin Storsjö <martin@martin.st>
This commit is contained in:
Martin Storsjö 2017-08-24 23:05:21 +03:00
parent 44aa9105c5
commit 1a7bf48eed

View File

@ -45,7 +45,11 @@ libname=$(mktemp -u "library").lib
trap 'rm -f -- $libname' EXIT trap 'rm -f -- $libname' EXIT
lib -out:${libname} $@ >/dev/null if [ -n "$AR" ]; then
$AR rcs ${libname} $@ >/dev/null
else
lib -out:${libname} $@ >/dev/null
fi
if [ $? != 0 ]; then if [ $? != 0 ]; then
echo "Could not create temporary library." >&2 echo "Could not create temporary library." >&2
exit 1 exit 1
@ -57,18 +61,28 @@ IFS='
# Determine if we're building for x86 or x86_64 and # Determine if we're building for x86 or x86_64 and
# set the symbol prefix accordingly. # set the symbol prefix accordingly.
prefix="" prefix=""
arch=$(dumpbin -headers ${libname} | if [ -n "$NM" ]; then
tr '\t' ' ' | case $ARCH in
grep '^ \+.\+machine \+(.\+)' | *86)
head -1 | prefix="_"
sed -e 's/^ \{1,\}.\{1,\} \{1,\}machine \{1,\}(\(...\)).*/\1/') ;;
*)
if [ "${arch}" = "x86" ]; then ;;
prefix="_" esac
else else
if [ "${arch}" != "ARM" ] && [ "${arch}" != "x64" ]; then arch=$(dumpbin -headers ${libname} |
echo "Unknown machine type." >&2 tr '\t' ' ' |
exit 1 grep '^ \+.\+machine \+(.\+)' |
head -1 |
sed -e 's/^ \{1,\}.\{1,\} \{1,\}machine \{1,\}(\(...\)).*/\1/')
if [ "${arch}" = "x86" ]; then
prefix="_"
else
if [ "${arch}" != "ARM" ] && [ "${arch}" != "x64" ]; then
echo "Unknown machine type." >&2
exit 1
fi
fi fi
fi fi
@ -112,10 +126,19 @@ for line in $(cat ${vscript} | tr '\t' ' '); do
' '
done done
dump=$(dumpbin -linkermember:1 ${libname} | if [ -n "$NM" ]; then
sed -e '/public symbols/,$!d' -e '/^ \{1,\}Summary/,$d' -e "s/ \{1,\}${prefix}/ /" -e 's/ \{1,\}/ /g' | # Use eval, since NM="nm -g"
tail -n +2 | dump=$(eval "$NM --defined-only -g ${libname}" |
cut -d' ' -f3) grep -v : |
grep -v ^$ |
cut -d' ' -f3 |
sed -e "s/^${prefix}//")
else
dump=$(dumpbin -linkermember:1 ${libname} |
sed -e '/public symbols/,$!d' -e '/^ \{1,\}Summary/,$d' -e "s/ \{1,\}${prefix}/ /" -e 's/ \{1,\}/ /g' |
tail -n +2 |
cut -d' ' -f3)
fi
rm ${libname} rm ${libname}