[PATCH v2] erofs-utils: build: link tools with liberofs dependencies

Yifan Zhao <[email protected]>
Newsgroups org.ozlabs.lists.linux-erofs
Message-ID <[email protected]>
From: Yifan Zhao <[email protected]>

liberofs.la is a noinst libtool archive, so relying on its
dependency_libs to carry external libraries is not enough for
static-only dependencies.

For example, when liblzma is installed as a static libtool archive,
libtool consumes -llzma while creating liberofs.la but does not record it
in dependency_libs.  The final tools then link only with liberofs.la and
fail with undefined lzma_* references.

Collect liberofs external libraries in LIBEROFS_LIBS and use it for both
liberofs.la and the final tools, so final executable links see the
pkg-config supplied liblzma flags directly.

Reported-by: Guo Xuenan <[email protected]>
Fixes: 6c2a000782b2 ("erofs-utils: lib: add test for s3erofs_prepare_url()")
Assisted-by: Codex:GPT-5.5
Signed-off-by: Yifan Zhao <[email protected]>
---
 configure.ac      |  9 +++++++++
 dump/Makefile.am  |  2 +-
 fsck/Makefile.am  |  4 ++--
 fuse/Makefile.am  |  5 +++--
 lib/Makefile.am   | 14 +++-----------
 mkfs/Makefile.am  |  2 +-
 mount/Makefile.am |  2 +-
 7 files changed, 20 insertions(+), 18 deletions(-)

diff --git a/configure.ac b/configure.ac
index f68bb74..392d931 100644
--- a/configure.ac
+++ b/configure.ac
@@ -790,6 +790,15 @@ AM_CONDITIONAL([ENABLE_STATIC_FUSE], [test "x${enable_static_fuse}" = "xyes"])
 AM_CONDITIONAL([ENABLE_OCI], [test "x${have_oci}" = "xyes"])
 AM_CONDITIONAL([ENABLE_FANOTIFY], [test "x${have_fanotify}" = "xyes"])
 
+LIBEROFS_LIBS="${libselinux_LIBS} ${libuuid_LIBS} ${liblz4_LIBS} \
+${liblzma_LIBS} ${zlib_LIBS} ${libdeflate_LIBS} ${libzstd_LIBS} \
+${libqpl_LIBS} ${libxxhash_LIBS} ${libcurl_LIBS} ${openssl_LIBS} \
+${libxml2_LIBS} ${json_c_LIBS} ${libnl3_LIBS}"
+AS_IF([test "x${enable_multithreading}" != "xno"], [
+  LIBEROFS_LIBS="${LIBEROFS_LIBS} -lpthread"
+])
+AC_SUBST([LIBEROFS_LIBS])
+
 if test "x$have_uuid" = "xyes"; then
   AC_DEFINE([HAVE_LIBUUID], 1, [Define to 1 if libuuid is found])
 fi
diff --git a/dump/Makefile.am b/dump/Makefile.am
index 2611fd2..5d908b4 100644
--- a/dump/Makefile.am
+++ b/dump/Makefile.am
@@ -6,4 +6,4 @@ bin_PROGRAMS     = dump.erofs
 AM_CPPFLAGS = ${libuuid_CFLAGS}
 dump_erofs_SOURCES = main.c
 dump_erofs_CFLAGS = -Wall -I$(top_srcdir)/include
-dump_erofs_LDADD = $(top_builddir)/lib/liberofs.la
+dump_erofs_LDADD = $(top_builddir)/lib/liberofs.la $(LIBEROFS_LIBS)
diff --git a/fsck/Makefile.am b/fsck/Makefile.am
index 8eebadd..461eb88 100644
--- a/fsck/Makefile.am
+++ b/fsck/Makefile.am
@@ -6,12 +6,12 @@ bin_PROGRAMS     = fsck.erofs
 AM_CPPFLAGS = ${libuuid_CFLAGS}
 fsck_erofs_SOURCES = main.c
 fsck_erofs_CFLAGS = -Wall -I$(top_srcdir)/include
-fsck_erofs_LDADD = $(top_builddir)/lib/liberofs.la
+fsck_erofs_LDADD = $(top_builddir)/lib/liberofs.la $(LIBEROFS_LIBS)
 
 if ENABLE_FUZZING
 noinst_PROGRAMS   = fuzz_erofsfsck
 fuzz_erofsfsck_SOURCES = main.c
 fuzz_erofsfsck_CFLAGS = -Wall -I$(top_srcdir)/include -DFUZZING
 fuzz_erofsfsck_LDFLAGS = -fsanitize=address,fuzzer
-fuzz_erofsfsck_LDADD = $(top_builddir)/lib/liberofs.la
+fuzz_erofsfsck_LDADD = $(top_builddir)/lib/liberofs.la $(LIBEROFS_LIBS)
 endif
diff --git a/fuse/Makefile.am b/fuse/Makefile.am
index 9fe5608..b72e065 100644
--- a/fuse/Makefile.am
+++ b/fuse/Makefile.am
@@ -6,12 +6,13 @@ bin_PROGRAMS     = erofsfuse
 erofsfuse_SOURCES = main.c
 erofsfuse_CFLAGS = -Wall -I$(top_srcdir)/include
 erofsfuse_CFLAGS += ${libfuse2_CFLAGS} ${libfuse3_CFLAGS} ${libselinux_CFLAGS}
-erofsfuse_LDADD = $(top_builddir)/lib/liberofs.la ${libfuse2_LIBS} ${libfuse3_LIBS}
+erofsfuse_LDADD = $(top_builddir)/lib/liberofs.la $(LIBEROFS_LIBS) \
+	${libfuse2_LIBS} ${libfuse3_LIBS}
 
 if ENABLE_STATIC_FUSE
 lib_LTLIBRARIES = liberofsfuse.la
 liberofsfuse_la_SOURCES = main.c
 liberofsfuse_la_CFLAGS  = -Wall -I$(top_srcdir)/include
 liberofsfuse_la_CFLAGS += -Dmain=erofsfuse_main ${libfuse2_CFLAGS} ${libfuse3_CFLAGS} ${libselinux_CFLAGS}
-liberofsfuse_la_LIBADD  = $(top_builddir)/lib/liberofs.la
+liberofsfuse_la_LIBADD  = $(top_builddir)/lib/liberofs.la $(LIBEROFS_LIBS)
 endif
diff --git a/lib/Makefile.am b/lib/Makefile.am
index 27bf710..25ad79d 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -48,9 +48,7 @@ liberofs_la_SOURCES = config.c io.c cache.c super.c inode.c xattr.c exclude.c \
 		      vmdk.c metabox.c global.c importer.c base64.c
 
 liberofs_la_CFLAGS = -Wall ${libuuid_CFLAGS} -I$(top_srcdir)/include
-liberofs_la_LDFLAGS = ${libselinux_LIBS} ${libuuid_LIBS} ${liblz4_LIBS} \
-	${liblzma_LIBS} ${zlib_LIBS} ${libdeflate_LIBS} ${libzstd_LIBS} \
-	${libqpl_LIBS}
+liberofs_la_LIBADD = $(LIBEROFS_LIBS)
 if ENABLE_LZ4
 liberofs_la_CFLAGS += ${liblz4_CFLAGS}
 liberofs_la_SOURCES += compressor_lz4.c
@@ -74,23 +72,18 @@ liberofs_la_SOURCES += compressor_libzstd.c
 endif
 if ENABLE_XXHASH
 liberofs_la_CFLAGS += ${libxxhash_CFLAGS}
-liberofs_la_LDFLAGS += ${libxxhash_LIBS}
 else
 liberofs_la_SOURCES += xxhash.c
 endif
 liberofs_la_CFLAGS += ${libcurl_CFLAGS} ${openssl_CFLAGS} ${libxml2_CFLAGS}
-liberofs_la_LDFLAGS += ${libcurl_LIBS} ${openssl_LIBS}
 if ENABLE_S3
 liberofs_la_SOURCES += remotes/s3.c
-liberofs_la_LDFLAGS += ${libxml2_LIBS}
 endif
 if ENABLE_EROFS_MT
-liberofs_la_LDFLAGS += -lpthread
 liberofs_la_SOURCES += workqueue.c
 endif
 if OS_LINUX
 liberofs_la_CFLAGS += ${libnl3_CFLAGS}
-liberofs_la_LDFLAGS += ${libnl3_LIBS}
 liberofs_la_SOURCES += backends/nbd.c
 if ENABLE_FANOTIFY
 liberofs_la_SOURCES += backends/fanotify.c
@@ -98,19 +91,18 @@ endif
 endif
 liberofs_la_SOURCES += remotes/oci.c remotes/docker_config.c
 liberofs_la_CFLAGS += ${json_c_CFLAGS}
-liberofs_la_LDFLAGS += ${json_c_LIBS}
 liberofs_la_SOURCES += gzran.c
 
 if ENABLE_S3
 noinst_PROGRAMS = s3erofs_test
 s3erofs_test_SOURCES = remotes/s3.c
 s3erofs_test_CFLAGS = -Wall -I$(top_srcdir)/include ${libxml2_CFLAGS} ${openssl_CFLAGS} -DTEST
-s3erofs_test_LDADD = liberofs.la
+s3erofs_test_LDADD = liberofs.la $(LIBEROFS_LIBS)
 endif
 
 if ENABLE_OCI
 noinst_PROGRAMS = ocierofs_test
 ocierofs_test_SOURCES = remotes/oci.c
 ocierofs_test_CFLAGS = -Wall -I$(top_srcdir)/include ${json_c_CFLAGS} -DTEST
-ocierofs_test_LDADD = liberofs.la
+ocierofs_test_LDADD = liberofs.la $(LIBEROFS_LIBS)
 endif
diff --git a/mkfs/Makefile.am b/mkfs/Makefile.am
index 386455a..f511a09 100644
--- a/mkfs/Makefile.am
+++ b/mkfs/Makefile.am
@@ -5,4 +5,4 @@ bin_PROGRAMS     = mkfs.erofs
 AM_CPPFLAGS = ${libselinux_CFLAGS}
 mkfs_erofs_SOURCES = main.c
 mkfs_erofs_CFLAGS = -Wall -I$(top_srcdir)/include
-mkfs_erofs_LDADD = $(top_builddir)/lib/liberofs.la
+mkfs_erofs_LDADD = $(top_builddir)/lib/liberofs.la $(LIBEROFS_LIBS)
diff --git a/mount/Makefile.am b/mount/Makefile.am
index 637029d..189dbaf 100644
--- a/mount/Makefile.am
+++ b/mount/Makefile.am
@@ -7,5 +7,5 @@ sbin_PROGRAMS    = mount.erofs
 AM_CPPFLAGS = ${libuuid_CFLAGS}
 mount_erofs_SOURCES = main.c
 mount_erofs_CFLAGS = -Wall -I$(top_srcdir)/include
-mount_erofs_LDADD = $(top_builddir)/lib/liberofs.la
+mount_erofs_LDADD = $(top_builddir)/lib/liberofs.la $(LIBEROFS_LIBS)
 endif
-- 
2.47.3
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.