make_libdeps.sh revision 255454
11573Srgrimes#!/bin/sh -e
21573Srgrimes#
31573Srgrimes# Copyright (c) 2002 Ruslan Ermilov, The FreeBSD Project
41573Srgrimes# All rights reserved.
51573Srgrimes#
61573Srgrimes# Redistribution and use in source and binary forms, with or without
71573Srgrimes# modification, are permitted provided that the following conditions
81573Srgrimes# are met:
91573Srgrimes# 1. Redistributions of source code must retain the above copyright
101573Srgrimes#    notice, this list of conditions and the following disclaimer.
111573Srgrimes# 2. Redistributions in binary form must reproduce the above copyright
121573Srgrimes#    notice, this list of conditions and the following disclaimer in the
131573Srgrimes#    documentation and/or other materials provided with the distribution.
141573Srgrimes#
151573Srgrimes# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
161573Srgrimes# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
171573Srgrimes# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
181573Srgrimes# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
191573Srgrimes# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
201573Srgrimes# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
211573Srgrimes# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
221573Srgrimes# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
231573Srgrimes# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
241573Srgrimes# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
251573Srgrimes# SUCH DAMAGE.
261573Srgrimes#
271573Srgrimes# $FreeBSD: head/tools/make_libdeps.sh 255454 2013-09-10 18:34:38Z des $
281573Srgrimes
291573Srgrimesexport PATH=/bin:/usr/bin
301573Srgrimes
311573SrgrimesLC_ALL=C			# make sort deterministic
321573SrgrimesFS=': '				# internal field separator
331573SrgrimesLIBDEPENDS=./_libdeps		# intermediate output file
341573SrgrimesUSRSRC=${1:-/usr/src}		# source root
3590039SobrienLIBS="
3690039Sobrien	lib
371573Srgrimes	gnu/lib
3851872Smarcel	kerberos5/lib
391573Srgrimes	secure/lib
401573Srgrimes	usr.bin/lex/lib
4117141Sjkh	cddl/lib
4251872Smarcel"				# where to scan for libraries
431573Srgrimes
4451872Smarcel# This sed(1) filter is used to convert -lfoo to path/to/libfoo.
451573Srgrimes#
4651794SmarcelSED_FILTER="
4751872Smarcelsed -E
4851872Smarcel    -e's; ;! ;g'
4951872Smarcel    -e's;$;!;'
5051872Smarcel    -e's;-lbsdxml!;lib/libexpat;g'
5151872Smarcel    -e's;-lbsdyml!;lib/libyaml;g'
521573Srgrimes    -e's;-lpthread!;lib/libthr;g'
531573Srgrimes    -e's;-lm!;lib/msun;g'
541573Srgrimes    -e's;-l(ncurses|termcap)!;lib/ncurses/ncurses;g'
5517141Sjkh    -e's;-l(gcc)!;gnu/lib/lib\1;g'
5651872Smarcel    -e's;-lssp_nonshared!;gnu/lib/libssp/libssp_nonshared;g'
571573Srgrimes    -e's;-l(asn1|hdb|kdc|heimbase|heimntlm|heimsqlite|hx509|krb5|roken|wind)!;kerberos5/lib/lib\1;g'
5851872Smarcel    -e's;-l(crypto|ssh|ssl)!;secure/lib/lib\1;g'
591573Srgrimes    -e's;-l([^!]+)!;lib/lib\1;g'
6051794Smarcel"
6151872Smarcel
6251872Smarcel# Generate interdependencies between libraries.
6351872Smarcel#
6451872Smarcelgenlibdepends()
6551872Smarcel{
661573Srgrimes	(
671573Srgrimes		cd ${USRSRC}
681573Srgrimes		find -s ${LIBS} -mindepth 1 -name Makefile |
6917141Sjkh		xargs grep -l 'bsd\.lib\.mk' |
7051872Smarcel		while read makefile; do
711573Srgrimes			libdir=$(dirname ${makefile})
721573Srgrimes			deps=$(
7351872Smarcel				cd ${libdir}
7451794Smarcel				make -m ${USRSRC}/share/mk -V LDADD
7551872Smarcel			)
7651872Smarcel			if [ "${deps}" ]; then
771573Srgrimes				echo ${libdir}"${FS}"$(
781573Srgrimes					echo ${deps} |
791573Srgrimes					eval ${SED_FILTER}
8017141Sjkh				)
8151872Smarcel			fi
821573Srgrimes		done
831573Srgrimes	)
8451872Smarcel}
8551794Smarcel
8651872Smarcelmain()
8751872Smarcel{
881573Srgrimes	if [ ! -f ${LIBDEPENDS} ]; then
891573Srgrimes		genlibdepends >${LIBDEPENDS}
901573Srgrimes	fi
9117141Sjkh
921573Srgrimes	prebuild_libs=$(
931573Srgrimes		awk -F"${FS}" '{ print $2 }' ${LIBDEPENDS} |rs 0 1 |sort -u
941573Srgrimes	)
951573Srgrimes	echo "Libraries with dependents:"
9651794Smarcel	echo
9751794Smarcel	echo ${prebuild_libs} |
9851872Smarcel	rs 0 1
9951794Smarcel	echo
10051794Smarcel
10151794Smarcel	echo "List of interdependencies:"
1021573Srgrimes	echo
103	for lib in ${prebuild_libs}; do
104		grep "^${lib}${FS}" ${LIBDEPENDS} || true
105	done |
106	awk -F"${FS}" '{
107		if ($2 in dependents)
108			dependents[$2]=dependents[$2]" "$1
109		else
110			dependents[$2]=$1
111	}
112	END {
113		for (lib in dependents)
114			print dependents[lib]": " lib
115	}' |
116	sort
117
118	exit 0
119}
120
121main
122