You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

156 lines
3.7KB

  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 -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. # Determine if we're building for x86 or x86_64 and
  51. # set the symbol prefix accordingly.
  52. prefix=""
  53. if [ -n "$NM" ]; then
  54. case $ARCH in
  55. *86)
  56. prefix="_"
  57. ;;
  58. *)
  59. ;;
  60. esac
  61. else
  62. arch=$(dumpbin -headers ${libname} |
  63. tr '\t' ' ' |
  64. grep '^ \+.\+machine \+(.\+)' |
  65. head -1 |
  66. sed -e 's/^ \{1,\}.\{1,\} \{1,\}machine \{1,\}(\(.\{3,5\}\)).*/\1/')
  67. if [ "${arch}" = "x86" ]; then
  68. prefix="_"
  69. else
  70. if [ "${arch}" != "ARM" ] && [ "${arch}" != "x64" ] && [ "${arch}" != "ARM64" ]; then
  71. echo "Unknown machine type." >&2
  72. exit 1
  73. fi
  74. fi
  75. fi
  76. started=0
  77. regex="none"
  78. for line in $(cat ${vscript} | tr '\t' ' '); do
  79. # We only care about global symbols
  80. echo "${line}" | grep -q '^ \+global:'
  81. if [ $? = 0 ]; then
  82. started=1
  83. line=$(echo "${line}" | sed -e 's/^ \{1,\}global: *//')
  84. else
  85. echo "${line}" | grep -q '^ \+local:'
  86. if [ $? = 0 ]; then
  87. started=0
  88. fi
  89. fi
  90. if [ ${started} = 0 ]; then
  91. continue
  92. fi
  93. # Handle multiple symbols on one line
  94. IFS=';'
  95. # Work around stupid expansion to filenames
  96. line=$(echo "${line}" | sed -e 's/\*/.\\+/g')
  97. for exp in ${line}; do
  98. # Remove leading and trailing whitespace
  99. exp=$(echo "${exp}" | sed -e 's/^ *//' -e 's/ *$//')
  100. if [ "${regex}" = "none" ]; then
  101. regex="${exp}"
  102. else
  103. regex="${regex};${exp}"
  104. fi
  105. done
  106. IFS='
  107. '
  108. done
  109. if [ -n "$NM" ]; then
  110. # Use eval, since NM="nm -g"
  111. dump=$(eval "$NM --defined-only -g ${libname}" |
  112. grep -v : |
  113. grep -v ^$ |
  114. cut -d' ' -f3 |
  115. sed -e "s/^${prefix}//")
  116. else
  117. dump=$(dumpbin -linkermember:1 ${libname} |
  118. sed -e '/public symbols/,$!d' -e '/^ \{1,\}Summary/,$d' -e "s/ \{1,\}${prefix}/ /" -e 's/ \{1,\}/ /g' |
  119. tail -n +2 |
  120. cut -d' ' -f3)
  121. fi
  122. rm ${libname}
  123. IFS=';'
  124. list=""
  125. for exp in ${regex}; do
  126. list="${list}"'
  127. '$(echo "${dump}" |
  128. grep "^${exp}" |
  129. sed -e 's/^/ /')
  130. done
  131. echo "EXPORTS"
  132. echo "${list}" | sort | uniq | tail -n +2