194541Sru#!/bin/sh -e 294541Sru# 394541Sru# Copyright (c) 2002 Ruslan Ermilov, The FreeBSD Project 494541Sru# All rights reserved. 594541Sru# 694541Sru# Redistribution and use in source and binary forms, with or without 794541Sru# modification, are permitted provided that the following conditions 894541Sru# are met: 994541Sru# 1. Redistributions of source code must retain the above copyright 1094541Sru# notice, this list of conditions and the following disclaimer. 1194541Sru# 2. Redistributions in binary form must reproduce the above copyright 1294541Sru# notice, this list of conditions and the following disclaimer in the 1394541Sru# documentation and/or other materials provided with the distribution. 1494541Sru# 1594541Sru# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 1694541Sru# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1794541Sru# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1894541Sru# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 1994541Sru# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2094541Sru# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2194541Sru# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2294541Sru# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2394541Sru# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2494541Sru# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2594541Sru# SUCH DAMAGE. 2694541Sru# 2794541Sru# $FreeBSD$ 2894541Sru 29172400Sruexport PATH=/bin:/usr/bin 3094541Sru 3194541SruFS=': ' # internal field separator 3294541SruLIBDEPENDS=./_libdeps # intermediate output file 3394541SruUSRSRC=${1:-/usr/src} # source root 3494541SruLIBS=" 3594541Sru lib 3694541Sru gnu/lib 3794541Sru kerberos5/lib 3894541Sru secure/lib 3994541Sru usr.bin/lex/lib 40172400Sru cddl/lib 4194541Sru" # where to scan for libraries 4294541Sru 4394541Sru# This sed(1) filter is used to convert -lfoo to path/to/libfoo. 4494541Sru# 4594541SruSED_FILTER=" 4694541Srused -E 4794541Sru -e's; ;! ;g' 4894541Sru -e's;$;!;' 49115122Sru -e's;-lbsdxml!;lib/libexpat;g' 50202969Sru -e's;-lpthread!;lib/libthr;g' 5194541Sru -e's;-lm!;lib/msun;g' 52202969Sru -e's;-l(ncurses|termcap)!;lib/ncurses/ncurses;g' 53202969Sru -e's;-l(gcc)!;gnu/lib/lib\1;g' 54202969Sru -e's;-lssp_nonshared!;gnu/lib/libssp/libssp_nonshared;g' 55225811Sstas -e's;-l(asn1|hdb|heimntlm|hx509|krb5|roken)!;kerberos5/lib/lib\1;g' 56128184Sru -e's;-l(crypto|ssh|ssl)!;secure/lib/lib\1;g' 5794541Sru -e's;-l([^!]+)!;lib/lib\1;g' 5894541Sru" 5994541Sru 6094541Sru# Generate interdependencies between libraries. 6194541Sru# 6294541Srugenlibdepends() 6394541Sru{ 6494541Sru ( 6594541Sru cd ${USRSRC} 6694541Sru find ${LIBS} -mindepth 1 -name Makefile | 6794541Sru xargs grep -l 'bsd\.lib\.mk' | 6894541Sru while read makefile; do 6994541Sru libdir=$(dirname ${makefile}) 7094541Sru deps=$( 7194541Sru cd ${libdir} 72164581Sdelphij make -m ${USRSRC}/share/mk -V LDADD 7394541Sru ) 7494541Sru if [ "${deps}" ]; then 7594541Sru echo ${libdir}"${FS}"$( 7694541Sru echo ${deps} | 7794541Sru eval ${SED_FILTER} 7894541Sru ) 7994541Sru fi 8094541Sru done 8194541Sru ) 8294541Sru} 8394541Sru 8494541Srumain() 8594541Sru{ 8694541Sru if [ ! -f ${LIBDEPENDS} ]; then 8794541Sru genlibdepends >${LIBDEPENDS} 8894541Sru fi 8994541Sru 9094541Sru prebuild_libs=$( 9194541Sru awk -F"${FS}" '{ print $2 }' ${LIBDEPENDS} |rs 0 1 |sort -u 9294541Sru ) 9394541Sru echo "Libraries with dependents:" 9494541Sru echo 9594541Sru echo ${prebuild_libs} | 9694541Sru rs 0 1 9794541Sru echo 9894541Sru 9994541Sru echo "List of interdependencies:" 10094541Sru echo 10194541Sru for lib in ${prebuild_libs}; do 10294541Sru grep "^${lib}${FS}" ${LIBDEPENDS} || true 10394541Sru done | 10494541Sru awk -F"${FS}" '{ 10594541Sru if ($2 in dependents) 10694541Sru dependents[$2]=dependents[$2]" "$1 10794541Sru else 10894541Sru dependents[$2]=$1 10994541Sru } 11094541Sru END { 11194541Sru for (lib in dependents) 11294541Sru print dependents[lib]": " lib 11394541Sru }' | 11494541Sru sort 11594541Sru 11694541Sru exit 0 11794541Sru} 11894541Sru 11994541Srumain 120