summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile.inc1102
-rw-r--r--tools/make_libdeps.sh117
2 files changed, 168 insertions, 51 deletions
diff --git a/Makefile.inc1 b/Makefile.inc1
index 38e2c97c360d..b8fd9d6780a1 100644
--- a/Makefile.inc1
+++ b/Makefile.inc1
@@ -717,71 +717,67 @@ includes:
#
# libraries - build all libraries, and install them under ${DESTDIR}.
#
-# The following dependencies exist between the libraries:
-#
-# lib*: csu libgcc_pic
-# libatm: libmd
-# libcam: libsbuf
-# libcrypt: libmd
-# libdevstat: libkvm
-# libdialog: libncurses
-# libedit: libncurses
-# libg++: msun
-# libkrb: libcrypt
-# libopie: libmd
-# libpam: libcom_err libcrypt libcrypto libkrb libopie libradius \
-# librpcsvc libtacplus libutil libz libssh
-# libradius: libmd
-# libreadline: libncurses
-# libssh: libcrypto libz
-# libstc++: msun
-# libtacplus: libmd
-#
-# Across directories this comes down to (rougly):
-#
-# gnu/lib: lib/msun lib/libncurses
-# kerberosIV/lib kerberos5/lib: lib/libcrypt
-# lib/libpam: secure/lib/libcrypto kerberosIV/lib/libkrb \
-# secure/lib/libssh lib/libz
-# secure/lib: secure/lib/libcrypto lib/libmd lib/libz
+# The list of libraries with dependents (${_prebuild_libs}) and their
+# interdependencies (__L) are built automatically by the
+# ${.CURDIR}/tools/make_libdeps.sh script.
#
+libraries:
+ cd ${.CURDIR}; \
+ ${MAKE} -f Makefile.inc1 _startup_libs; \
+ ${MAKE} -f Makefile.inc1 _prebuild_libs; \
+ ${MAKE} -f Makefile.inc1 _generic_libs;
+
.if exists(${.CURDIR}/lib/csu/${MACHINE_ARCH}.pcc)
-_csu= lib/csu/${MACHINE_ARCH}.pcc
+_startup_libs= lib/csu/${MACHINE_ARCH}.pcc
.elif ${MACHINE_ARCH} == "i386" && ${OBJFORMAT} == "elf"
-_csu= lib/csu/i386-elf
+_startup_libs= lib/csu/i386-elf
.else
-_csu= lib/csu/${MACHINE_ARCH}
+_startup_libs= lib/csu/${MACHINE_ARCH}
.endif
+_startup_libs+= gnu/lib/csu gnu/lib/libgcc
-.if exists(${.CURDIR}/secure) && !defined(NOCRYPT) && !defined(NOSECURE)
-_secure_lib= secure/lib
-.if exists(${.CURDIR}/secure/lib/libcrypto)
-_libcrypto= secure/lib/libcrypto
-.endif
-.endif
+_prebuild_libs= lib/libcom_err lib/libcrypt lib/libkvm lib/libmd \
+ lib/libncurses lib/libopie lib/libradius lib/librpcsvc \
+ lib/libsbuf lib/libtacplus lib/libutil lib/libz lib/msun
-.if !defined(NOCRYPT) && defined(MAKE_KERBEROS4)
-_kerberosIV_lib= kerberosIV/lib
-.endif
+lib/libopie__L lib/libradius__L lib/libtacplus__L: lib/libmd__L
+
+_generic_libs= lib gnu/lib
-.if !defined(NOCRYPT) && defined(MAKE_KERBEROS5)
-_kerberos5_lib= kerberos5/lib
+.if !defined(NOPERL) && !defined(NO_PERL)
+_generic_libs+= gnu/usr.bin/perl/libperl
.endif
-.if ${MACHINE_ARCH} == "i386"
-_libkeycap= usr.sbin/pcvt/keycap
+.if !defined(NOCRYPT)
+.if defined(MAKE_KERBEROS4)
+_prebuild_libs+= kerberosIV/lib/libkrb
+kerberosIV/lib/libkrb__L: lib/libcrypt__L
+_generic_libs+= kerberosIV/lib
+.endif
+.if defined(MAKE_KERBEROS5)
+_prebuild_libs+= kerberos5/lib/libasn1
+_prebuild_libs+= kerberos5/lib/libgssapi
+_prebuild_libs+= kerberos5/lib/libkrb5
+_prebuild_libs+= kerberos5/lib/libroken
+_generic_libs+= kerberos5/lib
+.endif
+.if !defined(NOSECURE)
+_prebuild_libs+= secure/lib/libcrypto
+.if !defined(NO_OPENSSH)
+_prebuild_libs+= secure/lib/libssh
+secure/lib/libssh__L: secure/lib/libcrypto__L lib/libz__L
.endif
+_generic_libs+= secure/lib
+.endif !defined(NOSECURE)
+.endif !defined(NOCRYPT)
-.if !defined(NOPERL) && !defined(NO_PERL)
-_libperl= gnu/usr.bin/perl/libperl
+_generic_libs+= usr.bin/lex/lib
+.if ${MACHINE_ARCH} == "i386"
+_generic_libs+= usr.sbin/pcvt/keycap
.endif
-libraries:
-.for _lib in ${_csu} gnu/lib/csu gnu/lib/libgcc lib/libmd lib/libcrypt \
- lib/libz ${_libcrypto} ${_secure_lib} ${_kerberosIV_lib} \
- ${_kerberos5_lib} lib/libcom_err lib/libkvm lib/msun lib/libncurses \
- lib/libopie lib/libradius lib/librpcsvc lib/libsbuf lib/libtacplus \
- lib/libutil lib gnu/lib ${_libperl} usr.bin/lex/lib ${_libkeycap}
+.for _lib in ${_startup_libs} ${_prebuild_libs} ${_generic_libs}
+${_lib}__L: .PHONY
.if exists(${.CURDIR}/${_lib})
cd ${.CURDIR}/${_lib}; \
${MAKE} depend; \
@@ -790,6 +786,10 @@ libraries:
.endif
.endfor
+_startup_libs: ${_startup_libs:S/$/__L/}
+_prebuild_libs: ${_prebuild_libs:S/$/__L/}
+_generic_libs: ${_generic_libs:S/$/__L/}
+
.for __target in clean cleandepend cleandir depend obj
.for entry in ${SUBDIR}
${entry}.${__target}__D: .PHONY
diff --git a/tools/make_libdeps.sh b/tools/make_libdeps.sh
new file mode 100644
index 000000000000..20f487036cd9
--- /dev/null
+++ b/tools/make_libdeps.sh
@@ -0,0 +1,117 @@
+#!/bin/sh -e
+#
+# Copyright (c) 2002 Ruslan Ermilov, The FreeBSD Project
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+# SUCH DAMAGE.
+#
+# $FreeBSD$
+
+export PATH=/usr/bin
+
+FS=': ' # internal field separator
+LIBDEPENDS=./_libdeps # intermediate output file
+USRSRC=${1:-/usr/src} # source root
+LIBS="
+ lib
+ gnu/lib
+ gnu/usr.bin/perl/libperl
+ kerberosIV/lib
+ kerberos5/lib
+ secure/lib
+ usr.bin/lex/lib
+ usr.sbin/pcvt/keycap
+" # where to scan for libraries
+
+# This sed(1) filter is used to convert -lfoo to path/to/libfoo.
+#
+SED_FILTER="
+sed -E
+ -e's; ;! ;g'
+ -e's;$;!;'
+ -e's;-lm!;lib/msun;g'
+ -e's;-l(krb)!;kerberosIV/lib/lib\1;g'
+ -e's;-l(asn1|gssapi|krb5|roken)!;kerberos5/lib/lib\1;g'
+ -e's;-l(crypto|ssh)!;secure/lib/lib\1;g'
+ -e's;-l([^!]+)!;lib/lib\1;g'
+"
+
+# Generate interdependencies between libraries.
+#
+genlibdepends()
+{
+ (
+ cd ${USRSRC}
+ find ${LIBS} -mindepth 1 -name Makefile |
+ xargs grep -l 'bsd\.lib\.mk' |
+ while read makefile; do
+ libdir=$(dirname ${makefile})
+ deps=$(
+ cd ${libdir}
+ make -V LDADD
+ )
+ if [ "${deps}" ]; then
+ echo ${libdir}"${FS}"$(
+ echo ${deps} |
+ eval ${SED_FILTER}
+ )
+ fi
+ done
+ )
+}
+
+main()
+{
+ if [ ! -f ${LIBDEPENDS} ]; then
+ genlibdepends >${LIBDEPENDS}
+ fi
+
+ prebuild_libs=$(
+ awk -F"${FS}" '{ print $2 }' ${LIBDEPENDS} |rs 0 1 |sort -u
+ )
+ echo "Libraries with dependents:"
+ echo
+ echo ${prebuild_libs} |
+ rs 0 1
+ echo
+
+ echo "List of interdependencies:"
+ echo
+ for lib in ${prebuild_libs}; do
+ grep "^${lib}${FS}" ${LIBDEPENDS} || true
+ done |
+ awk -F"${FS}" '{
+ if ($2 in dependents)
+ dependents[$2]=dependents[$2]" "$1
+ else
+ dependents[$2]=$1
+ }
+ END {
+ for (lib in dependents)
+ print dependents[lib]": " lib
+ }' |
+ sort
+
+ exit 0
+}
+
+main