make_libdeps.sh revision 164581
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 164581 2006-11-24 09:07:26Z delphij $ 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" # where to scan for libraries 4194541Sru 4294541Sru# This sed(1) filter is used to convert -lfoo to path/to/libfoo. 4394541Sru# 4494541SruSED_FILTER=" 4594541Srused -E 4694541Sru -e's; ;! ;g' 4794541Sru -e's;$;!;' 48115122Sru -e's;-lbsdxml!;lib/libexpat;g' 4994541Sru -e's;-lm!;lib/msun;g' 5097388Sru -e's;-l(supc\+\+)!;gnu/lib/lib\1;g' 51153838Sdfr -e's;-l(asn1|krb5|roken)!;kerberos5/lib/lib\1;g' 52128184Sru -e's;-l(crypto|ssh|ssl)!;secure/lib/lib\1;g' 5394541Sru -e's;-l([^!]+)!;lib/lib\1;g' 5494541Sru" 5594541Sru 5694541Sru# Generate interdependencies between libraries. 5794541Sru# 5894541Srugenlibdepends() 5994541Sru{ 6094541Sru ( 6194541Sru cd ${USRSRC} 6294541Sru find ${LIBS} -mindepth 1 -name Makefile | 6394541Sru xargs grep -l 'bsd\.lib\.mk' | 6494541Sru while read makefile; do 6594541Sru libdir=$(dirname ${makefile}) 6694541Sru deps=$( 6794541Sru cd ${libdir} 68164581Sdelphij make -m ${USRSRC}/share/mk -V LDADD 6994541Sru ) 7094541Sru if [ "${deps}" ]; then 7194541Sru echo ${libdir}"${FS}"$( 7294541Sru echo ${deps} | 7394541Sru eval ${SED_FILTER} 7494541Sru ) 7594541Sru fi 7694541Sru done 7794541Sru ) 7894541Sru} 7994541Sru 8094541Srumain() 8194541Sru{ 8294541Sru if [ ! -f ${LIBDEPENDS} ]; then 8394541Sru genlibdepends >${LIBDEPENDS} 8494541Sru fi 8594541Sru 8694541Sru prebuild_libs=$( 8794541Sru awk -F"${FS}" '{ print $2 }' ${LIBDEPENDS} |rs 0 1 |sort -u 8894541Sru ) 8994541Sru echo "Libraries with dependents:" 9094541Sru echo 9194541Sru echo ${prebuild_libs} | 9294541Sru rs 0 1 9394541Sru echo 9494541Sru 9594541Sru echo "List of interdependencies:" 9694541Sru echo 9794541Sru for lib in ${prebuild_libs}; do 9894541Sru grep "^${lib}${FS}" ${LIBDEPENDS} || true 9994541Sru done | 10094541Sru awk -F"${FS}" '{ 10194541Sru if ($2 in dependents) 10294541Sru dependents[$2]=dependents[$2]" "$1 10394541Sru else 10494541Sru dependents[$2]=$1 10594541Sru } 10694541Sru END { 10794541Sru for (lib in dependents) 10894541Sru print dependents[lib]": " lib 10994541Sru }' | 11094541Sru sort 11194541Sru 11294541Sru exit 0 11394541Sru} 11494541Sru 11594541Srumain 116