This configure option allows building only the libraries, without
the command-line tools.

My use-case was a statically-linked binary, compiled with musl-gcc,
which doesn't have argp and obstack.

This works on my machine, but I'm new to autoconf, so let me know
if this is not the right way of making the programs optional.

Signed-off-by: David Ventura <[email protected]>
---
 configure.ac           | 29 +++++++++++++++++++----------
 debuginfod/Makefile.am |  4 ++++
 lib/Makefile.am        |  6 +++++-
 src/Makefile.am        | 16 +++++++++++-----
 4 files changed, 39 insertions(+), 16 deletions(-)

diff --git a/configure.ac b/configure.ac
index 58e58af2..b58d5909 100644
--- a/configure.ac
+++ b/configure.ac
@@ -547,6 +547,12 @@ AM_CONDITIONAL(FATAL_TEXTREL, [test "x$enable_textrelcheck" != "xno"])
 AS_IF([test "x$enable_textrelcheck" != "xno"],
       [enable_textrelcheck=yes],[enable_textrelcheck=no])

+AC_ARG_ENABLE([programs],
+AS_HELP_STRING([--disable-programs],
+               [Do not build command-line programs (libraries only)]),
+               [], [enable_programs=yes])
+AM_CONDITIONAL(ENABLE_PROGRAMS, test "$enable_programs" = yes)
+
 AC_ARG_ENABLE([symbol-versioning],
 AS_HELP_STRING([--disable-symbol-versioning],
                [Disable symbol versioning in shared objects]))
@@ -673,6 +679,7 @@ AC_COMPILE_IFELSE([AC_LANG_SOURCE([])],
 CFLAGS="$old_CFLAGS"])
 AS_IF([test "x$ac_cv_fno_addrsig" = "xyes"], CFLAGS="$CFLAGS -fno-addrsig")

+if test "$enable_programs" = yes; then
 saved_LIBS="$LIBS"
 AC_SEARCH_LIBS([argp_parse], [argp])
 LIBS="$saved_LIBS"
@@ -681,7 +688,18 @@ case "$ac_cv_search_argp_parse" in
         -l*) argp_LDADD="$ac_cv_search_argp_parse" ;;
         *) argp_LDADD= ;;
 esac
+
+saved_LIBS="$LIBS"
+AC_SEARCH_LIBS([_obstack_free], [obstack])
+LIBS="$saved_LIBS"
+case "$ac_cv_search__obstack_free" in
+        no) AC_MSG_FAILURE([failed to find _obstack_free]) ;;
+        -l*) obstack_LIBS="$ac_cv_search__obstack_free" ;;
+        *) obstack_LIBS= ;;
+esac
+fi
 AC_SUBST([argp_LDADD])
+AC_SUBST([obstack_LIBS])

 saved_LIBS="$LIBS"
 AC_SEARCH_LIBS([fts_close], [fts])
@@ -693,16 +711,6 @@ case "$ac_cv_search_fts_close" in
 esac
 AC_SUBST([fts_LIBS])

-saved_LIBS="$LIBS"
-AC_SEARCH_LIBS([_obstack_free], [obstack])
-LIBS="$saved_LIBS"
-case "$ac_cv_search__obstack_free" in
-        no) AC_MSG_FAILURE([failed to find _obstack_free]) ;;
-        -l*) obstack_LIBS="$ac_cv_search__obstack_free" ;;
-        *) obstack_LIBS= ;;
-esac
-AC_SUBST([obstack_LIBS])
-
 dnl The directories with content.

 dnl Documentation.
@@ -1058,6 +1066,7 @@ AC_MSG_NOTICE([
     Deterministic archives by default  : ${default_ar_deterministic}
     Native language support            : ${USE_NLS}
     Extra Valgrind annotations         : ${use_vg_annotations}
+    Build command-line programs        : ${enable_programs}
     libdebuginfod client support       : ${enable_libdebuginfod}
     Debuginfod server support          : ${enable_debuginfod}
     Default DEBUGINFOD_URLS            : ${default_debuginfod_urls}
diff --git a/debuginfod/Makefile.am b/debuginfod/Makefile.am
index 4727e5fa..b783a9cf 100644
--- a/debuginfod/Makefile.am
+++ b/debuginfod/Makefile.am
@@ -62,12 +62,16 @@ AM_LDFLAGS = -Wl,-rpath-link,../libelf:../libdw:.

 bin_PROGRAMS =
 if DEBUGINFOD
+if ENABLE_PROGRAMS
 bin_PROGRAMS += debuginfod
 endif
+endif

 if LIBDEBUGINFOD
+if ENABLE_PROGRAMS
 bin_PROGRAMS += debuginfod-find
 endif
+endif

 debuginfod_SOURCES = debuginfod.cxx
 debuginfod_LDADD = $(libdw) $(libelf) $(libeu) $(libdebuginfod) $(argp_LDADD) $(fts_LIBS) $(libmicrohttpd_LIBS) $(sqlite3_LIBS) $(libarchive_LIBS) $(rpm_LIBS) $(jsonc_LIBS) $(libcurl_LIBS) $(lzma_LIBS) -lpthread -ldl
diff --git a/lib/Makefile.am b/lib/Makefile.am
index bf5f9ee2..34f014b9 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -35,7 +35,11 @@ noinst_LIBRARIES = libeu.a

 libeu_a_SOURCES = xasprintf.c xstrdup.c xstrndup.c xmalloc.c next_prime.c \
           crc32.c crc32_file.c eu-search.c \
-          color.c error.c printversion.c
+          error.c
+
+if ENABLE_PROGRAMS
+libeu_a_SOURCES += color.c printversion.c
+endif

 noinst_HEADERS = fixedsizehash.h libeu.h system.h dynamicsizehash.h list.h \
          eu-config.h color.h printversion.h bpf.h \
diff --git a/src/Makefile.am b/src/Makefile.am
index f041d458..2e76b6d8 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -28,6 +28,12 @@ AM_CPPFLAGS += -I$(srcdir)/../libelf -I$(srcdir)/../libebl \

 AM_LDFLAGS = -Wl,-rpath-link,../libelf:../libdw $(STACK_USAGE_NO_ERROR)

+noinst_LIBRARIES =
+CLEANFILES =
+EXTRA_DIST = arlib.h debugpred.h make-debug-archive.in
+MOSTLYCLEANFILES = *.gconv
+
+if ENABLE_PROGRAMS
 bin_PROGRAMS = readelf nm size strip elflint findtextrel addr2line \
            elfcmp objdump ranlib strings ar unstrip stack elfcompress \
            elfclassify srcfiles
@@ -36,21 +42,19 @@ if ENABLE_STACKTRACE
 bin_PROGRAMS += stacktrace
 endif

-noinst_LIBRARIES = libar.a
+noinst_LIBRARIES += libar.a

 libar_a_SOURCES = arlib.c arlib2.c arlib-argp.c

 bin_SCRIPTS = make-debug-archive

-EXTRA_DIST = arlib.h debugpred.h make-debug-archive.in
-
 EXTRA_libar_a_DEPENDENCIES = libar.manifest

 libar.manifest: $(libar_a_OBJECTS)
     $(AM_V_GEN)echo $^ > $@

-MOSTLYCLEANFILES = *.gconv
-CLEANFILES = $(bin_SCRIPTS) $(EXTRA_libar_a_DEPENDENCIES)
+CLEANFILES += $(bin_SCRIPTS) $(EXTRA_libar_a_DEPENDENCIES)
+endif

 if USE_LOCKS
 noinst_LIBRARIES += libthread.a
@@ -91,6 +95,7 @@ if DEMANGLE
 demanglelib = -lstdc++
 endif

+if ENABLE_PROGRAMS
 # Bad, bad stack usage...
 readelf_no_Wstack_usage = yes
 nm_no_Wstack_usage = yes
@@ -155,3 +160,4 @@ make-debug-archive: $(srcdir)/make-debug-archive.in
         $(srcdir)/make-debug-archive.in > [email protected]
     $(AM_V_at)chmod +x [email protected]
     $(AM_V_at)mv -f [email protected] $@
+endif
--
2.43.0


Reply via email to