[PATCH] erofs-utils: use pkg-config for lz4 configuration
Gao Xiang
hsiangkao at linux.alibaba.com
Thu Dec 5 14:08:46 AEDT 2024
Also obsolete those `LZ4_HC_STATIC_LINKING_ONLY` versions since it's
too complicated to be maintained.
Signed-off-by: Gao Xiang <hsiangkao at linux.alibaba.com>
---
configure.ac | 71 +++++++++++++++---------------------------
lib/Makefile.am | 2 +-
lib/compressor_lz4hc.c | 1 -
3 files changed, 26 insertions(+), 48 deletions(-)
diff --git a/configure.ac b/configure.ac
index 9c1657b..45a7d33 100644
--- a/configure.ac
+++ b/configure.ac
@@ -123,8 +123,8 @@ AC_ARG_ENABLE([fuzzing],
[enable_fuzzing="no"])
AC_ARG_ENABLE(lz4,
- [AS_HELP_STRING([--disable-lz4], [disable LZ4 compression support @<:@default=enabled@:>@])],
- [enable_lz4="$enableval"], [enable_lz4="yes"])
+ [AS_HELP_STRING([--disable-lz4], [disable LZ4 compression support @<:@default=auto@:>@])],
+ [enable_lz4="$enableval"])
AC_ARG_ENABLE(lzma,
[AS_HELP_STRING([--disable-lzma], [disable LZMA compression support @<:@default=auto@:>@])],
@@ -172,17 +172,6 @@ AC_ARG_WITH(selinux,
esac], [with_selinux=no])
# Checks for libraries.
-# Use customized LZ4 library path when specified.
-AC_ARG_WITH(lz4-incdir,
- [AS_HELP_STRING([--with-lz4-incdir=DIR], [LZ4 include directory])], [
- EROFS_UTILS_PARSE_DIRECTORY(["$withval"],[withval])])
-
-AC_ARG_WITH(lz4-libdir,
- [AS_HELP_STRING([--with-lz4-libdir=DIR], [LZ4 lib directory])], [
- EROFS_UTILS_PARSE_DIRECTORY(["$withval"],[withval])])
-
-AC_ARG_VAR([LZ4_CFLAGS], [C compiler flags for lz4])
-AC_ARG_VAR([LZ4_LIBS], [linker flags for lz4])
# Checks for header files.
AC_CHECK_HEADERS(m4_flatten([
@@ -396,36 +385,35 @@ AS_IF([test "x$enable_fuse" != "xno"], [
CPPFLAGS="${saved_CPPFLAGS}"], [have_fuse="no"])
# Configure lz4
-test -z $LZ4_LIBS && LZ4_LIBS='-llz4'
-
-if test "x$enable_lz4" = "xyes"; then
- test -z "${with_lz4_incdir}" || LZ4_CFLAGS="-I$with_lz4_incdir $LZ4_CFLAGS"
-
+AS_IF([test "x$enable_lz4" != "xno"], [
saved_CPPFLAGS=${CPPFLAGS}
- CPPFLAGS="${LZ4_CFLAGS} ${CPPFLAGS}"
-
- AC_CHECK_HEADERS([lz4.h],[have_lz4h="yes"], [])
-
- if test "x${have_lz4h}" = "xyes" ; then
+ PKG_CHECK_MODULES([liblz4], [liblz4], [
+ # Paranoia: don't trust the result reported by pkgconfig before trying out
saved_LIBS="$LIBS"
- saved_LDFLAGS=${LDFLAGS}
- test -z "${with_lz4_libdir}" || LDFLAGS="-L$with_lz4_libdir ${LDFLAGS}"
- AC_CHECK_LIB(lz4, LZ4_compress_destSize, [
- have_lz4="yes"
- have_lz4hc="yes"
- AC_CHECK_LIB(lz4, LZ4_compress_HC_destSize, [], [
- AC_CHECK_DECL(LZ4_compress_HC_destSize, [lz4_force_static="yes"],
- [have_lz4hc="no"], [[
-#define LZ4_HC_STATIC_LINKING_ONLY (1)
+ saved_CPPFLAGS=${CPPFLAGS}
+ CPPFLAGS="${liblz4_CFLAGS} ${CPPFLAGS}"
+ LIBS="${liblz4_LIBS} $LIBS"
+ AC_CHECK_HEADERS([lz4.h],[
+ AC_CHECK_LIB(lz4, LZ4_compress_destSize, [
+ AC_CHECK_DECL(LZ4_compress_destSize, [have_lz4="yes"],
+ [], [[
+#include <lz4.h>
+ ]])
+ ])
+ AC_CHECK_LIB(lz4, LZ4_compress_HC_destSize, [
+ AC_CHECK_DECL(LZ4_compress_HC_destSize, [have_lz4hc="yes"],
+ [], [[
#include <lz4hc.h>
]])
])
- ], [AC_MSG_ERROR([Cannot find proper lz4 version (>= 1.8.0)])])
- LDFLAGS=${saved_LDFLAGS}
+ ])
LIBS="${saved_LIBS}"
- fi
- CPPFLAGS=${saved_CPPFLAGS}
-fi
+ CPPFLAGS="${saved_CPPFLAGS}"
+ ], [[]])
+ AS_IF([test "x$enable_lz4" = "xyes" -a "x$have_lz4" != "xyes"], [
+ AC_MSG_ERROR([Cannot find a proper liblz4 version])
+ ])
+])
# Configure liblzma
have_liblzma="no"
@@ -581,16 +569,7 @@ if test "x${have_lz4}" = "xyes"; then
if test "x${have_lz4hc}" = "xyes"; then
AC_DEFINE([LZ4HC_ENABLED], [1], [Define to 1 if lz4hc is enabled.])
fi
-
- if test "x${lz4_force_static}" = "xyes"; then
- LZ4_LIBS="-Wl,-Bstatic -Wl,-whole-archive -Xlinker ${LZ4_LIBS} -Wl,-no-whole-archive -Wl,-Bdynamic"
- test -z "${with_lz4_libdir}" || LZ4_LIBS="-L${with_lz4_libdir} $LZ4_LIBS"
- else
- test -z "${with_lz4_libdir}" || LZ4_LIBS="-L${with_lz4_libdir} -R${with_lz4_libdir} $LZ4_LIBS"
- fi
- liblz4_LIBS="${LZ4_LIBS}"
fi
-AC_SUBST([liblz4_LIBS])
if test "x${have_liblzma}" = "xyes"; then
AC_DEFINE([HAVE_LIBLZMA], [1], [Define to 1 if liblzma is enabled.])
diff --git a/lib/Makefile.am b/lib/Makefile.am
index 758363e..9c0604d 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -38,7 +38,7 @@ liberofs_la_SOURCES = config.c io.c cache.c super.c inode.c xattr.c exclude.c \
liberofs_la_CFLAGS = -Wall ${libuuid_CFLAGS} -I$(top_srcdir)/include
if ENABLE_LZ4
-liberofs_la_CFLAGS += ${LZ4_CFLAGS}
+liberofs_la_CFLAGS += ${liblz4_CFLAGS}
liberofs_la_SOURCES += compressor_lz4.c
if ENABLE_LZ4HC
liberofs_la_SOURCES += compressor_lz4hc.c
diff --git a/lib/compressor_lz4hc.c b/lib/compressor_lz4hc.c
index 1e1ccc7..9955c0d 100644
--- a/lib/compressor_lz4hc.c
+++ b/lib/compressor_lz4hc.c
@@ -4,7 +4,6 @@
* http://www.huawei.com/
* Created by Gao Xiang <xiang at kernel.org>
*/
-#define LZ4_HC_STATIC_LINKING_ONLY (1)
#include <lz4hc.h>
#include "erofs/internal.h"
#include "erofs/print.h"
--
2.39.3 (Apple Git-146)
More information about the Linux-erofs
mailing list