Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 16 Nov 2017 15:26:39 +0000 (UTC)
From:      Hans Petter Selasky <hselasky@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r325897 - head/tools
Message-ID:  <201711161526.vAGFQdLO064441@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
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
 	)



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201711161526.vAGFQdLO064441>