[PATCH] build: support building static library

ComixHe heyuming at deepin.org
Thu May 23 17:31:04 AEST 2024


In some cases, developer may need to integrate erofs-utils into their
proejct as a static library to reduce package dependencies and
have more finer control over the feature used by the project.

For exapmle, squashfuse provides a static library `libsquashfuse.a` and
exposes some useful functions, Appimage uses this static library to build
image. It could ensure that the executable image can be executed directly
on most linux platforms and the user doesn't need to install squashfuse
in order to execute the image.

Signed-off-by: ComixHe <heyuming at deepin.org>
---
 configure.ac     | 28 ++++++++++++++++++++++++++++
 dump/Makefile.am | 10 ++++++++++
 fsck/Makefile.am | 10 ++++++++++
 fuse/Makefile.am | 10 ++++++++++
 mkfs/Makefile.am | 10 ++++++++++
 5 files changed, 68 insertions(+)

diff --git a/configure.ac b/configure.ac
index 1989bca..16ddb7c 100644
--- a/configure.ac
+++ b/configure.ac
@@ -147,6 +147,30 @@ AC_ARG_ENABLE(fuse,
    [AS_HELP_STRING([--enable-fuse], [enable erofsfuse @<:@default=no@:>@])],
    [enable_fuse="$enableval"], [enable_fuse="no"])
 
+AC_ARG_ENABLE([static-fuse],
+    [AS_HELP_STRING([--enable-static-fuse],
+                    [build erofsfuse as a static library @<:@default=no@:>@])],
+    [enable_static_fuse="$enableval"],
+    [enable_static_fuse="no"])
+
+AC_ARG_ENABLE([static-dump],
+    [AS_HELP_STRING([--enable-static-dump],
+                    [build dump.erofs as a static library @<:@default=no@:>@])],
+    [enable_static_dump="$enableval"],
+    [enable_static_dump="no"])
+
+AC_ARG_ENABLE([static-mkfs],
+    [AS_HELP_STRING([--enable-static-mkfs],
+                    [build mkfs.erofs as a static library @<:@default=no@:>@])],
+    [enable_static_mkfs="$enableval"],
+    [enable_static_mkfs="no"])
+
+AC_ARG_ENABLE([static-fsck],
+    [AS_HELP_STRING([--enable-static-fsck],
+                    [build fsck.erofs as a static library @<:@default=no@:>@])],
+    [enable_static_fsck="$enableval"],
+    [enable_static_fsck="no"])
+
 AC_ARG_WITH(uuid,
    [AS_HELP_STRING([--without-uuid],
       [Ignore presence of libuuid and disable uuid support @<:@default=enabled@:>@])])
@@ -525,6 +549,10 @@ AM_CONDITIONAL([ENABLE_FUSE], [test "x${have_fuse}" = "xyes"])
 AM_CONDITIONAL([ENABLE_LIBLZMA], [test "x${have_liblzma}" = "xyes"])
 AM_CONDITIONAL([ENABLE_LIBDEFLATE], [test "x${have_libdeflate}" = "xyes"])
 AM_CONDITIONAL([ENABLE_LIBZSTD], [test "x${have_libzstd}" = "xyes"])
+AM_CONDITIONAL([ENABLE_STATIC_FUSE], [test "x${enable_static_fuse}" = "xyes"])
+AM_CONDITIONAL([ENABLE_STATIC_MKFS], [test "x${enable_static_mkfs}" = "xyes"])
+AM_CONDITIONAL([ENABLE_STATIC_DUMP], [test "x${enable_static_dump}" = "xyes"])
+AM_CONDITIONAL([ENABLE_STATIC_FSCK], [test "x${enable_static_fsck}" = "xyes"])
 
 if test "x$have_uuid" = "xyes"; then
   AC_DEFINE([HAVE_LIBUUID], 1, [Define to 1 if libuuid is found])
diff --git a/dump/Makefile.am b/dump/Makefile.am
index 09c483e..da0df51 100644
--- a/dump/Makefile.am
+++ b/dump/Makefile.am
@@ -9,3 +9,13 @@ dump_erofs_CFLAGS = -Wall -I$(top_srcdir)/include
 dump_erofs_LDADD = $(top_builddir)/lib/liberofs.la ${libselinux_LIBS} \
 	${liblz4_LIBS} ${liblzma_LIBS} ${zlib_LIBS} ${libdeflate_LIBS} \
 	${libzstd_LIBS}
+
+if ENABLE_STATIC_DUMP
+lib_LTLIBRARIES     = libdumperofs.la
+libdumperofs_la_SOURCES = main.c
+libdumperofs_la_CFLAGS = -Wall -I$(top_srcdir)/include
+libdumperofs_la_CFLAGS += -Dmain=dumperofs_main -static
+libdumperofs_la_LIBADD = $(top_builddir)/lib/liberofs.la ${libselinux_LIBS} \
+	${liblz4_LIBS} ${liblzma_LIBS} ${zlib_LIBS} ${libdeflate_LIBS} \
+	${libzstd_LIBS}
+endif
diff --git a/fsck/Makefile.am b/fsck/Makefile.am
index 70eacc0..0916320 100644
--- a/fsck/Makefile.am
+++ b/fsck/Makefile.am
@@ -10,6 +10,16 @@ fsck_erofs_LDADD = $(top_builddir)/lib/liberofs.la ${libselinux_LIBS} \
 	${liblz4_LIBS} ${liblzma_LIBS} ${zlib_LIBS} ${libdeflate_LIBS} \
 	${libzstd_LIBS}
 
+if ENABLE_STATIC_FSCK
+lib_LTLIBRARIES    = libfsckerofs.la
+libfsckerofs_la_SOURCES = main.c
+libfsckerofs_la_CFLAGS = -Wall -I$(top_srcdir)/include
+libfsckerofs_la_CFLAGS += -Dmain=fsckerofs_main -static
+libfsckerofs_la_LIBADD = $(top_builddir)/lib/liberofs.la ${libselinux_LIBS} \
+	${liblz4_LIBS} ${liblzma_LIBS} ${zlib_LIBS} ${libdeflate_LIBS} \
+	${libzstd_LIBS}
+endif
+
 if ENABLE_FUZZING
 noinst_PROGRAMS   = fuzz_erofsfsck
 fuzz_erofsfsck_SOURCES = main.c
diff --git a/fuse/Makefile.am b/fuse/Makefile.am
index 7eae5f6..120d3e1 100644
--- a/fuse/Makefile.am
+++ b/fuse/Makefile.am
@@ -8,3 +8,13 @@ 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} ${liblz4_LIBS} \
 	${libselinux_LIBS} ${liblzma_LIBS} ${zlib_LIBS} ${libdeflate_LIBS} ${libzstd_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 -static ${libfuse2_CFLAGS} ${libfuse3_CFLAGS} ${libselinux_CFLAGS}
+liberofsfuse_la_LIBADD  = $(top_builddir)/lib/liberofs.la ${libfuse2_LIBS} ${libfuse3_LIBS} ${liblz4_LIBS} \
+	${libselinux_LIBS} ${liblzma_LIBS} ${zlib_LIBS} ${libdeflate_LIBS} ${libzstd_LIBS}
+endif
diff --git a/mkfs/Makefile.am b/mkfs/Makefile.am
index af97e39..6edcdda 100644
--- a/mkfs/Makefile.am
+++ b/mkfs/Makefile.am
@@ -8,3 +8,13 @@ mkfs_erofs_CFLAGS = -Wall -I$(top_srcdir)/include
 mkfs_erofs_LDADD = $(top_builddir)/lib/liberofs.la ${libselinux_LIBS} \
 	${libuuid_LIBS} ${liblz4_LIBS} ${liblzma_LIBS} ${zlib_LIBS} \
 	${libdeflate_LIBS} ${libzstd_LIBS}
+
+if ENABLE_STATIC_MKFS
+lib_LTLIBRARIES     = libmkerofs.la
+libmkerofs_la_SOURCES = main.c
+libmkerofs_la_CFLAGS = -Wall -I$(top_srcdir)/include
+libmkerofs_la_CFLAGS += -Dmain=mkerofs_main -static
+libmkerofs_la_LIBADD = $(top_builddir)/lib/liberofs.la ${libselinux_LIBS} \
+	${libuuid_LIBS} ${liblz4_LIBS} ${liblzma_LIBS} ${zlib_LIBS} \
+	${libdeflate_LIBS} ${libzstd_LIBS}
+endif
-- 
2.45.1



More information about the Linux-erofs mailing list