From owner-svn-src-head@freebsd.org Thu Nov 16 15:26:40 2017 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id B87AEDE111B; Thu, 16 Nov 2017 15:26:40 +0000 (UTC) (envelope-from hselasky@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 9028C7E8FD; Thu, 16 Nov 2017 15:26:40 +0000 (UTC) (envelope-from hselasky@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id vAGFQdEs064442; Thu, 16 Nov 2017 15:26:39 GMT (envelope-from hselasky@FreeBSD.org) Received: (from hselasky@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id vAGFQdLO064441; Thu, 16 Nov 2017 15:26:39 GMT (envelope-from hselasky@FreeBSD.org) Message-Id: <201711161526.vAGFQdLO064441@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: hselasky set sender to hselasky@FreeBSD.org using -f From: Hans Petter Selasky Date: Thu, 16 Nov 2017 15:26:39 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r325897 - head/tools X-SVN-Group: head X-SVN-Commit-Author: hselasky X-SVN-Commit-Paths: head/tools X-SVN-Commit-Revision: 325897 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.25 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 16 Nov 2017 15:26:40 -0000 Author: hselasky Date: Thu Nov 16 15:26:39 2017 New Revision: 325897 URL: https://svnweb.freebsd.org/changeset/base/325897 Log: Improve the library dependencies helper script in src/tools. Implement double pass of the relevant Makefiles. First make a list of library names and directories and then scan for all the dependencies. Spaces in directories in the source tree are not supported. This avoids using hardcoded mappings between the library name and the directory containing the library Makefile. Add support for scanning contrib/ofed . Bail out on any errors. Sponsored by: Mellanox Technologies MFC after: 1 week Modified: head/tools/make_libdeps.sh Modified: head/tools/make_libdeps.sh ============================================================================== --- head/tools/make_libdeps.sh Thu Nov 16 15:18:36 2017 (r325896) +++ head/tools/make_libdeps.sh Thu Nov 16 15:26:39 2017 (r325897) @@ -28,9 +28,12 @@ export PATH=/bin:/usr/bin +set -e + LC_ALL=C # make sort deterministic FS=': ' # internal field separator LIBDEPENDS=./_libdeps # intermediate output file +LIBDIRS=./_libdirs # intermediate output file USRSRC=${1:-/usr/src} # source root LIBS=" lib @@ -39,44 +42,74 @@ LIBS=" secure/lib usr.bin/lex/lib cddl/lib + contrib/ofed " # 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;-lbsdxml!;lib/libexpat;g' - -e's;-lpthread!;lib/libthr;g' - -e's;-lm!;lib/msun;g' - -e's;-l(ncurses|termcap)!;lib/ncurses/ncurses;g' - -e's;-l(gcc)!;gnu/lib/lib\1;g' - -e's;-lssp_nonshared!;gnu/lib/libssp/libssp_nonshared;g' - -e's;-l(asn1|hdb|kdc|heimbase|heimntlm|heimsqlite|hx509|krb5|roken|wind)!;kerberos5/lib/lib\1;g' - -e's;-l(crypto|ssh|ssl)!;secure/lib/lib\1;g' - -e's;-l([^!]+)!;lib/lib\1;g' -" +# convert -lfoo to foo +convert() +{ + sed -e "s/\-l//g" -e "s/pthread/thr/g" -e "s/ncurses.*/ncurses/g" +} + +# find library build directory given library name +findlibdir() +{ + while read NAME && read DIR + do + if [ "$NAME" = "$1" ]; then + echo "$DIR" + exit + fi + done + + # Should not happen + echo lib_not_found/lib$1 +} + +# find library build directories given one or more library names +resolvelibdirs() +{ + while read LIBNAME + do + cat $LIBDIRS | tr ' ' '\n' | findlibdir "$LIBNAME" + done +} + # Generate interdependencies between libraries. # genlibdepends() { ( + # Reset file + echo -n > $LIBDIRS + + # First pass - generate list of directories cd ${USRSRC} - find -s ${LIBS} -mindepth 1 -name Makefile | + find -s ${LIBS} -name Makefile | xargs grep -l 'bsd\.lib\.mk' | while read makefile; do libdir=$(dirname ${makefile}) + libname=$( + cd ${libdir} + make -m ${USRSRC}/share/mk WITH_OFED=YES -V LIB + ) + if [ "${libname}" ]; then + echo "${libname} ${libdir}" >> $LIBDIRS + fi + done + + # Second pass - generate dependencies + find -s ${LIBS} -name Makefile | + xargs grep -l 'bsd\.lib\.mk' | + while read makefile; do + libdir=$(dirname ${makefile}) deps=$( cd ${libdir} - make -m ${USRSRC}/share/mk -V LDADD + make -m ${USRSRC}/share/mk WITH_OFED=YES -V LDADD ) if [ "${deps}" ]; then - echo ${libdir}"${FS}"$( - echo ${deps} | - eval ${SED_FILTER} - ) + echo ${libdir}"${FS}"$(echo ${deps} | tr ' ' '\n' | convert | resolvelibdirs) fi done )