Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 4 Dec 2017 09:53:03 +0000 (UTC)
From:      Hans Petter Selasky <hselasky@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org
Subject:   svn commit: r326520 - stable/11/tools
Message-ID:  <201712040953.vB49r3jY094573@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: hselasky
Date: Mon Dec  4 09:53:03 2017
New Revision: 326520
URL: https://svnweb.freebsd.org/changeset/base/326520

Log:
  MFC r325897:
  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

Modified:
  stable/11/tools/make_libdeps.sh
Directory Properties:
  stable/11/   (props changed)

Modified: stable/11/tools/make_libdeps.sh
==============================================================================
--- stable/11/tools/make_libdeps.sh	Mon Dec  4 09:51:08 2017	(r326519)
+++ stable/11/tools/make_libdeps.sh	Mon Dec  4 09:53:03 2017	(r326520)
@@ -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?201712040953.vB49r3jY094573>