make_libdeps.sh 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. #!/bin/sh -e
  2. #
  3. # Copyright (c) 2002 Ruslan Ermilov, The FreeBSD Project
  4. # All rights reserved.
  5. #
  6. # Redistribution and use in source and binary forms, with or without
  7. # modification, are permitted provided that the following conditions
  8. # are met:
  9. # 1. Redistributions of source code must retain the above copyright
  10. # notice, this list of conditions and the following disclaimer.
  11. # 2. Redistributions in binary form must reproduce the above copyright
  12. # notice, this list of conditions and the following disclaimer in the
  13. # documentation and/or other materials provided with the distribution.
  14. #
  15. # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
  16. # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  17. # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  18. # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
  19. # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  20. # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  21. # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  22. # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  23. # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  24. # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  25. # SUCH DAMAGE.
  26. #
  27. export PATH=/bin:/usr/bin
  28. set -e
  29. LC_ALL=C # make sort deterministic
  30. FS=': ' # internal field separator
  31. LIBDEPENDS=./_libdeps # intermediate output file
  32. LIBDIRS=./_libdirs # intermediate output file
  33. USRSRC=${1:-/usr/src} # source root
  34. LIBS="
  35. lib
  36. gnu/lib
  37. kerberos5/lib
  38. secure/lib
  39. usr.bin/lex/lib
  40. cddl/lib
  41. contrib/ofed
  42. " # where to scan for libraries
  43. # convert -lfoo to foo
  44. convert()
  45. {
  46. sed -e "s/\-l//g" -e "s/pthread/thr/g" -e "s/ncurses.*/ncurses/g"
  47. }
  48. # find library build directory given library name
  49. findlibdir()
  50. {
  51. while read NAME && read DIR
  52. do
  53. if [ "$NAME" = "$1" ]; then
  54. echo "$DIR"
  55. exit
  56. fi
  57. done
  58. # Should not happen
  59. echo lib_not_found/lib$1
  60. }
  61. # find library build directories given one or more library names
  62. resolvelibdirs()
  63. {
  64. while read LIBNAME
  65. do
  66. cat $LIBDIRS | tr ' ' '\n' | findlibdir "$LIBNAME"
  67. done
  68. }
  69. # Generate interdependencies between libraries.
  70. #
  71. genlibdepends()
  72. {
  73. (
  74. # Reset file
  75. echo -n > $LIBDIRS
  76. # First pass - generate list of directories
  77. cd ${USRSRC}
  78. find -s ${LIBS} -name Makefile |
  79. xargs grep -l 'bsd\.lib\.mk' |
  80. while read makefile; do
  81. libdir=$(dirname ${makefile})
  82. libname=$(
  83. cd ${libdir}
  84. make -m ${USRSRC}/share/mk WITH_OFED=YES -V LIB
  85. )
  86. if [ "${libname}" ]; then
  87. echo "${libname} ${libdir}" >> $LIBDIRS
  88. fi
  89. done
  90. # Second pass - generate dependencies
  91. find -s ${LIBS} -name Makefile |
  92. xargs grep -l 'bsd\.lib\.mk' |
  93. while read makefile; do
  94. libdir=$(dirname ${makefile})
  95. deps=$(
  96. cd ${libdir}
  97. make -m ${USRSRC}/share/mk WITH_OFED=YES -V LDADD
  98. )
  99. if [ "${deps}" ]; then
  100. echo ${libdir}"${FS}"$(echo ${deps} | tr ' ' '\n' | convert | resolvelibdirs)
  101. fi
  102. done
  103. )
  104. }
  105. main()
  106. {
  107. if [ ! -f ${LIBDEPENDS} ]; then
  108. genlibdepends >${LIBDEPENDS}
  109. fi
  110. prebuild_libs=$(
  111. awk -F"${FS}" '{ print $2 }' ${LIBDEPENDS} | tr ' ' '\n' |
  112. sort -u
  113. )
  114. echo "Libraries with dependents:"
  115. echo
  116. echo ${prebuild_libs} | tr ' ' '\n'
  117. echo
  118. echo "List of interdependencies:"
  119. echo
  120. for lib in ${prebuild_libs}; do
  121. grep "^${lib}${FS}" ${LIBDEPENDS} || true
  122. done |
  123. awk -F"${FS}" '{
  124. if ($2 in dependents)
  125. dependents[$2]=dependents[$2]" "$1
  126. else
  127. dependents[$2]=$1
  128. }
  129. END {
  130. for (lib in dependents)
  131. print dependents[lib]": " lib
  132. }' |
  133. sort
  134. exit 0
  135. }
  136. main