makedef 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. #!/bin/sh
  2. # Copyright (c) 2013, Derek Buitenhuis
  3. #
  4. # Permission to use, copy, modify, and/or distribute this software for any
  5. # purpose with or without fee is hereby granted, provided that the above
  6. # copyright notice and this permission notice appear in all copies.
  7. #
  8. # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  9. # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  10. # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  11. # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  12. # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  13. # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  14. # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. # mktemp isn't POSIX, so supply an implementation
  16. mktemp() {
  17. echo "${2%%XXX*}.${HOSTNAME}.${UID}.$$"
  18. }
  19. if [ $# -lt 2 ]; then
  20. echo "Usage: makedef <version_script> <objects>" >&2
  21. exit 0
  22. fi
  23. vscript=$1
  24. shift
  25. if [ ! -f "$vscript" ]; then
  26. echo "Version script does not exist" >&2
  27. exit 1
  28. fi
  29. for object in "$@"; do
  30. if [ ! -f "$object" ]; then
  31. echo "Object does not exist: ${object}" >&2
  32. exit 1
  33. fi
  34. done
  35. # Create a lib temporarily to dump symbols from.
  36. # It's just much easier to do it this way
  37. libname=$(mktemp -u "library").lib
  38. trap 'rm -f -- $libname' EXIT
  39. lib -out:${libname} $@ >/dev/null
  40. if [ $? != 0 ]; then
  41. echo "Could not create temporary library." >&2
  42. exit 1
  43. fi
  44. IFS='
  45. '
  46. # Determine if we're building for x86 or x86_64 and
  47. # set the symbol prefix accordingly.
  48. prefix=""
  49. arch=$(dumpbin -headers ${libname} |
  50. tr '\t' ' ' |
  51. grep '^ \+.\+machine \+(.\+)' |
  52. head -1 |
  53. sed -e 's/^ \{1,\}.\{1,\} \{1,\}machine \{1,\}(\(...\)).*/\1/')
  54. if [ "${arch}" = "x86" ]; then
  55. prefix="_"
  56. else
  57. if [ "${arch}" != "ARM" ] && [ "${arch}" != "x64" ]; then
  58. echo "Unknown machine type." >&2
  59. exit 1
  60. fi
  61. fi
  62. started=0
  63. regex="none"
  64. for line in $(cat ${vscript} | tr '\t' ' '); do
  65. # We only care about global symbols
  66. echo "${line}" | grep -q '^ \+global:'
  67. if [ $? = 0 ]; then
  68. started=1
  69. line=$(echo "${line}" | sed -e 's/^ \{1,\}global: *//')
  70. else
  71. echo "${line}" | grep -q '^ \+local:'
  72. if [ $? = 0 ]; then
  73. started=0
  74. fi
  75. fi
  76. if [ ${started} = 0 ]; then
  77. continue
  78. fi
  79. # Handle multiple symbols on one line
  80. IFS=';'
  81. # Work around stupid expansion to filenames
  82. line=$(echo "${line}" | sed -e 's/\*/.\\+/g')
  83. for exp in ${line}; do
  84. # Remove leading and trailing whitespace
  85. exp=$(echo "${exp}" | sed -e 's/^ *//' -e 's/ *$//')
  86. if [ "${regex}" = "none" ]; then
  87. regex="${exp}"
  88. else
  89. regex="${regex};${exp}"
  90. fi
  91. done
  92. IFS='
  93. '
  94. done
  95. dump=$(dumpbin -linkermember:1 ${libname})
  96. rm ${libname}
  97. IFS=';'
  98. list=""
  99. for exp in ${regex}; do
  100. list="${list}"'
  101. '$(echo "${dump}" |
  102. sed -e '/public symbols/,$!d' -e '/^ \{1,\}Summary/,$d' -e "s/ \{1,\}${prefix}/ /" -e 's/ \{1,\}/ /g' |
  103. tail -n +2 |
  104. cut -d' ' -f3 |
  105. grep "^${exp}" |
  106. sed -e 's/^/ /')
  107. done
  108. echo "EXPORTS"
  109. echo "${list}" | sort | uniq | tail -n +2