create-exports-NetworkManager.sh 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. #!/bin/bash
  2. set -e
  3. set -o pipefail
  4. die() {
  5. echo "$@"
  6. exit 1
  7. }
  8. # generates the linker version script src/NetworkManager.ver
  9. # by looking at the symbols needed by the device and settings
  10. # plugins. Note that this depends on how NetworkManager and
  11. # the plugins are build. For example, compiling without
  12. # --with-more-asserts will yield less symbols.
  13. #
  14. # _build re-builds NetworkManager with relevant compile time
  15. # options to yield the most symbols.
  16. _build() {
  17. git clean -fdx
  18. ./autogen.sh --enable-ld-gc --enable-ifcfg-rh --enable-ifupdown \
  19. --enable-ibft --enable-teamdctl --enable-wifi \
  20. --with-modem-manager-1 --with-ofono --with-more-asserts \
  21. --with-more-logging
  22. make -j20
  23. }
  24. _sort() {
  25. LANG=C sort -u
  26. }
  27. call_nm() {
  28. "${NM:-nm}" "$1" |
  29. sed -n 's/.* \([^ ]\) \([^ ]*\)$/\1 \2/p'
  30. }
  31. get_symbols_nm () {
  32. if [ -z "$from_meson" ]; then
  33. base=./src/.libs/libNetworkManager.a
  34. else
  35. base=./src/nm-full-symbols
  36. fi
  37. call_nm "$base" |
  38. sed -n 's/^[tTDGRBS] //p' |
  39. _sort
  40. }
  41. get_symbols_explict() {
  42. cat <<EOF | _sort
  43. _IO_stdin_used
  44. EOF
  45. }
  46. get_symbols_missing() {
  47. (for f in $(find ./src/settings/plugins/*/${libs} \
  48. ./src/devices/*/${libs} \
  49. ./src/ppp/${libs} -name '*.so'); do
  50. call_nm "$f" |
  51. sed -n 's/^\([U]\) \(\(nm_\|nmp_\|_nm\|NM\|_NM\|c_siphash_\).*\)$/\2/p'
  52. done) |
  53. _sort |
  54. grep -Fx -f <(get_symbols_explict) -v |
  55. grep -Fx -f <(get_symbols_nm)
  56. }
  57. pretty() {
  58. sed 's/.*/\t\0;/'
  59. }
  60. do_build() {
  61. do_update
  62. make
  63. }
  64. do_rebuild() {
  65. _build
  66. do_build
  67. }
  68. do_update() {
  69. do_generate > ./src/NetworkManager.ver
  70. }
  71. do_generate() {
  72. cat <<EOF
  73. # this file is generated by $0
  74. {
  75. global:
  76. $(get_symbols_missing | pretty)
  77. $(get_symbols_explict | pretty)
  78. local:
  79. *;
  80. };
  81. EOF
  82. }
  83. if [ -f "build.ninja" ]; then
  84. from_meson=1
  85. libs=
  86. else
  87. libs=.libs/
  88. fi
  89. test -f ./src/${libs}libNetworkManager.a || die "must be called from NetworkManager top build dir after building the tree"
  90. case "$1" in
  91. rebuild)
  92. [ -n "$from_meson" ] && die "can't do a build when called from meson"
  93. do_rebuild
  94. ;;
  95. build)
  96. [ -n "$from_meson" ] && die "can't do a build when called from meson"
  97. do_build
  98. ;;
  99. --called-from-build)
  100. if test -z "${NM_BUILD_NO_CREATE_EXPORTS+x}"; then
  101. do_update
  102. else
  103. if test -f "./src/NetworkManager.ver"; then
  104. touch ./src/NetworkManager.ver
  105. fi
  106. fi
  107. ;;
  108. update)
  109. do_update
  110. ;;
  111. *)
  112. do_generate
  113. ;;
  114. esac