makedef 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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. if [ -n "$AR" ]; then
  40. $AR rcs ${libname} $@ >/dev/null
  41. else
  42. lib.exe -out:${libname} $@ >/dev/null
  43. fi
  44. if [ $? != 0 ]; then
  45. echo "Could not create temporary library." >&2
  46. exit 1
  47. fi
  48. IFS='
  49. '
  50. prefix="$EXTERN_PREFIX"
  51. started=0
  52. regex="none"
  53. for line in $(cat ${vscript} | tr '\t' ' '); do
  54. # We only care about global symbols
  55. echo "${line}" | grep -q '^ \+global:'
  56. if [ $? = 0 ]; then
  57. started=1
  58. line=$(echo "${line}" | sed -e 's/^ \{1,\}global: *//')
  59. else
  60. echo "${line}" | grep -q '^ \+local:'
  61. if [ $? = 0 ]; then
  62. started=0
  63. fi
  64. fi
  65. if [ ${started} = 0 ]; then
  66. continue
  67. fi
  68. # Handle multiple symbols on one line
  69. IFS=';'
  70. # Work around stupid expansion to filenames
  71. line=$(echo "${line}" | sed -e 's/\*/.\\+/g')
  72. for exp in ${line}; do
  73. # Remove leading and trailing whitespace
  74. exp=$(echo "${exp}" | sed -e 's/^ *//' -e 's/ *$//')
  75. if [ "${regex}" = "none" ]; then
  76. regex="${exp}"
  77. else
  78. regex="${regex};${exp}"
  79. fi
  80. done
  81. IFS='
  82. '
  83. done
  84. if [ -n "$NM" ]; then
  85. # Use eval, since NM="nm -g"
  86. dump=$(eval "$NM --defined-only -g ${libname}" |
  87. grep -v : |
  88. grep -v ^$ |
  89. cut -d' ' -f3 |
  90. sed -e "s/^${prefix}//")
  91. else
  92. dump=$(dumpbin.exe -linkermember:1 ${libname} |
  93. sed -e '/public symbols/,$!d' -e '/^ \{1,\}Summary/,$d' -e "s/ \{1,\}${prefix}/ /" -e 's/ \{1,\}/ /g' |
  94. tail -n +2 |
  95. cut -d' ' -f3)
  96. fi
  97. rm ${libname}
  98. IFS=';'
  99. list=""
  100. for exp in ${regex}; do
  101. list="${list}"'
  102. '$(echo "${dump}" |
  103. grep "^${exp}" |
  104. sed -e 's/^/ /')
  105. done
  106. echo "EXPORTS"
  107. echo "${list}" | sort | uniq | tail -n +2