#!/bin/sh -e1#2# Copyright (c) 2002 Ruslan Ermilov, The FreeBSD Project3# All rights reserved.4#5# Redistribution and use in source and binary forms, with or without6# modification, are permitted provided that the following conditions7# are met:8# 1. Redistributions of source code must retain the above copyright9# notice, this list of conditions and the following disclaimer.10# 2. Redistributions in binary form must reproduce the above copyright11# notice, this list of conditions and the following disclaimer in the12# documentation and/or other materials provided with the distribution.13#14# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND15# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE16# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE17# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE18# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL19# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS20# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)21# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT22# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY23# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF24# SUCH DAMAGE.25#2627export PATH=/bin:/usr/bin2829set -e3031LC_ALL=C # make sort deterministic32FS=': ' # internal field separator33LIBDEPENDS=./_libdeps # intermediate output file34LIBDIRS=./_libdirs # intermediate output file35USRSRC=${1:-/usr/src} # source root36LIBS="37lib38gnu/lib39kerberos5/lib40secure/lib41usr.bin/lex/lib42cddl/lib43contrib/ofed44" # where to scan for libraries454647# convert -lfoo to foo48convert()49{50sed -e "s/\-l//g" -e "s/pthread/thr/g" -e "s/ncurses.*/ncurses/g"51}5253# find library build directory given library name54findlibdir()55{56while read NAME && read DIR57do58if [ "$NAME" = "$1" ]; then59echo "$DIR"60exit61fi62done6364# Should not happen65echo lib_not_found/lib$166}6768# find library build directories given one or more library names69resolvelibdirs()70{71while read LIBNAME72do73cat $LIBDIRS | tr ' ' '\n' | findlibdir "$LIBNAME"74done75}7677# Generate interdependencies between libraries.78#79genlibdepends()80{81(82# Reset file83echo -n > $LIBDIRS8485# First pass - generate list of directories86cd ${USRSRC}87find -s ${LIBS} -name Makefile |88xargs grep -l 'bsd\.lib\.mk' |89while read makefile; do90libdir=$(dirname ${makefile})91libname=$(92cd ${libdir}93make -m ${USRSRC}/share/mk WITH_OFED=YES -V LIB94)95if [ "${libname}" ]; then96echo "${libname} ${libdir}" >> $LIBDIRS97fi98done99100# Second pass - generate dependencies101find -s ${LIBS} -name Makefile |102xargs grep -l 'bsd\.lib\.mk' |103while read makefile; do104libdir=$(dirname ${makefile})105deps=$(106cd ${libdir}107make -m ${USRSRC}/share/mk WITH_OFED=YES -V LDADD108)109if [ "${deps}" ]; then110echo ${libdir}"${FS}"$(echo ${deps} | tr ' ' '\n' | convert | resolvelibdirs)111fi112done113)114}115116main()117{118if [ ! -f ${LIBDEPENDS} ]; then119genlibdepends >${LIBDEPENDS}120fi121122prebuild_libs=$(123awk -F"${FS}" '{ print $2 }' ${LIBDEPENDS} | tr ' ' '\n' |124sort -u125)126echo "Libraries with dependents:"127echo128echo ${prebuild_libs} | tr ' ' '\n'129echo130131echo "List of interdependencies:"132echo133for lib in ${prebuild_libs}; do134grep "^${lib}${FS}" ${LIBDEPENDS} || true135done |136awk -F"${FS}" '{137if ($2 in dependents)138dependents[$2]=dependents[$2]" "$1139else140dependents[$2]=$1141}142END {143for (lib in dependents)144print dependents[lib]": " lib145}' |146sort147148exit 0149}150151main152153154