Skip to content

Commit

Permalink
configure: trust pkg-config when it's used for zlib
Browse files Browse the repository at this point in the history
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 curl#11778
  • Loading branch information
dfandrich committed Sep 1, 2023
1 parent 280f900 commit a20fbb0
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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])
Expand All @@ -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"
Expand Down

0 comments on commit a20fbb0

Please sign in to comment.