From a20fbb0348239b74e77ca2af9bf7c976b20aeafc Mon Sep 17 00:00:00 2001 From: Dan Fandrich Date: Thu, 31 Aug 2023 16:06:02 -0700 Subject: [PATCH] configure: trust pkg-config when it's used for zlib The library flags retrieved from pkg-config were later thrown out and harded-coded, which negates the whole reason to use pkg-config. Also, previously, the assumption was made that --libs-only-l and --libs-only-L are the full decomposition of --libs, which is untrue and would not allow linking against a static zlib. The new approach is better in that it uses --libs, although only if --libs-only-l returns nothing. Bug: https://curl.se/mail/lib-2023-08/0081.html Reported-by: Randall Closes #11778 --- configure.ac | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/configure.ac b/configure.ac index e551514b42..0aa6daafd2 100644 --- a/configure.ac +++ b/configure.ac @@ -1351,9 +1351,14 @@ else CURL_CHECK_PKGCONFIG(zlib) if test "$PKGCONFIG" != "no" ; then - LIBS="`$PKGCONFIG --libs-only-l zlib` $LIBS" - LDFLAGS="$LDFLAGS `$PKGCONFIG --libs-only-L zlib`" - CPPFLAGS="$CPPFLAGS `$PKGCONFIG --cflags-only-I zlib`" + ZLIB_LIBS="`$PKGCONFIG --libs-only-l zlib`" + if test -n "$ZLIB_LIBS"; then + LDFLAGS="$LDFLAGS `$PKGCONFIG --libs-only-L zlib`" + else + ZLIB_LIBS="`$PKGCONFIG --libs zlib`" + fi + LIBS="$ZLIB_LIBS $LIBS" + CPPFLAGS="$CPPFLAGS `$PKGCONFIG --cflags zlib`" OPT_ZLIB="" HAVE_LIBZ="1" fi @@ -1366,7 +1371,8 @@ else AC_CHECK_LIB(z, inflateEnd, dnl libz found, set the variable [HAVE_LIBZ="1" - LIBS="-lz $LIBS"], + ZLIB_LIBS="-lz" + LIBS="$ZLIB_LIBS $LIBS"], dnl if no lib found, try /usr/local [OPT_ZLIB="/usr/local"]) fi @@ -1388,7 +1394,8 @@ else [ dnl the lib was found! HAVE_LIBZ="1" - LIBS="-lz $LIBS" + ZLIB_LIBS="-lz" + LIBS="$ZLIB_LIBS $LIBS" ], [ CPPFLAGS=$clean_CPPFLAGS LDFLAGS=$clean_LDFLAGS]) @@ -1407,20 +1414,20 @@ else CPPFLAGS=$clean_CPPFLAGS LDFLAGS=$clean_LDFLAGS LIBS=$clean_LIBS + ZLIB_LIBS="" elif test "$HAVE_LIBZ" != "1" && test "$HAVE_ZLIB_H" = "1" then AC_MSG_WARN([configure found only the libz header file, not the lib!]) CPPFLAGS=$clean_CPPFLAGS LDFLAGS=$clean_LDFLAGS LIBS=$clean_LIBS + ZLIB_LIBS="" elif test "$HAVE_LIBZ" = "1" && test "$HAVE_ZLIB_H" = "1" then dnl both header and lib were found! AC_SUBST(HAVE_LIBZ) AC_DEFINE(HAVE_LIBZ, 1, [if zlib is available]) - - ZLIB_LIBS="-lz" - LIBS="-lz $clean_LIBS" + LIBS="$ZLIB_LIBS $clean_LIBS" dnl replace 'HAVE_LIBZ' in the automake makefile.ams AMFIXLIB="1" -- 2.47.3