From cbf71dbf5d7b62de3709c31c343e0ce672af5f61 Mon Sep 17 00:00:00 2001
From: Laurent Bigonville <bigon@bigon.be>
Date: Tue, 9 Jul 2019 14:00:53 +0200
Subject: [PATCH] Use pkg-config module names instead of listing the libraries

Fixes: #709
---
 configure.ac               | 1 +
 lib/libupsclient.pc.in     | 5 +++--
 m4/nut_check_libnss.m4     | 5 +++++
 m4/nut_check_libopenssl.m4 | 5 +++++
 4 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/configure.ac b/configure.ac
index ca5212050..0bf69f566 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1677,6 +1677,7 @@ AC_SUBST(TREE_VERSION)
 AC_SUBST(NUT_NETVERSION)
 AC_SUBST(LIBSSL_CFLAGS)
 AC_SUBST(LIBSSL_LIBS)
+AC_SUBST(LIBSSL_REQUIRES)
 AC_SUBST(LIBGD_CFLAGS)
 AC_SUBST(LIBGD_LDFLAGS)
 AC_SUBST(LIBNETSNMP_CFLAGS)
diff --git a/lib/libupsclient.pc.in b/lib/libupsclient.pc.in
index 4ad31fbde..8efce4020 100644
--- a/lib/libupsclient.pc.in
+++ b/lib/libupsclient.pc.in
@@ -9,5 +9,6 @@ nutuser=@RUN_AS_USER@
 Name: libupsclient
 Description: UPS monitoring with Network UPS Tools
 Version: @PACKAGE_VERSION@
-Libs: -L${libdir} -lupsclient @LIBSSL_LIBS@
-Cflags: -I${includedir} @LIBSSL_CFLAGS@
+Libs: -L${libdir} -lupsclient
+Cflags: -I${includedir}
+Requires: @LIBSSL_REQUIRES@
diff --git a/m4/nut_check_libnss.m4 b/m4/nut_check_libnss.m4
index 7c235318d..7fed727d3 100644
--- a/m4/nut_check_libnss.m4
+++ b/m4/nut_check_libnss.m4
@@ -11,16 +11,19 @@ if test -z "${nut_have_libnss_seen}"; then
 	dnl save CFLAGS and LIBS
 	CFLAGS_ORIG="${CFLAGS}"
 	LIBS_ORIG="${LIBS}"
+	REQUIRES_ORIG="${REQUIRES}"
 
 	AC_MSG_CHECKING(for Mozilla NSS version via pkg-config)
 	NSS_VERSION="`pkg-config --silence-errors --modversion nss 2>/dev/null`"
 	if test "$?" = "0" -a -n "${NSS_VERSION}"; then
 		CFLAGS="`pkg-config --silence-errors --cflags nss 2>/dev/null`"
 		LIBS="`pkg-config --silence-errors --libs nss 2>/dev/null`"
+		REQUIRES="nss"
 	else
 		NSS_VERSION="none"
 		CFLAGS=""
 		LIBS="-lnss3 -lnssutil3 -lsmime3 -lssl3 -lplds4 -lplc4 -lnspr4"
+		REQUIRES="nss"
 	fi
 	AC_MSG_RESULT(${NSS_VERSION} found)
 
@@ -67,10 +70,12 @@ if test -z "${nut_have_libnss_seen}"; then
 		AC_DEFINE(WITH_NSS, 1, [Define to enable SSL support using Mozilla NSS])
 		LIBSSL_CFLAGS="${CFLAGS}"
 		LIBSSL_LIBS="${LIBS}"
+		LIBSSL_REQUIRES="${REQUIRES}"
 	fi
 
 	dnl restore original CFLAGS and LIBS
 	CFLAGS="${CFLAGS_ORIG}"
 	LIBS="${LIBS_ORIG}"
+	REQUIRES="${REQUIRES_ORIG}"
 fi
 ])
diff --git a/m4/nut_check_libopenssl.m4 b/m4/nut_check_libopenssl.m4
index 7eb401cd9..d9e9e0237 100644
--- a/m4/nut_check_libopenssl.m4
+++ b/m4/nut_check_libopenssl.m4
@@ -12,16 +12,19 @@ if test -z "${nut_have_libopenssl_seen}"; then
 	dnl save CFLAGS and LIBS
 	CFLAGS_ORIG="${CFLAGS}"
 	LIBS_ORIG="${LIBS}"
+	REQUIRES_ORIG="${REQUIRES}"
 
 	AC_MSG_CHECKING(for OpenSSL version via pkg-config)
 	OPENSSL_VERSION="`pkg-config --silence-errors --modversion openssl 2>/dev/null`"
 	if test "$?" = "0" -a -n "${OPENSSL_VERSION}"; then
 		CFLAGS="`pkg-config --silence-errors --cflags openssl 2>/dev/null`"
 		LIBS="`pkg-config --silence-errors --libs openssl 2>/dev/null`"
+		REQUIRES="openssl"
 	else
 		OPENSSL_VERSION="none"
 		CFLAGS=""
 		LIBS="-lssl -lcrypto"
+		REQUIRES="openssl"
 	fi
 	AC_MSG_RESULT(${OPENSSL_VERSION} found)
 
@@ -67,10 +70,12 @@ if test -z "${nut_have_libopenssl_seen}"; then
 		AC_DEFINE(WITH_OPENSSL, 1, [Define to enable SSL support using OpenSSL])
 		LIBSSL_CFLAGS="${CFLAGS}"
 		LIBSSL_LIBS="${LIBS}"
+		LIBSSL_REQUIRES="${REQUIRES}"
 	fi
 
 	dnl restore original CFLAGS and LIBS
 	CFLAGS="${CFLAGS_ORIG}"
 	LIBS="${LIBS_ORIG}"
+	REQUIRES="${REQUIRES_ORIG}"
 fi
 ])
