Hi David,

On Thu, Jan 15, 2026 at 10:42 AM David <[email protected]> wrote:
>
> 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.

Thanks for the patch, I've included a couple suggestions below. Also
git was not able to read the patch due to a formatting problem (early
line breaks?). If you haven't already done so, 'git format-patch' then
'git send-email' is the best way to send patches to this mailing list.

>
> 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)

If we run the testsuite after building with --disable-programs, a
number of tests fail because the cli programs aren't found. This would
be cleaner if we return 77 in run-*.sh test scripts to skip tests.

To facilitate this I recommend using AC_DEFINE(ENABLE_PROGRAMS, 1,
...) when building the programs. Then in test scripts return 77 when
config.h contains "#define ENABLE_PROGRAMS 1". The following can be
defined in tests/test-subr.sh and called in the test scripts that test
cli programs:

check_enable_programs()
{
  ENABLE_PROGRAMS=$(grep '^#define ENABLE_PROGRAM' \
      ${abs_builddir}/../config.h | awk '{print $3}')

  if [ "$ENABLE_PROGRAMS" != 1 ]; then
    echo "ENABLE_PROGRAMS is not defined. Skipping tests."
    exit 77
  fi
}

Some test scripts contain a mix of tests that depend on the cli
programs and tests that don't. We could modify these scripts so that
only the latter run (when possible), but this isn't necessary in this
patch.

> +
>   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])

On some platforms elfutils libcpu needs obstack so I believe
AC_SEARCH_LIBS, etc, for obstack should still occur unconditionally.

>
>   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