Commit a4e0db2b9773d28e2e1601f5e6dc77b7bc2df60b

Guillem Jover 2021-02-09T06:04:38

build: Use a single variable to track libraries to link against Using various variables means we have to keep these in sync in various places. Just use a single variable that we can use anywhere where this is needed.

diff --git a/configure.ac b/configure.ac
index 7afc7af..3281efb 100644
--- a/configure.ac
+++ b/configure.ac
@@ -67,6 +67,7 @@ saved_LIBS="$LIBS"
 AC_SEARCH_LIBS([MD5Update], [md], [
   AS_IF([test "x$ac_cv_search_MD5Update" != "xnone required"], [
     MD_LIBS="$ac_cv_search_MD5Update"
+    LIBBSD_LIBS="$LIBBSD_LIBS $ac_cv_search_MD5Update"
   ])
 ], [
   AC_MSG_ERROR([cannot find required MD5 functions in libc or libmd])
@@ -74,6 +75,7 @@ AC_SEARCH_LIBS([MD5Update], [md], [
 AC_SEARCH_LIBS([SHA512Update], [md], [
   AS_IF([test "x$ac_cv_search_SHA512Update" != "xnone required"], [
     MD_LIBS="$ac_cv_search_SHA512Update"
+    LIBBSD_LIBS="$LIBBSD_LIBS $ac_cv_search_SHA512Update"
   ])
 ], [
   AC_MSG_ERROR([cannot find required SHA-2 functions in libc or libmd])
@@ -88,10 +90,9 @@ AS_CASE([$host_os],
     saved_LIBS="$LIBS"
     AC_SEARCH_LIBS([clock_gettime], [rt], [
       AS_IF([test "x$ac_cv_search_clock_gettime" != "xnone required"], [
-        CLOCK_GETTIME_LIBS="$ac_cv_search_clock_gettime"
+        LIBBSD_LIBS="$LIBBSD_LIBS $ac_cv_search_clock_gettime"
       ])
     ])
-    AC_SUBST([CLOCK_GETTIME_LIBS])
     LIBS="$saved_LIBS"
   ],
   [*-musl*], [
@@ -199,8 +200,7 @@ AC_LINK_IFELSE(
 	[AC_DEFINE([HAVE___REGISTER_ATFORK], [1],
 	           [Define to 1 if you have __register_atfork])
 	 AC_MSG_RESULT([yes])],
-	[ARC4RANDOM_ATFORK_LIBS="-pthread"
-	 AC_SUBST([ARC4RANDOM_ATFORK_LIBS])
+	[LIBBSD_LIBS="$LIBBSD_LIBS -pthread"
 	 AC_MSG_RESULT([no])
 	])
 
@@ -209,6 +209,8 @@ AC_CHECK_FUNCS([clearenv dirfd fopencookie __fpurge \
                 pstat_getproc sysconf])
 AM_CONDITIONAL([HAVE_GETENTROPY], [test "x$ac_cv_func_getentropy" = "xtrue"])
 
+AC_SUBST([LIBBSD_LIBS])
+
 AC_CONFIG_FILES([
 	Makefile
 	include/Makefile
diff --git a/src/Makefile.am b/src/Makefile.am
index 48fb1fa..7ef2013 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -52,9 +52,7 @@ libbsd_la_DEPENDENCIES = \
 	$(libbsd_la_included_sources) \
 	libbsd.map
 libbsd_la_LIBADD = \
-	$(MD_LIBS) \
-	$(CLOCK_GETTIME_LIBS) \
-	$(ARC4RANDOM_ATFORK_LIBS) \
+	$(LIBBSD_LIBS) \
 	$(nil)
 libbsd_la_LDFLAGS = \
 	-version-number $(LIBBSD_ABI)