From 659b3eeca88025b5bbe6a7dbb402c5b65d8cbed8 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Mon, 12 Feb 2024 16:59:59 +0100 Subject: [PATCH 01/22] ci_build.sh: add "TAKING SHORTCUT" to re-generate if current configure script syntax is broken Signed-off-by: Jim Klimov --- ci_build.sh | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/ci_build.sh b/ci_build.sh index f6491d4373..6f52b9a21d 100755 --- a/ci_build.sh +++ b/ci_build.sh @@ -1317,6 +1317,15 @@ default|default-alldrv|default-alldrv:no-distcheck|default-all-errors|default-sp fi fi + # When itertating configure.ac or m4 sources, we can end up with an + # existing but useless scropt file - nuke it and restart from scratch! + if [ -s "${CI_BUILDDIR}"/configure ] ; then + if ! sh -n "${CI_BUILDDIR}"/configure 2>/dev/null ; then + echo "=== Starting initial clean-up (from old build products): TAKING SHORTCUT because current configure script syntax is broken" + rm -f "${CI_BUILDDIR}"/Makefile "${CI_BUILDDIR}"/configure + fi + fi + if [ -s Makefile ]; then # Let initial clean-up be at default verbosity @@ -1925,6 +1934,15 @@ bindings) fi fi + # When itertating configure.ac or m4 sources, we can end up with an + # existing but useless scropt file - nuke it and restart from scratch! + if [ -s "${CI_BUILDDIR}"/configure ] ; then + if ! sh -n "${CI_BUILDDIR}"/configure 2>/dev/null ; then + echo "=== Starting initial clean-up (from old build products): TAKING SHORTCUT because current configure script syntax is broken" + rm -f "${CI_BUILDDIR}"/Makefile "${CI_BUILDDIR}"/configure + fi + fi + if [ -s Makefile ]; then # Help developers debug: # Let initial clean-up be at default verbosity From 77ec7c78014bd0385e24ae8f5712ae2fb3a04bc9 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Mon, 12 Feb 2024 20:41:06 +0100 Subject: [PATCH 02/22] ci_build.sh: empty BUILD_TYPE is not an "error", fix the warning message Signed-off-by: Jim Klimov --- ci_build.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ci_build.sh b/ci_build.sh index 6f52b9a21d..95dac86d84 100755 --- a/ci_build.sh +++ b/ci_build.sh @@ -1902,7 +1902,7 @@ bindings) pushd "./bindings/${BINDING}" && ./ci_build.sh ;; ""|inplace) - echo "ERROR: No BUILD_TYPE was specified, doing a minimal default ritual without any required options" >&2 + echo "WARNING: No BUILD_TYPE was specified, doing a minimal default ritual without any *required* build products and with developer-oriented options" >&2 if [ -n "${BUILD_WARNOPT}${BUILD_WARNFATAL}" ]; then echo "WARNING: BUILD_WARNOPT and BUILD_WARNFATAL settings are ignored in this mode (warnings are always enabled and fatal for these developer-oriented builds)" >&2 sleep 5 From 12afb9457f5b446887f84e0dc1df30c6f48a7f8e Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Mon, 12 Feb 2024 16:17:03 +0100 Subject: [PATCH 03/22] configure.ac, ci_build.sh: introduce --with-debuginfo (BUILD_DEBUGINFO) setting Signed-off-by: Jim Klimov --- ci_build.sh | 13 +++++++++++++ configure.ac | 33 ++++++++++++++++++++++++++++++++- 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/ci_build.sh b/ci_build.sh index 95dac86d84..2e6dc3bd2c 100755 --- a/ci_build.sh +++ b/ci_build.sh @@ -96,6 +96,9 @@ if [ "$BUILD_TYPE" = fightwarn ]; then #[ -n "$NUT_USB_VARIANTS" ] || NUT_USB_VARIANTS=auto fi +# configure default is "no"; an "auto" value is "yes unless CFLAGS say something" +[ -n "${BUILD_DEBUGINFO-}" ] || BUILD_DEBUGINFO="" + # Set this to enable verbose profiling [ -n "${CI_TIME-}" ] || CI_TIME="" case "$CI_TIME" in @@ -1299,6 +1302,10 @@ default|default-alldrv|default-alldrv:no-distcheck|default-all-errors|default-sp # and errors are found more easily in a wall of text: CONFIG_OPTS+=("--enable-Wcolor") + if [ -n "${BUILD_DEBUGINFO-}" ]; then + CONFIG_OPTS+=("--with-debuginfo=${BUILD_DEBUGINFO}") + fi + # Note: modern auto(re)conf requires pkg-config to generate the configure # script, so to stage the situation of building without one (as if on an # older system) we have to remove it when we already have the script. @@ -1976,6 +1983,12 @@ bindings) CONFIG_OPTS+=("--disable-silent-rules") fi + if [ -n "${BUILD_DEBUGINFO-}" ]; then + CONFIG_OPTS+=("--with-debuginfo=${BUILD_DEBUGINFO}") + else + CONFIG_OPTS+=("--with-debuginfo=auto") + fi + ${CONFIGURE_SCRIPT} "${CONFIG_OPTS[@]}" # NOTE: Currently parallel builds are expected to succeed (as far diff --git a/configure.ac b/configure.ac index 83b5b2a0be..bcb44dab4b 100644 --- a/configure.ac +++ b/configure.ac @@ -171,7 +171,9 @@ dnl Fix this early so we can expand with eval later test "${prefix}" = "NONE" && prefix="${ac_default_prefix}" test "${exec_prefix}" = "NONE" && exec_prefix='${prefix}' -CFLAGS=${CFLAGS-"-O"} +dnl # LEGACY DEFAULT # CFLAGS=${CFLAGS-"-O"} +CFLAGS_ORIG="${CFLAGS-}" +CXXFLAGS_ORIG="${CXXFLAGS-}" dnl Note: for practical and platform-independent use, see AX_REALPATH macro AC_CHECK_PROGS([REALPATH], [realpath], []) @@ -1653,6 +1655,9 @@ NUT_ARG_ENABLE([warnings], NUT_ARG_ENABLE([Werror], [fail the build if compiler emits any warnings (treat them as errors)], [no]) +NUT_ARG_WITH([debuginfo], + [enable compiler options for debug-friendly builds of all NUT binaries ("no" by default; "auto" means "yes unless CFLAGS say otherwise")], + [no]) dnl To help find warning/error details in a wall of text, see --enable-Wcolor handled above dnl ---------------------------------------------------------------------- @@ -4658,6 +4663,32 @@ AC_ARG_VAR(CCACHE_PATH) PATH_DURING_CONFIGURE="$PATH" AC_SUBST(PATH_DURING_CONFIGURE) +dnl Some binaries, like CPPUNIT tests, have similar flags already added +AC_MSG_CHECKING([whether to enable debug info in all NUT binaries]) +AS_IF([test x"${nut_with_debuginfo}" = xauto], [ + AS_CASE(["${CFLAGS}${CXXFLAGS}"], + [*-O*|*-g*], [nut_with_debuginfo="Related settings already specified by caller, not changing anything"], + [nut_with_debuginfo=yes]) +]) +AS_CASE(["${nut_with_debuginfo}"], + [yes], [ + AS_IF([test x"${CLANGCC}" = x"yes" -o test x"${GCC}" = x"yes"], [ + CFLAGS="${CFLAGS} -O0 -g3 -gdwarf-2" + ],[nut_with_debuginfo="Unknown C compiler, not adding options"] + ) + AS_IF([test "x$CLANGXX" = xyes -o "x$GXX" = xyes], [ + CXXFLAGS="${CXXFLAGS} -O0 -g3 -gdwarf-2" + ],[nut_with_debuginfo="Unknown C++ compiler, not adding options"] + )], + [no], [ + dnl # By default we do not add debug info + dnl # Apply legacy defaults if no flags were specified by caller + AS_IF([test x"${CFLAGS_ORIG}" = x], [CFLAGS="-O ${CFLAGS}"]) + AS_IF([test x"${CXXFLAGS_ORIG}" = x], [CXXFLAGS="-O ${CXXFLAGS}"]) + ] +) +AC_MSG_RESULT(["${nut_with_debuginfo}"]) + AC_MSG_NOTICE([Generating "data" files from templates, see below for executable scripts]) AC_CONFIG_FILES([ clients/Makefile From 851cdef176d50c1828702f15fc14e7c5615118b0 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Mon, 12 Feb 2024 17:00:38 +0100 Subject: [PATCH 04/22] configure.ac: separate internally nut_with_debuginfo into nut_with_debuginfo_C vs. nut_with_debuginfo_CXX Signed-off-by: Jim Klimov --- configure.ac | 56 ++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 43 insertions(+), 13 deletions(-) diff --git a/configure.ac b/configure.ac index bcb44dab4b..16a9ec7902 100644 --- a/configure.ac +++ b/configure.ac @@ -4665,29 +4665,59 @@ AC_SUBST(PATH_DURING_CONFIGURE) dnl Some binaries, like CPPUNIT tests, have similar flags already added AC_MSG_CHECKING([whether to enable debug info in all NUT binaries]) -AS_IF([test x"${nut_with_debuginfo}" = xauto], [ - AS_CASE(["${CFLAGS}${CXXFLAGS}"], - [*-O*|*-g*], [nut_with_debuginfo="Related settings already specified by caller, not changing anything"], - [nut_with_debuginfo=yes]) -]) -AS_CASE(["${nut_with_debuginfo}"], +nut_with_debuginfo_C="${nut_with_debuginfo}" +nut_with_debuginfo_CXX="${nut_with_debuginfo}" +AS_CASE(["${CFLAGS}"], + [*-O*|*-g*], [ + AS_IF([test x"${nut_with_debuginfo_C}" = xauto], [ + nut_with_debuginfo_C="Related settings already specified by caller or detected CFLAGS, not changing anything" + ]) + ], + [ dnl No competing options are provided + AS_CASE(["${nut_with_debuginfo_C}"], + [auto], [nut_with_debuginfo_C="yes"], + [no], [nut_with_debuginfo_C="legacy"]) + ]) + +AS_CASE(["${CXXFLAGS}"], + [*-O*|*-g*], [ + AS_IF([test x"${nut_with_debuginfo_CXX}" = xauto], [ + nut_with_debuginfo_CXX="Related settings already specified by caller or detected CXXFLAGS, not changing anything" + ]) + ], + [ dnl No competing options are provided + AS_CASE(["${nut_with_debuginfo_CXX}"], + [auto], [nut_with_debuginfo_CXX="yes"], + [no], [nut_with_debuginfo_CXX="legacy"]) + ]) + +AS_CASE(["${nut_with_debuginfo_C}"], [yes], [ AS_IF([test x"${CLANGCC}" = x"yes" -o test x"${GCC}" = x"yes"], [ CFLAGS="${CFLAGS} -O0 -g3 -gdwarf-2" - ],[nut_with_debuginfo="Unknown C compiler, not adding options"] - ) + ],[nut_with_debuginfo_C="Unknown C compiler, not adding options"] + )], + dnl # [no]: By default we do not add debug info + [legacy], [ + dnl # Apply legacy defaults if no flags were specified by caller + AS_IF([test x"${CFLAGS_ORIG}" = x], [CFLAGS="-O ${CFLAGS}"]) + ] +) + +AS_CASE(["${nut_with_debuginfo_CXX}"], + [yes], [ AS_IF([test "x$CLANGXX" = xyes -o "x$GXX" = xyes], [ CXXFLAGS="${CXXFLAGS} -O0 -g3 -gdwarf-2" - ],[nut_with_debuginfo="Unknown C++ compiler, not adding options"] + ],[nut_with_debuginfo_CXX="Unknown C++ compiler, not adding options"] )], - [no], [ - dnl # By default we do not add debug info + dnl # [no]: By default we do not add debug info + [legacy], [ dnl # Apply legacy defaults if no flags were specified by caller - AS_IF([test x"${CFLAGS_ORIG}" = x], [CFLAGS="-O ${CFLAGS}"]) AS_IF([test x"${CXXFLAGS_ORIG}" = x], [CXXFLAGS="-O ${CXXFLAGS}"]) ] ) -AC_MSG_RESULT(["${nut_with_debuginfo}"]) + +AC_MSG_RESULT(["C: ${nut_with_debuginfo_C}; C++: ${nut_with_debuginfo_CXX}"]) AC_MSG_NOTICE([Generating "data" files from templates, see below for executable scripts]) AC_CONFIG_FILES([ From 62f98dbea685242fb05c38760cd11c6131232c28 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Mon, 12 Feb 2024 22:15:24 +0100 Subject: [PATCH 05/22] configure.ac: if we apply nut_with_debuginfo_CXX, avoid separate settings for CPPUNIT_NUT_CXXFLAGS debugging Signed-off-by: Jim Klimov --- configure.ac | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/configure.ac b/configure.ac index 16a9ec7902..552ea134ac 100644 --- a/configure.ac +++ b/configure.ac @@ -3578,6 +3578,9 @@ unset CPLUSPLUS_DECL AC_MSG_CHECKING(for have_cppunit) have_cppunit="no" +dnl CPPUNIT_NUT_CXXFLAGS are set below if suitable, but can be +dnl disabled further below if nut_with_debuginfo gets applied +dnl for all NUT build products: CPPUNIT_NUT_CXXFLAGS="" AS_IF([test x"$have_PKG_CONFIG" = xyes], [AS_IF([test x"${have_cxx11}" = xyes], @@ -4707,7 +4710,9 @@ AS_CASE(["${nut_with_debuginfo_C}"], AS_CASE(["${nut_with_debuginfo_CXX}"], [yes], [ AS_IF([test "x$CLANGXX" = xyes -o "x$GXX" = xyes], [ + dnl Where we can enable debug, minimize the optimizations CXXFLAGS="${CXXFLAGS} -O0 -g3 -gdwarf-2" + CPPUNIT_NUT_CXXFLAGS="" ],[nut_with_debuginfo_CXX="Unknown C++ compiler, not adding options"] )], dnl # [no]: By default we do not add debug info From ac1fdf7e1574280aeb22ae98c39583042efd7763 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Mon, 12 Feb 2024 22:24:22 +0100 Subject: [PATCH 06/22] configure.ac, tests/Makefile.am: define CPPUNIT_NUT_CXXFLAGS properly Signed-off-by: Jim Klimov --- configure.ac | 4 +++- tests/Makefile.am | 3 +++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 552ea134ac..f1b515dff9 100644 --- a/configure.ac +++ b/configure.ac @@ -3673,7 +3673,6 @@ AC_MSG_RESULT(${have_cppunit}) NUT_REPORT_FEATURE([build C++ tests with CPPUNIT], [${have_cppunit}], [], [HAVE_CPPUNIT], [Define to enable CPPUNIT tests]) -AC_DEFINE_UNQUOTED(CPPUNIT_NUT_CXXFLAGS, $CPPUNIT_NUT_CXXFLAGS, [Compiler flags for cppunit tests]) AC_MSG_CHECKING(whether to install Augeas configuration-management lenses) AC_ARG_WITH(augeas-lenses-dir, @@ -4724,6 +4723,9 @@ AS_CASE(["${nut_with_debuginfo_CXX}"], AC_MSG_RESULT(["C: ${nut_with_debuginfo_C}; C++: ${nut_with_debuginfo_CXX}"]) +dnl Only in the end, do you understand... +AC_SUBST(CPPUNIT_NUT_CXXFLAGS) + AC_MSG_NOTICE([Generating "data" files from templates, see below for executable scripts]) AC_CONFIG_FILES([ clients/Makefile diff --git a/tests/Makefile.am b/tests/Makefile.am index 8ddb86af43..4d825159a8 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -21,6 +21,9 @@ CLEANFILES = *.trs *.log AM_CFLAGS = -I$(top_srcdir)/include -I$(top_srcdir)/drivers AM_CXXFLAGS = -I$(top_srcdir)/include +# Compiler flags for cppunit tests +CPPUNIT_NUT_CXXFLAGS = @CPPUNIT_NUT_CXXFLAGS@ + check_PROGRAMS = $(TESTS) check_SCRIPTS = From 373b10c09172e7175695f4e5973194f6d5c2d7b1 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Tue, 13 Feb 2024 11:01:42 +0100 Subject: [PATCH 07/22] configure.ac: allow to --enable-cppunit=force for dev-testing Signed-off-by: Jim Klimov --- configure.ac | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index f1b515dff9..da6db1285b 100644 --- a/configure.ac +++ b/configure.ac @@ -3664,10 +3664,15 @@ return res ? 0 : 1; dnl # By default keep the originally detected have_cppunit value AC_MSG_CHECKING(for impact from --enable-cppunit option - should we build cppunit tests?) AC_ARG_ENABLE(cppunit, - [AS_HELP_STRING([--enable-cppunit], [enable CPPUNIT tests for C++ bindings])], + [AS_HELP_STRING([--enable-cppunit], [enable CPPUNIT tests for C++ bindings (yes, no, force, auto)])], [AS_CASE(["${enableval}"], + ["force"], [AS_IF([test x"${have_cppunit}" = xyes], [], [ + AC_MSG_WARN([--with-cppunit=yes can not be satisfied, but developer asked for it]) + have_cppunit=yes + ])], ["yes"], [AS_IF([test x"${have_cppunit}" = xyes], [], [AC_MSG_ERROR([--with-cppunit=yes can not be satisfied])])], ["no"], [have_cppunit=no] + dnl # "auto" and other values keep what was detected (or not) )]) AC_MSG_RESULT(${have_cppunit}) From d6852c28b3d03cbcad80d7649d245dbbb88bfa95 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Tue, 13 Feb 2024 16:31:08 +0100 Subject: [PATCH 08/22] configure.ac: avoid autoconf-added debug/optimization settings Signed-off-by: Jim Klimov --- configure.ac | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/configure.ac b/configure.ac index da6db1285b..5e4f00e35b 100644 --- a/configure.ac +++ b/configure.ac @@ -591,6 +591,11 @@ AC_CONFIG_LIBOBJ_DIR([common]) dnl +------------------------------------------------------------------- +CFLAGS_BEFORE_ACPROG="${CFLAGS-}" +CXXFLAGS_BEFORE_ACPROG="${CXXFLAGS-}" +AC_MSG_NOTICE([CFLAGS_BEFORE_ACPROG="${CFLAGS-}"]) +AC_MSG_NOTICE([CXXFLAGS_BEFORE_ACPROG="${CXXFLAGS-}"]) + dnl AC_PROG_CC dnl Macro AC_PROG_CC_C99 is obsolete; use AC_PROG_CC dnl Note that NUT does not support building with C89 anyway @@ -600,6 +605,13 @@ AM_PROG_CC_C_O AC_PROG_CPP AC_PROG_CXX AC_PROG_CXX_C_O + +AC_MSG_NOTICE([CFLAGS_AFTER_ACPROG="${CFLAGS-}"]) +AC_MSG_NOTICE([CXXFLAGS_AFTER_ACPROG="${CXXFLAGS-}"]) + +dnl CFLAGS_BEFORE_ACPROG=${CFLAGS-} +dnl CXXFLAGS_BEFORE_ACPROG=${CXXFLAGS-} + AC_PROG_INSTALL AC_PROG_MKDIR_P AC_PROG_LN_S From 5e157bd1ca7dc28831e9dcb6110c3e6faf5f69fb Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Wed, 14 Feb 2024 08:53:26 +0100 Subject: [PATCH 09/22] configure.ac: rearrange mangling of CFLAGS and CXXFLAGS by autotools defaults (optimizations/debug barged in) and our script Signed-off-by: Jim Klimov --- configure.ac | 58 +++++++++++++++++++++++++++++++--------------------- 1 file changed, 35 insertions(+), 23 deletions(-) diff --git a/configure.ac b/configure.ac index 5e4f00e35b..f9deffaf26 100644 --- a/configure.ac +++ b/configure.ac @@ -110,6 +110,22 @@ dnl is known to suffice): m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])], [AC_MSG_NOTICE([Silent Rules feature not defined in this automake version, skipped])]) +dnl +------------------------------------------------------------------- + +dnl Avoid "polluting" CFLAGS etc. with auto-settings like "-g -O2" +dnl at least if we intend to tune --with-debuginfo anyway +CFLAGS_ORIG="${CFLAGS-}" +CXXFLAGS_ORIG="${CXXFLAGS-}" + +CFLAGS_BEFORE_ACPROG="${CFLAGS-}" +CXXFLAGS_BEFORE_ACPROG="${CXXFLAGS-}" +AC_MSG_NOTICE([CFLAGS_BEFORE_ACPROG="${CFLAGS-}"]) +AC_MSG_NOTICE([CXXFLAGS_BEFORE_ACPROG="${CXXFLAGS-}"]) + +dnl # LEGACY DEFAULT # CFLAGS=${CFLAGS-"-O"} +CFLAGS="${CFLAGS- }" +CXXFLAGS="${CXXFLAGS- }" + dnl we need Autoconf 2.61 or better to enable features of Posix that are extensions to C dnl (and actually 2.64 or better for m4/ax_check_compile_flag.m4 when it is sourced) dnl UPDATE: As tested on CentOS 6, its "autoconf-2.63-5.1.el6.noarch" also suffices. @@ -117,14 +133,33 @@ dnl But OpenBSD 6.5 requires autoconf-2.65 and automake-1.13 or newer... AC_MSG_CHECKING(for autoconf macro to enable system extensions) m4_version_prereq(2.61, [ AC_MSG_RESULT(yes) + dnl Causes calls to ac_prog stuff, so dittoed below if "no" AC_USE_SYSTEM_EXTENSIONS ], [ AC_MSG_RESULT(no) + AC_PROG_CC ]) AC_PREREQ([2.63]) dnl #AC_PREREQ([2.64]) +dnl Macro AC_PROG_CC_C99 is obsolete; use AC_PROG_CC +dnl Note that NUT does not support building with C89 anyway +dnl AC_PROG_CC_C99 +dnl Needed for per-target flags +AM_PROG_CC_C_O +AC_PROG_CPP +AC_PROG_CXX +AC_PROG_CXX_C_O + +AC_MSG_NOTICE([CFLAGS_AFTER_ACPROG="${CFLAGS-}"]) +AC_MSG_NOTICE([CXXFLAGS_AFTER_ACPROG="${CXXFLAGS-}"]) + +dnl CFLAGS_BEFORE_ACPROG=${CFLAGS-} +dnl CXXFLAGS_BEFORE_ACPROG=${CXXFLAGS-} + +dnl +------------------------------------------------------------------- + dnl Use "./configure --enable-maintainer-mode" to keep Makefile.in and Makefile dnl in sync after Git updates. AM_MAINTAINER_MODE @@ -172,8 +207,6 @@ test "${prefix}" = "NONE" && prefix="${ac_default_prefix}" test "${exec_prefix}" = "NONE" && exec_prefix='${prefix}' dnl # LEGACY DEFAULT # CFLAGS=${CFLAGS-"-O"} -CFLAGS_ORIG="${CFLAGS-}" -CXXFLAGS_ORIG="${CXXFLAGS-}" dnl Note: for practical and platform-independent use, see AX_REALPATH macro AC_CHECK_PROGS([REALPATH], [realpath], []) @@ -591,27 +624,6 @@ AC_CONFIG_LIBOBJ_DIR([common]) dnl +------------------------------------------------------------------- -CFLAGS_BEFORE_ACPROG="${CFLAGS-}" -CXXFLAGS_BEFORE_ACPROG="${CXXFLAGS-}" -AC_MSG_NOTICE([CFLAGS_BEFORE_ACPROG="${CFLAGS-}"]) -AC_MSG_NOTICE([CXXFLAGS_BEFORE_ACPROG="${CXXFLAGS-}"]) - -dnl AC_PROG_CC -dnl Macro AC_PROG_CC_C99 is obsolete; use AC_PROG_CC -dnl Note that NUT does not support building with C89 anyway -dnl AC_PROG_CC_C99 -dnl Needed for per-target flags -AM_PROG_CC_C_O -AC_PROG_CPP -AC_PROG_CXX -AC_PROG_CXX_C_O - -AC_MSG_NOTICE([CFLAGS_AFTER_ACPROG="${CFLAGS-}"]) -AC_MSG_NOTICE([CXXFLAGS_AFTER_ACPROG="${CXXFLAGS-}"]) - -dnl CFLAGS_BEFORE_ACPROG=${CFLAGS-} -dnl CXXFLAGS_BEFORE_ACPROG=${CXXFLAGS-} - AC_PROG_INSTALL AC_PROG_MKDIR_P AC_PROG_LN_S From 803fb205d9af1fbd97d96580edf5f57f59b5777d Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Wed, 14 Feb 2024 09:51:43 +0100 Subject: [PATCH 10/22] configure.ac: do not mangle C(XX)FLAGS added by autotools; just stash and consult original values when deciding --with-debuginfo behavior Signed-off-by: Jim Klimov --- configure.ac | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/configure.ac b/configure.ac index f9deffaf26..24fd861704 100644 --- a/configure.ac +++ b/configure.ac @@ -112,20 +112,17 @@ m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])], dnl +------------------------------------------------------------------- -dnl Avoid "polluting" CFLAGS etc. with auto-settings like "-g -O2" -dnl at least if we intend to tune --with-debuginfo anyway +dnl Help avoid "polluting" CFLAGS etc. with auto-settings like "-g -O2" +dnl at least if we intend to tune --with-debuginfo anyway (where we check +dnl if the caller asked for specific optimizations). Following some +dnl experimentation, we do not want to actually mangle the flags provided +dnl by autoconf - for GCC at least, the rightmost mentions of conflicting +dnl flags on command line win. We just want to know when it is okay to add ours. CFLAGS_ORIG="${CFLAGS-}" CXXFLAGS_ORIG="${CXXFLAGS-}" - -CFLAGS_BEFORE_ACPROG="${CFLAGS-}" -CXXFLAGS_BEFORE_ACPROG="${CXXFLAGS-}" AC_MSG_NOTICE([CFLAGS_BEFORE_ACPROG="${CFLAGS-}"]) AC_MSG_NOTICE([CXXFLAGS_BEFORE_ACPROG="${CXXFLAGS-}"]) -dnl # LEGACY DEFAULT # CFLAGS=${CFLAGS-"-O"} -CFLAGS="${CFLAGS- }" -CXXFLAGS="${CXXFLAGS- }" - dnl we need Autoconf 2.61 or better to enable features of Posix that are extensions to C dnl (and actually 2.64 or better for m4/ax_check_compile_flag.m4 when it is sourced) dnl UPDATE: As tested on CentOS 6, its "autoconf-2.63-5.1.el6.noarch" also suffices. @@ -155,9 +152,6 @@ AC_PROG_CXX_C_O AC_MSG_NOTICE([CFLAGS_AFTER_ACPROG="${CFLAGS-}"]) AC_MSG_NOTICE([CXXFLAGS_AFTER_ACPROG="${CXXFLAGS-}"]) -dnl CFLAGS_BEFORE_ACPROG=${CFLAGS-} -dnl CXXFLAGS_BEFORE_ACPROG=${CXXFLAGS-} - dnl +------------------------------------------------------------------- dnl Use "./configure --enable-maintainer-mode" to keep Makefile.in and Makefile @@ -4698,10 +4692,10 @@ dnl Some binaries, like CPPUNIT tests, have similar flags already added AC_MSG_CHECKING([whether to enable debug info in all NUT binaries]) nut_with_debuginfo_C="${nut_with_debuginfo}" nut_with_debuginfo_CXX="${nut_with_debuginfo}" -AS_CASE(["${CFLAGS}"], +AS_CASE(["${CFLAGS_ORIG}"], [*-O*|*-g*], [ AS_IF([test x"${nut_with_debuginfo_C}" = xauto], [ - nut_with_debuginfo_C="Related settings already specified by caller or detected CFLAGS, not changing anything" + nut_with_debuginfo_C="Related settings already specified by caller CFLAGS, not changing anything" ]) ], [ dnl No competing options are provided @@ -4710,10 +4704,10 @@ AS_CASE(["${CFLAGS}"], [no], [nut_with_debuginfo_C="legacy"]) ]) -AS_CASE(["${CXXFLAGS}"], +AS_CASE(["${CXXFLAGS_ORIG}"], [*-O*|*-g*], [ AS_IF([test x"${nut_with_debuginfo_CXX}" = xauto], [ - nut_with_debuginfo_CXX="Related settings already specified by caller or detected CXXFLAGS, not changing anything" + nut_with_debuginfo_CXX="Related settings already specified by caller CXXFLAGS, not changing anything" ]) ], [ dnl No competing options are provided @@ -4740,6 +4734,7 @@ AS_CASE(["${nut_with_debuginfo_CXX}"], AS_IF([test "x$CLANGXX" = xyes -o "x$GXX" = xyes], [ dnl Where we can enable debug, minimize the optimizations CXXFLAGS="${CXXFLAGS} -O0 -g3 -gdwarf-2" + dnl Use same settings for CPPUNIT tests (they bump their own by default) CPPUNIT_NUT_CXXFLAGS="" ],[nut_with_debuginfo_CXX="Unknown C++ compiler, not adding options"] )], From b6460377d81afa8da06350bb352e7135de5e7f40 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Wed, 14 Feb 2024 09:53:19 +0100 Subject: [PATCH 11/22] configure.ac: avoid needless quoting in AC_MSG_RESULT() printouts Signed-off-by: Jim Klimov --- configure.ac | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/configure.ac b/configure.ac index 24fd861704..36efad445e 100644 --- a/configure.ac +++ b/configure.ac @@ -1629,7 +1629,7 @@ AC_ARG_WITH(all, dnl # if test -z "${with_nut_monitor}"; then with_nut_monitor="${withval}"; fi fi - AC_MSG_RESULT("${withval}") + AC_MSG_RESULT([${withval}]) else AC_MSG_RESULT(not given) fi @@ -4316,7 +4316,7 @@ AS_CASE(["${nut_enable_warnings}"], nut_enable_warnings="no" ] ) -AC_MSG_RESULT(["${nut_enable_warnings}"]) +AC_MSG_RESULT([${nut_enable_warnings}]) dnl # Nothing special for gcc - we tend to survive it with GNU standard >= 99 dnl # and fail with strict C standard. Suggestions welcome for "gcc-hard" to @@ -4452,7 +4452,7 @@ AS_CASE(["${nut_enable_Werror}"], CXXFLAGS="${CXXFLAGS} -Wno-error" ] ) -AC_MSG_RESULT(["${nut_enable_Werror}"]) +AC_MSG_RESULT([${nut_enable_Werror}]) dnl Some compilers (e.g. older clang-3.4) have issues with built-in methods dnl that are implemented as macros in system headers -- but only for some @@ -4584,7 +4584,8 @@ AS_IF([test -n "${ac_abs_top_builddir}" && test -d "${ac_abs_top_builddir}"], TOP_BUILDDIR="`cd "$TOP_BUILDDIR" && pwd`" || AC_MSG_ERROR([Can not detect TOP_BUILDDIR])] )] ) -AC_MSG_RESULT(["${TOP_BUILDDIR}"]) +dnl Quoted in case someone copy-pastes this path and it has whitespaces: +AC_MSG_RESULT(['${TOP_BUILDDIR}']) ABS_TOP_BUILDDIR="`cd "${TOP_BUILDDIR}" && pwd`" || AC_MSG_ERROR([Can not detect ABS_TOP_BUILDDIR]) ABS_TOP_SRCDIR="`cd "${abs_srcdir}" && pwd`" || AC_MSG_ERROR([Can not detect ABS_TOP_SRCDIR]) @@ -4745,7 +4746,7 @@ AS_CASE(["${nut_with_debuginfo_CXX}"], ] ) -AC_MSG_RESULT(["C: ${nut_with_debuginfo_C}; C++: ${nut_with_debuginfo_CXX}"]) +AC_MSG_RESULT([C: ${nut_with_debuginfo_C}; C++: ${nut_with_debuginfo_CXX}]) dnl Only in the end, do you understand... AC_SUBST(CPPUNIT_NUT_CXXFLAGS) From 53dba3143f16896522eeac44180bc56f6ebb58a0 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Wed, 14 Feb 2024 10:01:05 +0100 Subject: [PATCH 12/22] configure.ac: fix typo in shell test Signed-off-by: Jim Klimov --- configure.ac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 36efad445e..cc857db58a 100644 --- a/configure.ac +++ b/configure.ac @@ -4719,7 +4719,7 @@ AS_CASE(["${CXXFLAGS_ORIG}"], AS_CASE(["${nut_with_debuginfo_C}"], [yes], [ - AS_IF([test x"${CLANGCC}" = x"yes" -o test x"${GCC}" = x"yes"], [ + AS_IF([test x"${CLANGCC}" = x"yes" -o x"${GCC}" = x"yes"], [ CFLAGS="${CFLAGS} -O0 -g3 -gdwarf-2" ],[nut_with_debuginfo_C="Unknown C compiler, not adding options"] )], From a8a28e19ace5ee2b44bd21a015b079ae6620a91a Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Wed, 14 Feb 2024 10:16:55 +0100 Subject: [PATCH 13/22] configure.ac: hide C(XX)FLAGS_(BEFORE|AFTER)_ACPROG tracing printouts; move "LEGACY DEFAULT FALLBACK" CFLAGS to the same block where we check AC_PROG_C* Signed-off-by: Jim Klimov --- configure.ac | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/configure.ac b/configure.ac index cc857db58a..b4882a33d0 100644 --- a/configure.ac +++ b/configure.ac @@ -120,8 +120,8 @@ dnl by autoconf - for GCC at least, the rightmost mentions of conflicting dnl flags on command line win. We just want to know when it is okay to add ours. CFLAGS_ORIG="${CFLAGS-}" CXXFLAGS_ORIG="${CXXFLAGS-}" -AC_MSG_NOTICE([CFLAGS_BEFORE_ACPROG="${CFLAGS-}"]) -AC_MSG_NOTICE([CXXFLAGS_BEFORE_ACPROG="${CXXFLAGS-}"]) +dnl AC_MSG_NOTICE([CFLAGS_BEFORE_ACPROG="${CFLAGS-}"]) +dnl AC_MSG_NOTICE([CXXFLAGS_BEFORE_ACPROG="${CXXFLAGS-}"]) dnl we need Autoconf 2.61 or better to enable features of Posix that are extensions to C dnl (and actually 2.64 or better for m4/ax_check_compile_flag.m4 when it is sourced) @@ -149,8 +149,14 @@ AC_PROG_CPP AC_PROG_CXX AC_PROG_CXX_C_O -AC_MSG_NOTICE([CFLAGS_AFTER_ACPROG="${CFLAGS-}"]) -AC_MSG_NOTICE([CXXFLAGS_AFTER_ACPROG="${CXXFLAGS-}"]) +dnl AC_MSG_NOTICE([CFLAGS_AFTER_ACPROG="${CFLAGS-}"]) +dnl AC_MSG_NOTICE([CXXFLAGS_AFTER_ACPROG="${CXXFLAGS-}"]) + +dnl # LEGACY DEFAULT FALLBACK which NUT had since 2005 or before: +dnl # if autoconf does not set any options, use default/moderate optimizations +CFLAGS=${CFLAGS-"-O"} +dnl # Not so far a legacy, added for consistency in 2024 :) +CXXFLAGS=${CXXFLAGS-"-O"} dnl +------------------------------------------------------------------- @@ -200,8 +206,6 @@ dnl Fix this early so we can expand with eval later test "${prefix}" = "NONE" && prefix="${ac_default_prefix}" test "${exec_prefix}" = "NONE" && exec_prefix='${prefix}' -dnl # LEGACY DEFAULT # CFLAGS=${CFLAGS-"-O"} - dnl Note: for practical and platform-independent use, see AX_REALPATH macro AC_CHECK_PROGS([REALPATH], [realpath], []) From cab13c78eeafcb93c1650344df7b3786794e58cf Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Wed, 14 Feb 2024 10:20:53 +0100 Subject: [PATCH 14/22] configure.ac: add C(XX)FLAGS_ORIG tracing printouts to where we check nut_with_debuginfo Signed-off-by: Jim Klimov --- configure.ac | 2 ++ 1 file changed, 2 insertions(+) diff --git a/configure.ac b/configure.ac index b4882a33d0..2fd3a28a43 100644 --- a/configure.ac +++ b/configure.ac @@ -4694,6 +4694,8 @@ PATH_DURING_CONFIGURE="$PATH" AC_SUBST(PATH_DURING_CONFIGURE) dnl Some binaries, like CPPUNIT tests, have similar flags already added +AC_MSG_NOTICE([CFLAGS_ORIG='${CFLAGS_ORIG}']) +AC_MSG_NOTICE([CXXFLAGS_ORIG='${CXXFLAGS_ORIG}']) AC_MSG_CHECKING([whether to enable debug info in all NUT binaries]) nut_with_debuginfo_C="${nut_with_debuginfo}" nut_with_debuginfo_CXX="${nut_with_debuginfo}" From 301d119be970b1f7bb1ea7e6bb95452bb8198632 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Wed, 14 Feb 2024 10:31:19 +0100 Subject: [PATCH 15/22] configure.ac: move stashing of CFLAGS_ORIG/CXXFLAGS_ORIG higher in the script; only do it if they are not yet set (and do set them if re-entering for an in-place build) Signed-off-by: Jim Klimov --- configure.ac | 38 ++++++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/configure.ac b/configure.ac index 2fd3a28a43..4ea6e8b842 100644 --- a/configure.ac +++ b/configure.ac @@ -2,6 +2,20 @@ dnl +------------------------------------------------------------------+ dnl | Network UPS Tools: configure.ac | dnl +------------------------------------------------------------------+ +dnl +------------------------------------------------------------------- +dnl Help avoid "polluting" CFLAGS etc. with auto-settings like "-g -O2" +dnl at least if we intend to tune --with-debuginfo anyway (where we check +dnl if the caller asked for specific optimizations). Following some +dnl experimentation, we do not want to actually mangle the flags provided +dnl by autoconf - for GCC at least, the rightmost mentions of conflicting +dnl flags on command line win. We just want to know when it is okay to add +dnl ours. It seems these copies must be stashed as early as possible. +dnl It may be poorly compatible with "in-place" build setup though; +dnl trying some tricks around that. +test -n "${CFLAGS_ORIG-}" || CFLAGS_ORIG="${CFLAGS-}" +test -n "${CXXFLAGS_ORIG-}" || CXXFLAGS_ORIG="${CXXFLAGS-}" +dnl +------------------------------------------------------------------- + dnl NUT version number is defined here, with a Git suffixed macro like dnl NUT_VERSION_MACRO "2.7.4-2838-gdfc3ac08" dnl in include/nut_version.h (generated by make) @@ -111,22 +125,12 @@ m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])], [AC_MSG_NOTICE([Silent Rules feature not defined in this automake version, skipped])]) dnl +------------------------------------------------------------------- - -dnl Help avoid "polluting" CFLAGS etc. with auto-settings like "-g -O2" -dnl at least if we intend to tune --with-debuginfo anyway (where we check -dnl if the caller asked for specific optimizations). Following some -dnl experimentation, we do not want to actually mangle the flags provided -dnl by autoconf - for GCC at least, the rightmost mentions of conflicting -dnl flags on command line win. We just want to know when it is okay to add ours. -CFLAGS_ORIG="${CFLAGS-}" -CXXFLAGS_ORIG="${CXXFLAGS-}" -dnl AC_MSG_NOTICE([CFLAGS_BEFORE_ACPROG="${CFLAGS-}"]) -dnl AC_MSG_NOTICE([CXXFLAGS_BEFORE_ACPROG="${CXXFLAGS-}"]) - dnl we need Autoconf 2.61 or better to enable features of Posix that are extensions to C dnl (and actually 2.64 or better for m4/ax_check_compile_flag.m4 when it is sourced) dnl UPDATE: As tested on CentOS 6, its "autoconf-2.63-5.1.el6.noarch" also suffices. dnl But OpenBSD 6.5 requires autoconf-2.65 and automake-1.13 or newer... +dnl AC_MSG_NOTICE([CFLAGS_BEFORE_ACPROG="${CFLAGS-}"]) +dnl AC_MSG_NOTICE([CXXFLAGS_BEFORE_ACPROG="${CXXFLAGS-}"]) AC_MSG_CHECKING(for autoconf macro to enable system extensions) m4_version_prereq(2.61, [ AC_MSG_RESULT(yes) @@ -607,11 +611,21 @@ AS_IF([test x"$nut_enable_inplace_runtime" = xyes -a x"${NUT_VERSION_DEPLOYED-}" NUT_VERSION_DEPLOYED="" ]) export NUT_VERSION_DEPLOYED + dnl # Avoid replacement after re-entering: + test -n "${CFLAGS_ORIG-}" || CFLAGS_ORIG=" " + test -n "${CXXFLAGS_ORIG-}" || CXXFLAGS_ORIG=" " + export CFLAGS_ORIG + export CXXFLAGS_ORIG eval exec "$0" $CONFIG_FLAGS_DEPLOYED $CONFIG_FLAGS --disable-inplace-runtime ],[ AC_MSG_NOTICE([No CONFIG_FLAGS were reported or discovered from existing NUT deployment (if any); restarting script for a clean run]) NUT_VERSION_DEPLOYED="" export NUT_VERSION_DEPLOYED + dnl # Avoid replacement after re-entering: + test -n "${CFLAGS_ORIG-}" || CFLAGS_ORIG=" " + test -n "${CXXFLAGS_ORIG-}" || CXXFLAGS_ORIG=" " + export CFLAGS_ORIG + export CXXFLAGS_ORIG AC_MSG_NOTICE([exec "$0" $CONFIG_FLAGS --disable-inplace-runtime]) eval exec "$0" $CONFIG_FLAGS --disable-inplace-runtime ]) From a4a75813e120c210ceec284b1b84bf685bd68b5b Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Wed, 14 Feb 2024 10:38:59 +0100 Subject: [PATCH 16/22] configure.ac: rename C(XX)FLAGS_ORIG to CONFIG_C(XX)FLAGS to avoid conflict with m4 scripts and to maintain similarly to CONFIG_FLAGS Signed-off-by: Jim Klimov --- configure.ac | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/configure.ac b/configure.ac index 4ea6e8b842..7282baee3b 100644 --- a/configure.ac +++ b/configure.ac @@ -12,8 +12,8 @@ dnl flags on command line win. We just want to know when it is okay to add dnl ours. It seems these copies must be stashed as early as possible. dnl It may be poorly compatible with "in-place" build setup though; dnl trying some tricks around that. -test -n "${CFLAGS_ORIG-}" || CFLAGS_ORIG="${CFLAGS-}" -test -n "${CXXFLAGS_ORIG-}" || CXXFLAGS_ORIG="${CXXFLAGS-}" +test -n "${CONFIG_CFLAGS-}" || CONFIG_CFLAGS="${CFLAGS-}" +test -n "${CONFIG_CXXFLAGS-}" || CONFIG_CXXFLAGS="${CXXFLAGS-}" dnl +------------------------------------------------------------------- dnl NUT version number is defined here, with a Git suffixed macro like @@ -612,20 +612,20 @@ AS_IF([test x"$nut_enable_inplace_runtime" = xyes -a x"${NUT_VERSION_DEPLOYED-}" ]) export NUT_VERSION_DEPLOYED dnl # Avoid replacement after re-entering: - test -n "${CFLAGS_ORIG-}" || CFLAGS_ORIG=" " - test -n "${CXXFLAGS_ORIG-}" || CXXFLAGS_ORIG=" " - export CFLAGS_ORIG - export CXXFLAGS_ORIG + test -n "${CONFIG_CFLAGS-}" || CONFIG_CFLAGS=" " + test -n "${CONFIG_CXXFLAGS-}" || CONFIG_CXXFLAGS=" " + export CONFIG_CFLAGS + export CONFIG_CXXFLAGS eval exec "$0" $CONFIG_FLAGS_DEPLOYED $CONFIG_FLAGS --disable-inplace-runtime ],[ AC_MSG_NOTICE([No CONFIG_FLAGS were reported or discovered from existing NUT deployment (if any); restarting script for a clean run]) NUT_VERSION_DEPLOYED="" export NUT_VERSION_DEPLOYED dnl # Avoid replacement after re-entering: - test -n "${CFLAGS_ORIG-}" || CFLAGS_ORIG=" " - test -n "${CXXFLAGS_ORIG-}" || CXXFLAGS_ORIG=" " - export CFLAGS_ORIG - export CXXFLAGS_ORIG + test -n "${CONFIG_CFLAGS-}" || CONFIG_CFLAGS=" " + test -n "${CONFIG_CXXFLAGS-}" || CONFIG_CXXFLAGS=" " + export CONFIG_CFLAGS + export CONFIG_CXXFLAGS AC_MSG_NOTICE([exec "$0" $CONFIG_FLAGS --disable-inplace-runtime]) eval exec "$0" $CONFIG_FLAGS --disable-inplace-runtime ]) @@ -4708,12 +4708,12 @@ PATH_DURING_CONFIGURE="$PATH" AC_SUBST(PATH_DURING_CONFIGURE) dnl Some binaries, like CPPUNIT tests, have similar flags already added -AC_MSG_NOTICE([CFLAGS_ORIG='${CFLAGS_ORIG}']) -AC_MSG_NOTICE([CXXFLAGS_ORIG='${CXXFLAGS_ORIG}']) +AC_MSG_NOTICE([CONFIG_CFLAGS='${CONFIG_CFLAGS}']) +AC_MSG_NOTICE([CONFIG_CXXFLAGS='${CONFIG_CXXFLAGS}']) AC_MSG_CHECKING([whether to enable debug info in all NUT binaries]) nut_with_debuginfo_C="${nut_with_debuginfo}" nut_with_debuginfo_CXX="${nut_with_debuginfo}" -AS_CASE(["${CFLAGS_ORIG}"], +AS_CASE(["${CONFIG_CFLAGS}"], [*-O*|*-g*], [ AS_IF([test x"${nut_with_debuginfo_C}" = xauto], [ nut_with_debuginfo_C="Related settings already specified by caller CFLAGS, not changing anything" @@ -4725,7 +4725,7 @@ AS_CASE(["${CFLAGS_ORIG}"], [no], [nut_with_debuginfo_C="legacy"]) ]) -AS_CASE(["${CXXFLAGS_ORIG}"], +AS_CASE(["${CONFIG_CXXFLAGS}"], [*-O*|*-g*], [ AS_IF([test x"${nut_with_debuginfo_CXX}" = xauto], [ nut_with_debuginfo_CXX="Related settings already specified by caller CXXFLAGS, not changing anything" @@ -4746,7 +4746,7 @@ AS_CASE(["${nut_with_debuginfo_C}"], dnl # [no]: By default we do not add debug info [legacy], [ dnl # Apply legacy defaults if no flags were specified by caller - AS_IF([test x"${CFLAGS_ORIG}" = x], [CFLAGS="-O ${CFLAGS}"]) + AS_IF([test x"${CONFIG_CFLAGS}" = x], [CFLAGS="-O ${CFLAGS}"]) ] ) @@ -4762,7 +4762,7 @@ AS_CASE(["${nut_with_debuginfo_CXX}"], dnl # [no]: By default we do not add debug info [legacy], [ dnl # Apply legacy defaults if no flags were specified by caller - AS_IF([test x"${CXXFLAGS_ORIG}" = x], [CXXFLAGS="-O ${CXXFLAGS}"]) + AS_IF([test x"${CONFIG_CXXFLAGS}" = x], [CXXFLAGS="-O ${CXXFLAGS}"]) ] ) From 52665149a5fbae455462da742fe3caddd8afe40c Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Wed, 14 Feb 2024 10:40:27 +0100 Subject: [PATCH 17/22] configure.ac: move CONFIG_C(XX)FLAGS definition back down to where we check AC_PROG_C* macros Signed-off-by: Jim Klimov --- configure.ac | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/configure.ac b/configure.ac index 7282baee3b..464187f40e 100644 --- a/configure.ac +++ b/configure.ac @@ -2,20 +2,6 @@ dnl +------------------------------------------------------------------+ dnl | Network UPS Tools: configure.ac | dnl +------------------------------------------------------------------+ -dnl +------------------------------------------------------------------- -dnl Help avoid "polluting" CFLAGS etc. with auto-settings like "-g -O2" -dnl at least if we intend to tune --with-debuginfo anyway (where we check -dnl if the caller asked for specific optimizations). Following some -dnl experimentation, we do not want to actually mangle the flags provided -dnl by autoconf - for GCC at least, the rightmost mentions of conflicting -dnl flags on command line win. We just want to know when it is okay to add -dnl ours. It seems these copies must be stashed as early as possible. -dnl It may be poorly compatible with "in-place" build setup though; -dnl trying some tricks around that. -test -n "${CONFIG_CFLAGS-}" || CONFIG_CFLAGS="${CFLAGS-}" -test -n "${CONFIG_CXXFLAGS-}" || CONFIG_CXXFLAGS="${CXXFLAGS-}" -dnl +------------------------------------------------------------------- - dnl NUT version number is defined here, with a Git suffixed macro like dnl NUT_VERSION_MACRO "2.7.4-2838-gdfc3ac08" dnl in include/nut_version.h (generated by make) @@ -117,6 +103,18 @@ If this happens, please retry with GNU C/C++ language mode options instead. ])] ) +dnl +------------------------------------------------------------------- +dnl Help avoid "polluting" CFLAGS etc. with auto-settings like "-g -O2" +dnl at least if we intend to tune --with-debuginfo anyway (where we check +dnl if the caller asked for specific optimizations). Following some +dnl experimentation, we do not want to actually mangle the flags provided +dnl by autoconf - for GCC at least, the rightmost mentions of conflicting +dnl flags on command line win. We just want to know when it is okay to add +dnl ours. They may be inherited from "in-place" build setup though. +test -n "${CONFIG_CFLAGS-}" || CONFIG_CFLAGS="${CFLAGS-}" +test -n "${CONFIG_CXXFLAGS-}" || CONFIG_CXXFLAGS="${CXXFLAGS-}" +dnl +------------------------------------------------------------------- + dnl Default to `configure --enable-silent-rules` or `make V=1` for details? dnl This feature seems to require automake-1.13 or newer (1.11+ by other info) dnl On very old systems can comment it away with little loss (then automake-1.10 From d5e5a5182df4efd6fa5a957e299afb4948951c25 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Wed, 14 Feb 2024 10:51:51 +0100 Subject: [PATCH 18/22] m4/nut_report_feature.m4: adjust NUT_REPORT_COMPILERS to note about debug optimizations Signed-off-by: Jim Klimov --- m4/nut_report_feature.m4 | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/m4/nut_report_feature.m4 b/m4/nut_report_feature.m4 index dd2666cd58..02ff814033 100644 --- a/m4/nut_report_feature.m4 +++ b/m4/nut_report_feature.m4 @@ -129,6 +129,23 @@ AC_DEFUN([NUT_REPORT_COMPILERS], echo "NUT Compiler settings:" echo "----------------------" echo "" + if test x"${nut_with_debuginfo_C}" = x"yes" -o x"${nut_with_debuginfo_CXX}" = x"yes" ; then + printf 'NOTE: Settings for ' + if test x"${nut_with_debuginfo_C}" = x"yes" ; then + printf 'C ' + fi + if test x"${nut_with_debuginfo_C}${nut_with_debuginfo_CXX}" = x"yesyes" ; then + printf 'and ' + fi + if test x"${nut_with_debuginfo_CXX}" = x"yes" ; then + printf 'C++ ' + fi + printf 'compiler' + if test x"${nut_with_debuginfo_C}${nut_with_debuginfo_CXX}" = x"yesyes" ; then + printf 's' + fi + printf ' are adjusted for debugging (and minimal optimizations)\n\n' + fi printf '* CC \t: %s\n' "$CC" printf '* CFLAGS \t: %s\n' "$CFLAGS" printf '* CXX \t: %s\n' "$CXX" From bf74261e315acabc033b6f9c42be32c74a413900 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Wed, 14 Feb 2024 10:15:24 +0100 Subject: [PATCH 19/22] NEWS.adoc: document "configure --with-debuginfo" possibility [#2310] Signed-off-by: Jim Klimov --- NEWS.adoc | 5 +++++ docs/nut.dict | 4 +++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/NEWS.adoc b/NEWS.adoc index d208096758..4876dab631 100644 --- a/NEWS.adoc +++ b/NEWS.adoc @@ -82,6 +82,11 @@ https://github.com/networkupstools/nut/milestone/10 building NUT without it. [#2262] * Builds requested with a specific C/C++ language standard revision via `CFLAGS` and `CXXFLAGS` should again be honoured. [PR #2306] + * Allow requesting detailed debug builds (with disabled optimizations for + binaries to best match the source code) for supported compilers using + `configure` script option `--with-debuginfo`. Note that default autoconf + behavior usually embeds moderate optimizations and debug information on + its own. [PR #2310] - nut-usbinfo.pl, nut-scanner and libnutscan: * Library API version for `libnutscan` was bumped from 2.2.0 to 2.5.0 diff --git a/docs/nut.dict b/docs/nut.dict index b4b6c3b31a..f0feecc9c9 100644 --- a/docs/nut.dict +++ b/docs/nut.dict @@ -1,4 +1,4 @@ -personal_ws-1.1 en 3444 utf-8 +personal_ws-1.1 en 3446 utf-8 AAC AAS ABI @@ -1896,6 +1896,7 @@ dataok datasheet datastale dayofweek +dbgsym dblatex dcd dcn @@ -1906,6 +1907,7 @@ deUNV debian debootstrap debouncing +debuginfo deci decrement decrypt From d60e4aa6e70abdaf8fe4535e64fc5cded08069aa Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Wed, 14 Feb 2024 12:01:58 +0100 Subject: [PATCH 20/22] configure.ac: typo fix (--with-cppunit => --enable-cppunit) in messages Signed-off-by: Jim Klimov --- configure.ac | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/configure.ac b/configure.ac index 464187f40e..fa012165ff 100644 --- a/configure.ac +++ b/configure.ac @@ -3701,10 +3701,10 @@ AC_ARG_ENABLE(cppunit, [AS_HELP_STRING([--enable-cppunit], [enable CPPUNIT tests for C++ bindings (yes, no, force, auto)])], [AS_CASE(["${enableval}"], ["force"], [AS_IF([test x"${have_cppunit}" = xyes], [], [ - AC_MSG_WARN([--with-cppunit=yes can not be satisfied, but developer asked for it]) + AC_MSG_WARN([--enable-cppunit=yes can not be satisfied, but developer asked for it]) have_cppunit=yes ])], - ["yes"], [AS_IF([test x"${have_cppunit}" = xyes], [], [AC_MSG_ERROR([--with-cppunit=yes can not be satisfied])])], + ["yes"], [AS_IF([test x"${have_cppunit}" = xyes], [], [AC_MSG_ERROR([--enable-cppunit=yes can not be satisfied])])], ["no"], [have_cppunit=no] dnl # "auto" and other values keep what was detected (or not) )]) From 99df2b4d1742c0978117835c740910921640924e Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Wed, 14 Feb 2024 12:54:26 +0100 Subject: [PATCH 21/22] configure.ac: to not change nut_with_debuginfo* from "no" to "legacy", leave it strictly as caller asked Recent changes are more careful about the "LEGACY FALLBACK" application. Let users ask for it explicitly though. Signed-off-by: Jim Klimov --- configure.ac | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/configure.ac b/configure.ac index fa012165ff..8c04d64df1 100644 --- a/configure.ac +++ b/configure.ac @@ -4706,6 +4706,8 @@ PATH_DURING_CONFIGURE="$PATH" AC_SUBST(PATH_DURING_CONFIGURE) dnl Some binaries, like CPPUNIT tests, have similar flags already added +dnl We might wipe their specific options below if consistently applying +dnl debug-friendly options to everything AC_MSG_NOTICE([CONFIG_CFLAGS='${CONFIG_CFLAGS}']) AC_MSG_NOTICE([CONFIG_CXXFLAGS='${CONFIG_CXXFLAGS}']) AC_MSG_CHECKING([whether to enable debug info in all NUT binaries]) @@ -4718,9 +4720,7 @@ AS_CASE(["${CONFIG_CFLAGS}"], ]) ], [ dnl No competing options are provided - AS_CASE(["${nut_with_debuginfo_C}"], - [auto], [nut_with_debuginfo_C="yes"], - [no], [nut_with_debuginfo_C="legacy"]) + AS_IF([test x"${nut_with_debuginfo_C}" = xauto], [nut_with_debuginfo_C="yes"]) ]) AS_CASE(["${CONFIG_CXXFLAGS}"], @@ -4730,9 +4730,7 @@ AS_CASE(["${CONFIG_CXXFLAGS}"], ]) ], [ dnl No competing options are provided - AS_CASE(["${nut_with_debuginfo_CXX}"], - [auto], [nut_with_debuginfo_CXX="yes"], - [no], [nut_with_debuginfo_CXX="legacy"]) + AS_IF([test x"${nut_with_debuginfo_CXX}" = xauto], [nut_with_debuginfo_CXX="yes"]) ]) AS_CASE(["${nut_with_debuginfo_C}"], From 651f800ec1f05b402f9d6432dc2ea077d9e63550 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Wed, 14 Feb 2024 12:57:26 +0100 Subject: [PATCH 22/22] configure.ac: fix nut_with_debuginfo*="legacy" to consider flag list snapshots made just after autoconf might have mangled them Signed-off-by: Jim Klimov --- configure.ac | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/configure.ac b/configure.ac index 8c04d64df1..45f4ebcb88 100644 --- a/configure.ac +++ b/configure.ac @@ -151,6 +151,9 @@ AC_PROG_CPP AC_PROG_CXX AC_PROG_CXX_C_O +CFLAGS_AFTER_ACPROG="${CFLAGS-}" +CXXFLAGS_AFTER_ACPROG="${CXXFLAGS-}" + dnl AC_MSG_NOTICE([CFLAGS_AFTER_ACPROG="${CFLAGS-}"]) dnl AC_MSG_NOTICE([CXXFLAGS_AFTER_ACPROG="${CXXFLAGS-}"]) @@ -4741,8 +4744,8 @@ AS_CASE(["${nut_with_debuginfo_C}"], )], dnl # [no]: By default we do not add debug info [legacy], [ - dnl # Apply legacy defaults if no flags were specified by caller - AS_IF([test x"${CONFIG_CFLAGS}" = x], [CFLAGS="-O ${CFLAGS}"]) + dnl # Apply legacy defaults if no flags were specified by caller or detected by autoconf + AS_IF([test x"${CFLAGS_AFTER_ACPROG}" = x], [CFLAGS="-O ${CFLAGS}"]) ] ) @@ -4757,8 +4760,8 @@ AS_CASE(["${nut_with_debuginfo_CXX}"], )], dnl # [no]: By default we do not add debug info [legacy], [ - dnl # Apply legacy defaults if no flags were specified by caller - AS_IF([test x"${CONFIG_CXXFLAGS}" = x], [CXXFLAGS="-O ${CXXFLAGS}"]) + dnl # Apply legacy defaults if no flags were specified by caller or detected by autoconf + AS_IF([test x"${CXXFLAGS_AFTER_ACPROG}" = x], [CXXFLAGS="-O ${CXXFLAGS}"]) ] )