erofs-utils: support zlib auto-detection
authorGao Xiang <hsiangkao@linux.alibaba.com>
Tue, 20 Feb 2024 17:16:59 +0000 (01:16 +0800)
committerGao Xiang <hsiangkao@linux.alibaba.com>
Tue, 20 Feb 2024 18:13:37 +0000 (02:13 +0800)
Fix explicit `--with-zlib` so that it errors out when zlib
is unavailable.

Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>
Link: https://lore.kernel.org/r/20240220171700.3693176-1-hsiangkao@linux.alibaba.com
configure.ac

index bf6e99fea631e77e6ba1fb3537b88743d70df6ef..cd14beb4d8956722c7fe52a69293bb3369423f83 100644 (file)
@@ -124,7 +124,7 @@ AC_ARG_ENABLE(lzma,
 
 AC_ARG_WITH(zlib,
    [AS_HELP_STRING([--without-zlib],
-      [Ignore presence of zlib inflate support @<:@default=enabled@:>@])])
+      [Ignore presence of zlib inflate support @<:@default=auto@:>@])])
 
 AC_ARG_WITH(libdeflate,
    [AS_HELP_STRING([--with-libdeflate],
@@ -426,18 +426,29 @@ if test "x$enable_lzma" = "xyes"; then
 fi
 
 # Configure zlib
+have_zlib="no"
 AS_IF([test "x$with_zlib" != "xno"], [
-  PKG_CHECK_MODULES([zlib], [zlib])
-  # Paranoia: don't trust the result reported by pkgconfig before trying out
-  saved_LIBS="$LIBS"
-  saved_CPPFLAGS=${CPPFLAGS}
-  CPPFLAGS="${zlib_CFLAGS} ${CPPFLAGS}"
-  LIBS="${zlib_LIBS} $LIBS"
-  AC_CHECK_LIB(z, inflate, [
-    have_zlib="yes" ], [
-    AC_MSG_ERROR([zlib doesn't work properly])])
-  LIBS="${saved_LIBS}"
-  CPPFLAGS="${saved_CPPFLAGS}"], [have_zlib="no"])
+  PKG_CHECK_MODULES([zlib], [zlib], [
+    # Paranoia: don't trust the result reported by pkgconfig before trying out
+    saved_LIBS="$LIBS"
+    saved_CPPFLAGS=${CPPFLAGS}
+    CPPFLAGS="${zlib_CFLAGS} ${CPPFLAGS}"
+    LIBS="${zlib_LIBS} $LIBS"
+    AC_CHECK_HEADERS([zlib.h],[
+      AC_CHECK_LIB(z, inflate, [], [
+        AC_MSG_ERROR([zlib doesn't work properly])])
+      AC_CHECK_DECL(inflate, [have_zlib="yes"],
+        [AC_MSG_ERROR([zlib doesn't work properly])], [[
+#include <zlib.h>
+      ]])
+    ])
+    LIBS="${saved_LIBS}"
+    CPPFLAGS="${saved_CPPFLAGS}"], [
+    AS_IF([test "x$with_zlib" = "xyes"], [
+      AC_MSG_ERROR([Cannot find proper zlib])
+    ])
+  ])
+])
 
 # Configure libdeflate
 AS_IF([test "x$with_libdeflate" != "xno"], [