#!/bin/sh
-grep 'extrn ' StarCraft.asm | awk '{print $2}' | awk -F: '{print $1}' > implist
+# warning: i686-w64-mingw32- on Ubuntu 14.04
+# contains broken InterlockedDecrement
+test -n "$mingwb" || mingwb=i686-w64-mingw32
-echo ".data" > tramp.s
-echo ".align 4" >> tramp.s
+target_s=$1
+src_asm=$2
+implist=${target_s}_implist
+tmpsym=${target_s}_tmpsym
+shift 2
-cat implist | while read i; do
- rm -f tmpsym
+grep 'extrn ' $src_asm | awk '{print $2}' | \
+ awk -F: '{print $1}' > $implist
+
+echo ".data" > $target_s
+echo ".align 4" >> $target_s
+
+cat $implist | while read i; do
+ rm -f $tmpsym
case $i in
__imp_*)
si=`echo $i | cut -c 7-`
;;
esac
- grep "\<_$si\>" /usr/i586-mingw32msvc/lib/lib* *.lib | awk '{print $3}' | \
+ grep -e "\<_\?_$si\>" -e "@$si\>" /usr/$mingwb/lib/lib* "$@" | awk '{print $3}' | \
while read f; do
- sym=`i586-mingw32msvc-nm $f | grep "\<_$si\>" | grep ' T ' | awk '{print $3}'`
+ sym=`${mingwb}-nm $f | grep -e "\<_\?_$si\>" -e " @$si\>" | grep ' T ' | awk '{print $3}'`
if test -n "$sym"; then
- echo $sym > tmpsym
+ echo $sym > $tmpsym
break
fi
done
- sym=`cat tmpsym`
+ sym=`cat $tmpsym`
if test -z "$sym"; then
- echo "no file/sym for $i, lf $f"
+ echo "$target_s: no file/sym for $i"
exit 1
fi
- echo ".globl $i" >> tramp.s
- echo "$i:" >> tramp.s
- echo " .long $sym" >> tramp.s
- echo >> tramp.s
+ echo ".globl $i" >> $target_s
+ echo "$i:" >> $target_s
+ echo " .long $sym" >> $target_s
+ echo >> $target_s
done