make_libdeps.sh revision 272461
1255577Sdes#!/bin/sh -e 2255577Sdes# 3255577Sdes# Copyright (c) 2002 Ruslan Ermilov, The FreeBSD Project 4255577Sdes# All rights reserved. 5255577Sdes# 6255577Sdes# Redistribution and use in source and binary forms, with or without 7255577Sdes# modification, are permitted provided that the following conditions 8255577Sdes# are met: 9255577Sdes# 1. Redistributions of source code must retain the above copyright 10255577Sdes# notice, this list of conditions and the following disclaimer. 11255577Sdes# 2. Redistributions in binary form must reproduce the above copyright 12255577Sdes# notice, this list of conditions and the following disclaimer in the 13255577Sdes# documentation and/or other materials provided with the distribution. 14255577Sdes# 15255577Sdes# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 16255577Sdes# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17255577Sdes# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18255577Sdes# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19255577Sdes# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20255577Sdes# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21255577Sdes# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22255577Sdes# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23255577Sdes# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24255577Sdes# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25255577Sdes# SUCH DAMAGE. 26255577Sdes# 27255577Sdes# $FreeBSD: releng/10.1/tools/make_libdeps.sh 256998 2013-10-23 18:07:07Z bdrewery $ 28255577Sdes 29255577Sdesexport PATH=/bin:/usr/bin 30255577Sdes 31255577SdesLC_ALL=C # make sort deterministic 32255577SdesFS=': ' # internal field separator 33255577SdesLIBDEPENDS=./_libdeps # intermediate output file 34255589SdesUSRSRC=${1:-/usr/src} # source root 35255577SdesLIBS=" 36255577Sdes lib 37255577Sdes gnu/lib 38255577Sdes kerberos5/lib 39255577Sdes secure/lib 40255577Sdes usr.bin/lex/lib 41255589Sdes cddl/lib 42255577Sdes" # where to scan for libraries 43255577Sdes 44255577Sdes# This sed(1) filter is used to convert -lfoo to path/to/libfoo. 45255577Sdes# 46255577SdesSED_FILTER=" 47255577Sdessed -E 48255577Sdes -e's; ;! ;g' 49255577Sdes -e's;$;!;' 50255577Sdes -e's;-lbsdxml!;lib/libexpat;g' 51255577Sdes -e's;-lpthread!;lib/libthr;g' 52255577Sdes -e's;-lm!;lib/msun;g' 53255577Sdes -e's;-l(ncurses|termcap)!;lib/ncurses/ncurses;g' 54255577Sdes -e's;-l(gcc)!;gnu/lib/lib\1;g' 55255577Sdes -e's;-lssp_nonshared!;gnu/lib/libssp/libssp_nonshared;g' 56255577Sdes -e's;-l(asn1|hdb|kdc|heimbase|heimntlm|heimsqlite|hx509|krb5|roken|wind)!;kerberos5/lib/lib\1;g' 57255577Sdes -e's;-l(crypto|ssh|ssl)!;secure/lib/lib\1;g' 58255577Sdes -e's;-l([^!]+)!;lib/lib\1;g' 59255577Sdes" 60255577Sdes 61255577Sdes# Generate interdependencies between libraries. 62255577Sdes# 63255577Sdesgenlibdepends() 64255577Sdes{ 65255577Sdes ( 66255577Sdes cd ${USRSRC} 67255577Sdes find -s ${LIBS} -mindepth 1 -name Makefile | 68255577Sdes xargs grep -l 'bsd\.lib\.mk' | 69255577Sdes while read makefile; do 70255577Sdes libdir=$(dirname ${makefile}) 71255577Sdes deps=$( 72255577Sdes cd ${libdir} 73255577Sdes make -m ${USRSRC}/share/mk -V LDADD 74 ) 75 if [ "${deps}" ]; then 76 echo ${libdir}"${FS}"$( 77 echo ${deps} | 78 eval ${SED_FILTER} 79 ) 80 fi 81 done 82 ) 83} 84 85main() 86{ 87 if [ ! -f ${LIBDEPENDS} ]; then 88 genlibdepends >${LIBDEPENDS} 89 fi 90 91 prebuild_libs=$( 92 awk -F"${FS}" '{ print $2 }' ${LIBDEPENDS} |rs 0 1 |sort -u 93 ) 94 echo "Libraries with dependents:" 95 echo 96 echo ${prebuild_libs} | 97 rs 0 1 98 echo 99 100 echo "List of interdependencies:" 101 echo 102 for lib in ${prebuild_libs}; do 103 grep "^${lib}${FS}" ${LIBDEPENDS} || true 104 done | 105 awk -F"${FS}" '{ 106 if ($2 in dependents) 107 dependents[$2]=dependents[$2]" "$1 108 else 109 dependents[$2]=$1 110 } 111 END { 112 for (lib in dependents) 113 print dependents[lib]": " lib 114 }' | 115 sort 116 117 exit 0 118} 119 120main 121