make_libdeps.sh revision 94541
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 94541 2002-04-12 19:46:25Z 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	gnu/usr.bin/perl/libperl
3894541Sru	kerberosIV/lib
3994541Sru	kerberos5/lib
4094541Sru	secure/lib
4194541Sru	usr.bin/lex/lib
4294541Sru	usr.sbin/pcvt/keycap
4394541Sru"				# where to scan for libraries
4494541Sru
4594541Sru# This sed(1) filter is used to convert -lfoo to path/to/libfoo.
4694541Sru#
4794541SruSED_FILTER="
4894541Srused -E
4994541Sru    -e's; ;! ;g'
5094541Sru    -e's;$;!;'
5194541Sru    -e's;-lm!;lib/msun;g'
5294541Sru    -e's;-l(krb)!;kerberosIV/lib/lib\1;g'
5394541Sru    -e's;-l(asn1|gssapi|krb5|roken)!;kerberos5/lib/lib\1;g'
5494541Sru    -e's;-l(crypto|ssh)!;secure/lib/lib\1;g'
5594541Sru    -e's;-l([^!]+)!;lib/lib\1;g'
5694541Sru"
5794541Sru
5894541Sru# Generate interdependencies between libraries.
5994541Sru#
6094541Srugenlibdepends()
6194541Sru{
6294541Sru	(
6394541Sru		cd ${USRSRC}
6494541Sru		find ${LIBS} -mindepth 1 -name Makefile |
6594541Sru		xargs grep -l 'bsd\.lib\.mk' |
6694541Sru		while read makefile; do
6794541Sru			libdir=$(dirname ${makefile})
6894541Sru			deps=$(
6994541Sru				cd ${libdir}
7094541Sru				make -V LDADD
7194541Sru			)
7294541Sru			if [ "${deps}" ]; then
7394541Sru				echo ${libdir}"${FS}"$(
7494541Sru					echo ${deps} |
7594541Sru					eval ${SED_FILTER}
7694541Sru				)
7794541Sru			fi
7894541Sru		done
7994541Sru	)
8094541Sru}
8194541Sru
8294541Srumain()
8394541Sru{
8494541Sru	if [ ! -f ${LIBDEPENDS} ]; then
8594541Sru		genlibdepends >${LIBDEPENDS}
8694541Sru	fi
8794541Sru
8894541Sru	prebuild_libs=$(
8994541Sru		awk -F"${FS}" '{ print $2 }' ${LIBDEPENDS} |rs 0 1 |sort -u
9094541Sru	)
9194541Sru	echo "Libraries with dependents:"
9294541Sru	echo
9394541Sru	echo ${prebuild_libs} |
9494541Sru	rs 0 1
9594541Sru	echo
9694541Sru
9794541Sru	echo "List of interdependencies:"
9894541Sru	echo
9994541Sru	for lib in ${prebuild_libs}; do
10094541Sru		grep "^${lib}${FS}" ${LIBDEPENDS} || true
10194541Sru	done |
10294541Sru	awk -F"${FS}" '{
10394541Sru		if ($2 in dependents)
10494541Sru			dependents[$2]=dependents[$2]" "$1
10594541Sru		else
10694541Sru			dependents[$2]=$1
10794541Sru	}
10894541Sru	END {
10994541Sru		for (lib in dependents)
11094541Sru			print dependents[lib]": " lib
11194541Sru	}' |
11294541Sru	sort
11394541Sru
11494541Sru	exit 0
11594541Sru}
11694541Sru
11794541Srumain
118