3 # Copyright (c) 2013, Derek Buitenhuis
5 # Permission to use, copy, modify, and/or distribute this software for any
6 # purpose with or without fee is hereby granted, provided that the above
7 # copyright notice and this permission notice appear in all copies.
9 # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 # mktemp isn't POSIX, so supply an implementation
19 echo "${2%%XXX*}.${HOSTNAME}.${UID}.$$"
23 echo "Usage: makedef <version_script> <objects>" >&2
30 if [ ! -f "$vscript" ]; then
31 echo "Version script does not exist" >&2
35 for object in "$@"; do
36 if [ ! -f "$object" ]; then
37 echo "Object does not exist: ${object}" >&2
42 # Create a lib temporarily to dump symbols from.
43 # It's just much easier to do it this way
44 libname=$(mktemp -u "library").lib
46 trap 'rm -f -- $libname' EXIT
48 lib -out:${libname} $@ >/dev/null
50 echo "Could not create temporary library." >&2
57 # Determine if we're building for x86 or x86_64 and
58 # set the symbol prefix accordingly.
60 arch=$(dumpbin -headers ${libname} |
62 grep '^ \+.\+machine \+(.\+)' |
64 sed -e 's/^ \{1,\}.\{1,\} \{1,\}machine \{1,\}(\(...\)).*/\1/')
66 if [ "${arch}" = "x86" ]; then
69 if [ "${arch}" != "ARM" ] && [ "${arch}" != "x64" ]; then
70 echo "Unknown machine type." >&2
78 for line in $(cat ${vscript} | tr '\t' ' '); do
79 # We only care about global symbols
80 echo "${line}" | grep -q '^ \+global:'
83 line=$(echo "${line}" | sed -e 's/^ \{1,\}global: *//')
85 echo "${line}" | grep -q '^ \+local:'
91 if [ ${started} = 0 ]; then
95 # Handle multiple symbols on one line
98 # Work around stupid expansion to filenames
99 line=$(echo "${line}" | sed -e 's/\*/.\\+/g')
100 for exp in ${line}; do
101 # Remove leading and trailing whitespace
102 exp=$(echo "${exp}" | sed -e 's/^ *//' -e 's/ *$//')
104 if [ "${regex}" = "none" ]; then
107 regex="${regex};${exp}"
115 dump=$(dumpbin -linkermember:1 ${libname})
121 for exp in ${regex}; do
124 sed -e '/public symbols/,$!d' -e '/^ \{1,\}Summary/,$d' -e "s/ \{1,\}${prefix}/ /" -e 's/ \{1,\}/ /g' |
132 echo "${list}" | sort | uniq | tail -n +2