[3/5] makedef: Extend the script for use with mingw tools as well

Message ID 1503647204-20460-3-git-send-email-martin@martin.st
State Committed
Commit 1a7bf48eed806beea7e835b31b06aa6bc94da5da
Headers show

Commit Message

Martin Storsjö Aug. 25, 2017, 7:46 a.m.
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).
---
Reindented the new if blocks.
---
 compat/windows/makedef | 55 +++++++++++++++++++++++++++++++++++---------------
 1 file changed, 39 insertions(+), 16 deletions(-)

Comments

Luca Barbato Aug. 25, 2017, 5:02 p.m. | #1
On 25/08/2017 09:46, Martin Storsjö wrote:
> 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).
> ---
> Reindented the new if blocks.
> ---
>   compat/windows/makedef | 55 +++++++++++++++++++++++++++++++++++---------------
>   1 file changed, 39 insertions(+), 16 deletions(-)
> 
> diff --git a/compat/windows/makedef b/compat/windows/makedef
> index b3de992..fd7959a 100755
> --- a/compat/windows/makedef
> +++ b/compat/windows/makedef
> @@ -45,7 +45,11 @@ libname=$(mktemp -u "library").lib
>   
>   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
>       echo "Could not create temporary library." >&2
>       exit 1
> @@ -57,18 +61,28 @@ IFS='
>   # Determine if we're building for x86 or x86_64 and
>   # set the symbol prefix accordingly.
>   prefix=""
> -arch=$(dumpbin -headers ${libname} |
> -       tr '\t' ' ' |
> -       grep '^ \+.\+machine \+(.\+)' |
> -       head -1 |
> -       sed -e 's/^ \{1,\}.\{1,\} \{1,\}machine \{1,\}(\(...\)).*/\1/')
> -
> -if [ "${arch}" = "x86" ]; then
> -    prefix="_"
> +if [ -n "$NM" ]; then
> +    case $ARCH in
> +    *86)
> +        prefix="_"
> +        ;;
> +    *)
> +        ;;
> +    esac
>   else
> -    if [ "${arch}" != "ARM" ] && [ "${arch}" != "x64" ]; then
> -        echo "Unknown machine type." >&2
> -        exit 1
> +    arch=$(dumpbin -headers ${libname} |
> +           tr '\t' ' ' |
> +           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
>   
> @@ -112,10 +126,19 @@ for line in $(cat ${vscript} | tr '\t' ' '); do
>   '
>   done
>   
> -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)
> +if [ -n "$NM" ]; then
> +    # Use eval, since NM="nm -g"
> +    dump=$(eval "$NM --defined-only -g ${libname}" |
> +              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}
>   
> 

Seems fine.

Patch

diff --git a/compat/windows/makedef b/compat/windows/makedef
index b3de992..fd7959a 100755
--- a/compat/windows/makedef
+++ b/compat/windows/makedef
@@ -45,7 +45,11 @@  libname=$(mktemp -u "library").lib
 
 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
     echo "Could not create temporary library." >&2
     exit 1
@@ -57,18 +61,28 @@  IFS='
 # Determine if we're building for x86 or x86_64 and
 # set the symbol prefix accordingly.
 prefix=""
-arch=$(dumpbin -headers ${libname} |
-       tr '\t' ' ' |
-       grep '^ \+.\+machine \+(.\+)' |
-       head -1 |
-       sed -e 's/^ \{1,\}.\{1,\} \{1,\}machine \{1,\}(\(...\)).*/\1/')
-
-if [ "${arch}" = "x86" ]; then
-    prefix="_"
+if [ -n "$NM" ]; then
+    case $ARCH in
+    *86)
+        prefix="_"
+        ;;
+    *)
+        ;;
+    esac
 else
-    if [ "${arch}" != "ARM" ] && [ "${arch}" != "x64" ]; then
-        echo "Unknown machine type." >&2
-        exit 1
+    arch=$(dumpbin -headers ${libname} |
+           tr '\t' ' ' |
+           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
 
@@ -112,10 +126,19 @@  for line in $(cat ${vscript} | tr '\t' ' '); do
 '
 done
 
-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)
+if [ -n "$NM" ]; then
+    # Use eval, since NM="nm -g"
+    dump=$(eval "$NM --defined-only -g ${libname}" |
+              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}