make_libdeps.sh revision 128184
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: head/tools/make_libdeps.sh 128184 2004-04-13 11:06:20Z ru $ 2894541Sru 2994541Sruexport PATH=/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 4094541Sru usr.sbin/pcvt/keycap 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' 5094541Sru -e's;-lm!;lib/msun;g' 5197388Sru -e's;-l(supc\+\+)!;gnu/lib/lib\1;g' 5294541Sru -e's;-l(asn1|gssapi|krb5|roken)!;kerberos5/lib/lib\1;g' 53128184Sru -e's;-l(crypto|ssh|ssl)!;secure/lib/lib\1;g' 5494541Sru -e's;-l([^!]+)!;lib/lib\1;g' 5594541Sru" 5694541Sru 5794541Sru# Generate interdependencies between libraries. 5894541Sru# 5994541Srugenlibdepends() 6094541Sru{ 6194541Sru ( 6294541Sru cd ${USRSRC} 6394541Sru find ${LIBS} -mindepth 1 -name Makefile | 6494541Sru xargs grep -l 'bsd\.lib\.mk' | 6594541Sru while read makefile; do 6694541Sru libdir=$(dirname ${makefile}) 6794541Sru deps=$( 6894541Sru cd ${libdir} 6994541Sru make -V LDADD 7094541Sru ) 7194541Sru if [ "${deps}" ]; then 7294541Sru echo ${libdir}"${FS}"$( 7394541Sru echo ${deps} | 7494541Sru eval ${SED_FILTER} 7594541Sru ) 7694541Sru fi 7794541Sru done 7894541Sru ) 7994541Sru} 8094541Sru 8194541Srumain() 8294541Sru{ 8394541Sru if [ ! -f ${LIBDEPENDS} ]; then 8494541Sru genlibdepends >${LIBDEPENDS} 8594541Sru fi 8694541Sru 8794541Sru prebuild_libs=$( 8894541Sru awk -F"${FS}" '{ print $2 }' ${LIBDEPENDS} |rs 0 1 |sort -u 8994541Sru ) 9094541Sru echo "Libraries with dependents:" 9194541Sru echo 9294541Sru echo ${prebuild_libs} | 9394541Sru rs 0 1 9494541Sru echo 9594541Sru 9694541Sru echo "List of interdependencies:" 9794541Sru echo 9894541Sru for lib in ${prebuild_libs}; do 9994541Sru grep "^${lib}${FS}" ${LIBDEPENDS} || true 10094541Sru done | 10194541Sru awk -F"${FS}" '{ 10294541Sru if ($2 in dependents) 10394541Sru dependents[$2]=dependents[$2]" "$1 10494541Sru else 10594541Sru dependents[$2]=$1 10694541Sru } 10794541Sru END { 10894541Sru for (lib in dependents) 10994541Sru print dependents[lib]": " lib 11094541Sru }' | 11194541Sru sort 11294541Sru 11394541Sru exit 0 11494541Sru} 11594541Sru 11694541Srumain 117