From 72cc8fc41078c65381febce3d549b5a8626351d6 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Wed, 23 Apr 2025 16:32:15 +0200 Subject: [PATCH 1/8] common/common-nut_version.c, common/common.c: evict UPS_VERSION and its consumers into a separate compilation unit [#2097] Signed-off-by: Jim Klimov --- NEWS.adoc | 4 + common/Makefile.am | 40 +++--- common/common-nut_version.c | 270 ++++++++++++++++++++++++++++++++++++ common/common.c | 246 ++------------------------------ 4 files changed, 307 insertions(+), 253 deletions(-) create mode 100644 common/common-nut_version.c diff --git a/NEWS.adoc b/NEWS.adoc index 9b9c4d142d..863904e208 100644 --- a/NEWS.adoc +++ b/NEWS.adoc @@ -41,6 +41,10 @@ https://github.com/networkupstools/nut/milestone/9 - (expected) Bug fixes for fallout possible due to "fightwarn" effort in 2.8.0+ + - Refactored NUT "common" sources to reference `nut_version.h` macros from + a smaller C source file, to minimize the compilation unit size impacted by + development iterations. [issue #2097] + Release notes for NUT 2.8.3 - what's new since 2.8.2 ---------------------------------------------------- diff --git a/common/Makefile.am b/common/Makefile.am index 1ef405a735..364ec298ee 100644 --- a/common/Makefile.am +++ b/common/Makefile.am @@ -39,20 +39,20 @@ libparseconf_la_SOURCES = parseconf.c # be built before anything else... but do depend on its build area: if BUILDING_IN_TREE # No need for symlink hack - common.c: $(top_builddir)/include/nut_version.h + common-nut_version.c: $(top_builddir)/include/nut_version.h else !BUILDING_IN_TREE -# Surprisingly, for some "make" implementations this dependency means -# that the "common.c" required for builds below will be seeked in the +# Surprisingly, for some "make" implementations this dependency means that +# the "common-nut_version.c" required for builds below will be seeked in the # current directory. So for out-of-tree builds like distcheck, we have # to symlink the "real" source to build area. And then when we handle # subsequent dependencies, we already have a filename that "make" now # discovers and is confused about: - common.c: $(top_builddir)/include/nut_version.h $(srcdir)/common.c + common-nut_version.c: $(top_builddir)/include/nut_version.h $(srcdir)/common-nut_version.c @if [ x"$(abs_top_srcdir)" = x"$(abs_top_builddir)" ] || test -s "$@" ; then \ exit 0 ; \ else \ - echo " LN $(top_srcdir)/common/common.c => $@ (relative to `pwd`)" ; \ - ln -s -f "$(top_srcdir)/common/common.c" "$@" ; \ + echo " LN $(top_srcdir)/common/common-nut_version.c => $@ (relative to `pwd`)" ; \ + ln -s -f "$(top_srcdir)/common/common-nut_version.c" "$@" ; \ fi endif !BUILDING_IN_TREE @@ -65,24 +65,28 @@ $(top_builddir)/include/nut_version.h: libcommon_la_SOURCES = state.c str.c upsconf.c libcommonclient_la_SOURCES = state.c str.c -# several other Makefiles include the two helpers common.c str.c (and -# perhaps some other string-related code), so make them a library too; +# several other Makefiles include the three helpers common.c common-nut_version.c str.c +# (and perhaps some other string-related code), so we make them a library too; # note that LTLIBOBJS pulls in snprintf.c contents too. noinst_LTLIBRARIES += libcommonstr.la libcommonstr_la_SOURCES = str.c libcommonstr_la_CFLAGS = $(AM_CFLAGS) -DWITHOUT_LIBSYSTEMD=1 libcommonstr_la_LIBADD = @LTLIBOBJS@ @BSDKVMPROCLIBS@ +COMMON_SRC = \ + common-nut_version.c \ + common.c + if BUILDING_IN_TREE - libcommon_la_SOURCES += common.c - libcommonstr_la_SOURCES += common.c - libcommonclient_la_SOURCES += common.c + libcommon_la_SOURCES += $(COMMON_SRC) + libcommonstr_la_SOURCES += $(COMMON_SRC) + libcommonclient_la_SOURCES += $(COMMON_SRC) else !BUILDING_IN_TREE - nodist_libcommon_la_SOURCES = common.c - nodist_libcommonstr_la_SOURCES = common.c - nodist_libcommonclient_la_SOURCES = common.c - CLEANFILES += $(top_builddir)/common/common.c - BUILT_SOURCES = common.c + nodist_libcommon_la_SOURCES = $(COMMON_SRC) + nodist_libcommonstr_la_SOURCES = $(COMMON_SRC) + nodist_libcommonclient_la_SOURCES = $(COMMON_SRC) + CLEANFILES += $(top_builddir)/common/nut_version.c + BUILT_SOURCES = common-nut_version.c endif !BUILDING_IN_TREE if HAVE_STRPTIME @@ -193,7 +197,9 @@ MAINTAINERCLEANFILES = Makefile.in .dirstamp # NOTE: Do not clean ".deps" in SUBDIRS of the main project, # the root Makefile.am takes care of that! clean-local: - if test -L $(builddir)/common.c || test -h $(builddir)/common.c ; then rm -f $(builddir)/common.c ; fi + if test -L $(builddir)/common-nut_version.c \ + || test -h $(builddir)/common-nut_version.c \ + ; then rm -f $(builddir)/common-nut_version.c ; fi # $(AM_V_at)rm -rf $(builddir)/.deps # Helper for only the enabled libs to get built: diff --git a/common/common-nut_version.c b/common/common-nut_version.c new file mode 100644 index 0000000000..581bc0f282 --- /dev/null +++ b/common/common-nut_version.c @@ -0,0 +1,270 @@ +/* nut_version.c - data and functions regarding just NUT version reporting + (extracted from common.c to minimize the compilation unit + impacted by git metadata changes during development) + + Copyright (C) 2021-2025 Jim Klimov + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#include "common.h" +#include +#include +#include + +#ifndef WIN32 +# include +#else /* WIN32 */ +# include "wincompat.h" +#endif /* WIN32 */ + +/* the reason we define UPS_VERSION as a static string, rather than a + macro, is to make dependency tracking easier (only common.o depends + on nut_version.h), and also to prevent all sources from + having to be recompiled each time the version changes (they only + need to be re-linked). */ +#include "nut_version.h" +const char *UPS_VERSION = NUT_VERSION_MACRO; + +/* privately declare a few things implemented in common.c (this code used + * to be there) */ +extern struct timeval upslog_start; +extern int upslog_flags; +int xbit_test(int val, int flag); + +int banner_is_disabled(void) +{ + static int value = -1; + + if (value < 0) { + char *s = getenv("NUT_QUIET_INIT_BANNER"); + /* Envvar present and empty or true-ish means NUT tool name+version + * banners disabled by the setting: default is enabled (inversed per + * method name) */ + value = 0; + if (s) { + if (*s == '\0' || !strcasecmp(s, "true") || strcmp(s, "1")) { + value = 1; + } + } + } + + return value; +} + +const char *describe_NUT_VERSION_once(void) +{ + static char buf[LARGEBUF]; + static const char *printed = NULL; + + if (printed) + return printed; + + memset(buf, 0, sizeof(buf)); + +#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_UNREACHABLE_CODE +#pragma GCC diagnostic push +#endif +#ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_UNREACHABLE_CODE +#pragma GCC diagnostic ignored "-Wunreachable-code" +#endif +#ifdef __clang__ +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wunreachable-code" +#endif + /* NOTE: Some compilers deduce that macro-based decisions about + * NUT_VERSION_IS_RELEASE make one of codepaths unreachable in + * a particular build. So we pragmatically handwave this away. + */ + if (1 < snprintf(buf, sizeof(buf), + "%s %s%s%s", + NUT_VERSION_MACRO, + NUT_VERSION_IS_RELEASE ? "release" : + (NUT_VERSION_IS_PRERELEASE + ? "(pre-release iteration of " + : "(development iteration after "), + NUT_VERSION_IS_RELEASE ? "" : NUT_VERSION_SEMVER_MACRO, + NUT_VERSION_IS_RELEASE ? "" : ")" + )) { + printed = buf; + } else { + upslogx(LOG_WARNING, "%s: failed to report detailed NUT version", __func__); + printed = UPS_VERSION; + } +#ifdef __clang__ +#pragma clang diagnostic pop +#endif +#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_UNREACHABLE_CODE +#pragma GCC diagnostic pop +#endif + + return printed; +} + +int print_banner_once(const char *prog, int even_if_disabled) +{ + static int printed = 0; + static int ret = -1; + + if (printed) + return ret; + + if (!banner_is_disabled() || even_if_disabled) { + ret = printf("Network UPS Tools %s %s%s\n", + prog, describe_NUT_VERSION_once(), + even_if_disabled == 2 ? "\n" : ""); + fflush(stdout); + if (ret > 0) + printed = 1; + } + + return ret; +} + +void nut_report_config_flags(void) +{ + /* Roughly similar to upslogx() but without the buffer-size limits and + * timestamp/debug-level prefixes. Only printed if debug (any) is on. + * Depending on amount of configuration tunables involved by a particular + * build of NUT, the string can be quite long (over 1KB). + */ +#if 0 + const char *acinit_ver = NULL; +#endif + /* Pass these as variables to avoid warning about never reaching one + * of compiled codepaths: */ + const char *compiler_ver = CC_VERSION; + const char *config_flags = CONFIG_FLAGS; + struct timeval now; + + if (nut_debug_level < 1) + return; + +#if 0 + /* Only report git revision if NUT_VERSION_MACRO in nut_version.h aka + * UPS_VERSION here is remarkably different from PACKAGE_VERSION from + * configure.ac AC_INIT() -- which may be e.g. "2.8.0.1" although some + * distros, especially embedders, tend to place their product IDs here). + * The macro may be that fixed version or refer to git source revision, + * as decided when generating nut_version.h (and if it was re-generated + * in case of rebuilds while developers are locally iterating -- this + * may be disabled for faster local iterations at a cost of a little lie). + */ + if (PACKAGE_VERSION && UPS_VERSION && + (strlen(UPS_VERSION) < 12 || !strstr(UPS_VERSION, PACKAGE_VERSION)) + ) { + /* If UPS_VERSION is too short (so likely a static string + * from configure.ac AC_INIT() -- although some distros, + * especially embedders, tend to place their product IDs here), + * or if PACKAGE_VERSION *is NOT* a substring of it: */ + acinit_ver = PACKAGE_VERSION; +/* + // Triplet that was printed below: + (acinit_ver ? " (release/snapshot of " : ""), + (acinit_ver ? acinit_ver : ""), + (acinit_ver ? ")" : ""), +*/ + } +#endif + + /* NOTE: If changing wording here, keep in sync with configure.ac logic + * looking for CONFIG_FLAGS_DEPLOYED via "configured with flags:" string! + */ + + gettimeofday(&now, NULL); + + if (upslog_start.tv_sec == 0) { + upslog_start = now; + } + + if (upslog_start.tv_usec > now.tv_usec) { + now.tv_usec += 1000000; + now.tv_sec -= 1; + } + + if (xbit_test(upslog_flags, UPSLOG_STDERR)) { + fprintf(stderr, "%4.0f.%06ld\t[D1] Network UPS Tools version %s%s%s%s %s%s\n", + difftime(now.tv_sec, upslog_start.tv_sec), + (long)(now.tv_usec - upslog_start.tv_usec), + describe_NUT_VERSION_once(), + (compiler_ver && *compiler_ver != '\0' ? " built with " : ""), + (compiler_ver && *compiler_ver != '\0' ? compiler_ver : ""), + (compiler_ver && *compiler_ver != '\0' ? " and" : ""), + (config_flags && *config_flags != '\0' ? "configured with flags: " : "configured all by default guesswork"), + (config_flags && *config_flags != '\0' ? config_flags : "") + ); +#ifdef WIN32 + fflush(stderr); +#endif /* WIN32 */ + } + + /* NOTE: May be ignored or truncated by receiver if that syslog server + * (and/or OS sender) does not accept messages of such length */ + if (xbit_test(upslog_flags, UPSLOG_SYSLOG)) { + syslog(LOG_DEBUG, "Network UPS Tools version %s%s%s%s %s%s", + describe_NUT_VERSION_once(), + (compiler_ver && *compiler_ver != '\0' ? " built with " : ""), + (compiler_ver && *compiler_ver != '\0' ? compiler_ver : ""), + (compiler_ver && *compiler_ver != '\0' ? " and" : ""), + (config_flags && *config_flags != '\0' ? "configured with flags: " : "configured all by default guesswork"), + (config_flags && *config_flags != '\0' ? config_flags : "") + ); + } +} + +const char *suggest_doc_links(const char *progname, const char *progconf) { + static char buf[LARGEBUF]; + + buf[0] = '\0'; + + if (progname) { + char *s = NULL, *buf2 = xstrdup(xbasename(progname)); + size_t i; + + for (i = 0; buf2[i]; i++) { + buf2[i] = tolower((unsigned char)(buf2[i])); + } + + if ((s = strstr(buf2, ".exe")) && strcmp(buf2, "nut.exe")) + *s = '\0'; + + snprintf(buf, sizeof(buf), + "For more information please "); +#if defined(WITH_DOCS) && WITH_DOCS + /* FIXME: Currently all NUT tools and drivers are in same + * man page section for "System Management Programs". + * If this ever changes (e.g. clients like `upsc` can be + * a "User Program" just as well), we may need an extra + method argument here. + */ + snprintfcat(buf, sizeof(buf), + "Read The Fine Manual ('man %s %s') and/or ", + MAN_SECTION_CMD_SYS, buf2); +#endif + snprintfcat(buf, sizeof(buf), + "see\n\t%s/docs/man/%s.html\n", + NUT_WEBSITE_BASE, buf2); + + free(buf2); + } + + if (progconf) + snprintfcat(buf, sizeof(buf), + "%s check documentation and samples of %s\n", + progname ? "Also" : "Please", + progconf); + + return buf; +} diff --git a/common/common.c b/common/common.c index c1ea0d0243..25336d04c4 100644 --- a/common/common.c +++ b/common/common.c @@ -447,14 +447,6 @@ static int upsnotify_reported_disabled_systemd = 0; static int upsnotify_reported_disabled_notech = 0; static int upsnotify_report_verbosity = -1; -/* the reason we define UPS_VERSION as a static string, rather than a - macro, is to make dependency tracking easier (only common.o depends - on nut_version.h), and also to prevent all sources from - having to be recompiled each time the version changes (they only - need to be re-linked). */ -#include "nut_version.h" -const char *UPS_VERSION = NUT_VERSION_MACRO; - #include /* Know which bitness we were built for, @@ -531,9 +523,14 @@ pid_t get_max_pid_t(void) int nut_debug_level = 0; int nut_log_level = 0; - static int upslog_flags = UPSLOG_STDERR; - static struct timeval upslog_start = { 0, 0 }; + /* Declare so it can be privately externalized for nut_version.c */ + extern struct timeval upslog_start; + extern int upslog_flags; + + int upslog_flags = UPSLOG_STDERR; + + struct timeval upslog_start = { 0, 0 }; static void xbit_set(int *val, int flag) { @@ -545,7 +542,9 @@ static void xbit_clear(int *val, int flag) *val ^= (*val & flag); } -static int xbit_test(int val, int flag) +/* Declare so it can be privately externalized for nut_version.c */ +int xbit_test(int val, int flag); +int xbit_test(int val, int flag) { return ((val & flag) == flag); } @@ -576,140 +575,6 @@ int syslog_is_disabled(void) return value; } -int banner_is_disabled(void) -{ - static int value = -1; - - if (value < 0) { - char *s = getenv("NUT_QUIET_INIT_BANNER"); - /* Envvar present and empty or true-ish means NUT tool name+version - * banners disabled by the setting: default is enabled (inversed per - * method name) */ - value = 0; - if (s) { - if (*s == '\0' || !strcasecmp(s, "true") || strcmp(s, "1")) { - value = 1; - } - } - } - - return value; -} - -const char *describe_NUT_VERSION_once(void) -{ - static char buf[LARGEBUF]; - static const char *printed = NULL; - - if (printed) - return printed; - - memset(buf, 0, sizeof(buf)); - -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_UNREACHABLE_CODE -#pragma GCC diagnostic push -#endif -#ifdef HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_UNREACHABLE_CODE -#pragma GCC diagnostic ignored "-Wunreachable-code" -#endif -#ifdef __clang__ -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wunreachable-code" -#endif - /* NOTE: Some compilers deduce that macro-based decisions about - * NUT_VERSION_IS_RELEASE make one of codepaths unreachable in - * a particular build. So we pragmatically handwave this away. - */ - if (1 < snprintf(buf, sizeof(buf), - "%s %s%s%s", - NUT_VERSION_MACRO, - NUT_VERSION_IS_RELEASE ? "release" : - (NUT_VERSION_IS_PRERELEASE - ? "(pre-release iteration of " - : "(development iteration after "), - NUT_VERSION_IS_RELEASE ? "" : NUT_VERSION_SEMVER_MACRO, - NUT_VERSION_IS_RELEASE ? "" : ")" - )) { - printed = buf; - } else { - upslogx(LOG_WARNING, "%s: failed to report detailed NUT version", __func__); - printed = UPS_VERSION; - } -#ifdef __clang__ -#pragma clang diagnostic pop -#endif -#ifdef HAVE_PRAGMAS_FOR_GCC_DIAGNOSTIC_IGNORED_UNREACHABLE_CODE -#pragma GCC diagnostic pop -#endif - - return printed; -} - -int print_banner_once(const char *prog, int even_if_disabled) -{ - static int printed = 0; - static int ret = -1; - - if (printed) - return ret; - - if (!banner_is_disabled() || even_if_disabled) { - ret = printf("Network UPS Tools %s %s%s\n", - prog, describe_NUT_VERSION_once(), - even_if_disabled == 2 ? "\n" : ""); - fflush(stdout); - if (ret > 0) - printed = 1; - } - - return ret; -} - -const char *suggest_doc_links(const char *progname, const char *progconf) { - static char buf[LARGEBUF]; - - buf[0] = '\0'; - - if (progname) { - char *s = NULL, *buf2 = xstrdup(xbasename(progname)); - size_t i; - - for (i = 0; buf2[i]; i++) { - buf2[i] = tolower((unsigned char)(buf2[i])); - } - - if ((s = strstr(buf2, ".exe")) && strcmp(buf2, "nut.exe")) - *s = '\0'; - - snprintf(buf, sizeof(buf), - "For more information please "); -#if defined(WITH_DOCS) && WITH_DOCS - /* FIXME: Currently all NUT tools and drivers are in same - * man page section for "System Management Programs". - * If this ever changes (e.g. clients like `upsc` can be - * a "User Program" just as well), we may need an extra - method argument here. - */ - snprintfcat(buf, sizeof(buf), - "Read The Fine Manual ('man %s %s') and/or ", - MAN_SECTION_CMD_SYS, buf2); -#endif - snprintfcat(buf, sizeof(buf), - "see\n\t%s/docs/man/%s.html\n", - NUT_WEBSITE_BASE, buf2); - - free(buf2); - } - - if (progconf) - snprintfcat(buf, sizeof(buf), - "%s check documentation and samples of %s\n", - progname ? "Also" : "Please", - progconf); - - return buf; -} - /* enable writing upslog_with_errno() and upslogx() type messages to the syslog */ void syslogbit_set(void) @@ -2887,97 +2752,6 @@ int upsnotify(upsnotify_state_t state, const char *fmt, ...) return ret; } -void nut_report_config_flags(void) -{ - /* Roughly similar to upslogx() but without the buffer-size limits and - * timestamp/debug-level prefixes. Only printed if debug (any) is on. - * Depending on amount of configuration tunables involved by a particular - * build of NUT, the string can be quite long (over 1KB). - */ -#if 0 - const char *acinit_ver = NULL; -#endif - /* Pass these as variables to avoid warning about never reaching one - * of compiled codepaths: */ - const char *compiler_ver = CC_VERSION; - const char *config_flags = CONFIG_FLAGS; - struct timeval now; - - if (nut_debug_level < 1) - return; - -#if 0 - /* Only report git revision if NUT_VERSION_MACRO in nut_version.h aka - * UPS_VERSION here is remarkably different from PACKAGE_VERSION from - * configure.ac AC_INIT() -- which may be e.g. "2.8.0.1" although some - * distros, especially embedders, tend to place their product IDs here). - * The macro may be that fixed version or refer to git source revision, - * as decided when generating nut_version.h (and if it was re-generated - * in case of rebuilds while developers are locally iterating -- this - * may be disabled for faster local iterations at a cost of a little lie). - */ - if (PACKAGE_VERSION && UPS_VERSION && - (strlen(UPS_VERSION) < 12 || !strstr(UPS_VERSION, PACKAGE_VERSION)) - ) { - /* If UPS_VERSION is too short (so likely a static string - * from configure.ac AC_INIT() -- although some distros, - * especially embedders, tend to place their product IDs here), - * or if PACKAGE_VERSION *is NOT* a substring of it: */ - acinit_ver = PACKAGE_VERSION; -/* - // Triplet that was printed below: - (acinit_ver ? " (release/snapshot of " : ""), - (acinit_ver ? acinit_ver : ""), - (acinit_ver ? ")" : ""), -*/ - } -#endif - - /* NOTE: If changing wording here, keep in sync with configure.ac logic - * looking for CONFIG_FLAGS_DEPLOYED via "configured with flags:" string! - */ - - gettimeofday(&now, NULL); - - if (upslog_start.tv_sec == 0) { - upslog_start = now; - } - - if (upslog_start.tv_usec > now.tv_usec) { - now.tv_usec += 1000000; - now.tv_sec -= 1; - } - - if (xbit_test(upslog_flags, UPSLOG_STDERR)) { - fprintf(stderr, "%4.0f.%06ld\t[D1] Network UPS Tools version %s%s%s%s %s%s\n", - difftime(now.tv_sec, upslog_start.tv_sec), - (long)(now.tv_usec - upslog_start.tv_usec), - describe_NUT_VERSION_once(), - (compiler_ver && *compiler_ver != '\0' ? " built with " : ""), - (compiler_ver && *compiler_ver != '\0' ? compiler_ver : ""), - (compiler_ver && *compiler_ver != '\0' ? " and" : ""), - (config_flags && *config_flags != '\0' ? "configured with flags: " : "configured all by default guesswork"), - (config_flags && *config_flags != '\0' ? config_flags : "") - ); -#ifdef WIN32 - fflush(stderr); -#endif /* WIN32 */ - } - - /* NOTE: May be ignored or truncated by receiver if that syslog server - * (and/or OS sender) does not accept messages of such length */ - if (xbit_test(upslog_flags, UPSLOG_SYSLOG)) { - syslog(LOG_DEBUG, "Network UPS Tools version %s%s%s%s %s%s", - describe_NUT_VERSION_once(), - (compiler_ver && *compiler_ver != '\0' ? " built with " : ""), - (compiler_ver && *compiler_ver != '\0' ? compiler_ver : ""), - (compiler_ver && *compiler_ver != '\0' ? " and" : ""), - (config_flags && *config_flags != '\0' ? "configured with flags: " : "configured all by default guesswork"), - (config_flags && *config_flags != '\0' ? config_flags : "") - ); - } -} - static void vupslog(int priority, const char *fmt, va_list va, int use_strerror) { int ret, errno_orig = errno; From 8379edc032c3324080aac749da0edea3b7d84a5c Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Wed, 23 Apr 2025 16:35:33 +0200 Subject: [PATCH 2/8] common/common-nut_version.c: nut_report_config_flags(): try to also report build bitness, if known [#2097] Signed-off-by: Jim Klimov --- common/common-nut_version.c | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/common/common-nut_version.c b/common/common-nut_version.c index 581bc0f282..6ffc00a5b7 100644 --- a/common/common-nut_version.c +++ b/common/common-nut_version.c @@ -38,6 +38,24 @@ #include "nut_version.h" const char *UPS_VERSION = NUT_VERSION_MACRO; +/* Know which bitness we were built for, to adjust the report */ +#include "nut_stdint.h" +#if defined(UINTPTR_MAX) && (UINTPTR_MAX + 0) == 0xffffffffffffffffULL +# define BUILD_64 1 +#else +# ifdef BUILD_64 +# undef BUILD_64 +# endif +#endif + +#if defined(UINTPTR_MAX) && (UINTPTR_MAX + 0) == 0x00000000ffffffffULL +# define BUILD_32 1 +#else +# ifdef BUILD_32 +# undef BUILD_32 +# endif +#endif + /* privately declare a few things implemented in common.c (this code used * to be there) */ extern struct timeval upslog_start; @@ -147,11 +165,20 @@ void nut_report_config_flags(void) * of compiled codepaths: */ const char *compiler_ver = CC_VERSION; const char *config_flags = CONFIG_FLAGS; + const char *bitness_str = NULL; struct timeval now; if (nut_debug_level < 1) return; +#ifdef BUILD_64 + bitness_str = "64"; +#else +# ifdef BUILD_32 + bitness_str = "32"; +# endif +#endif + #if 0 /* Only report git revision if NUT_VERSION_MACRO in nut_version.h aka * UPS_VERSION here is remarkably different from PACKAGE_VERSION from @@ -195,10 +222,13 @@ void nut_report_config_flags(void) } if (xbit_test(upslog_flags, UPSLOG_STDERR)) { - fprintf(stderr, "%4.0f.%06ld\t[D1] Network UPS Tools version %s%s%s%s %s%s\n", + fprintf(stderr, "%4.0f.%06ld\t[D1] Network UPS Tools version %s%s%s%s%s%s%s %s%s\n", difftime(now.tv_sec, upslog_start.tv_sec), (long)(now.tv_usec - upslog_start.tv_usec), describe_NUT_VERSION_once(), + bitness_str ? " (" : "", + bitness_str ? bitness_str : "", + bitness_str ? "-bit build)" : "", (compiler_ver && *compiler_ver != '\0' ? " built with " : ""), (compiler_ver && *compiler_ver != '\0' ? compiler_ver : ""), (compiler_ver && *compiler_ver != '\0' ? " and" : ""), @@ -213,8 +243,11 @@ void nut_report_config_flags(void) /* NOTE: May be ignored or truncated by receiver if that syslog server * (and/or OS sender) does not accept messages of such length */ if (xbit_test(upslog_flags, UPSLOG_SYSLOG)) { - syslog(LOG_DEBUG, "Network UPS Tools version %s%s%s%s %s%s", + syslog(LOG_DEBUG, "Network UPS Tools version %s%s%s%s%s%s%s %s%s", describe_NUT_VERSION_once(), + bitness_str ? " (" : "", + bitness_str ? bitness_str : "", + bitness_str ? "-bit build)" : "", (compiler_ver && *compiler_ver != '\0' ? " built with " : ""), (compiler_ver && *compiler_ver != '\0' ? compiler_ver : ""), (compiler_ver && *compiler_ver != '\0' ? " and" : ""), From 2f20c8899c903c30ca9cb5a5caa5d527459a2edd Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Wed, 23 Apr 2025 17:24:03 +0200 Subject: [PATCH 3/8] */Makefile.am: refactor with a separate libcommonversion.la [#2097] Avoid multiple rebuilds and relinks of libcommon*.la and their dependants when nut_version.h changes. Now there is just one library impacted by this, included to LDFLAGS across the board for Makefiles of directories with consumers of methods exported from common-nut_version.c (declared by common.h still). Signed-off-by: Jim Klimov --- Makefile.am | 10 ++++++++++ clients/Makefile.am | 27 ++++++++++++++++++++++----- common/Makefile.am | 17 +++++++++++++---- drivers/Makefile.am | 12 ++++++++++-- scripts/Windows/Makefile.am | 6 +++++- server/Makefile.am | 7 ++++++- tools/nut-scanner/Makefile.am | 5 ++++- tools/nutconf/Makefile.am | 7 +++++-- 8 files changed, 75 insertions(+), 16 deletions(-) diff --git a/Makefile.am b/Makefile.am index 9b42b1d84c..d6db01669c 100644 --- a/Makefile.am +++ b/Makefile.am @@ -196,6 +196,8 @@ all-libs-local/include: +@$(SUBDIR_TGT_RULE) ### Delivers: libcommon.la libcommonclient.la libcommonstr.la +### (consume only one of these at a time!) +### Delivers: libcommonversion.la (only version methods) ### Delivers: libparseconf.la libnutconf.la libnutwincompat.la ### Requires-ext: include/nut_version.h ### Requires-int: libparseconf.la libcommonclient.la @@ -206,6 +208,7 @@ all-libs-local/common: all-libs-local/include ### Delivers: libupsclient-version.h ### LIB-Requires-ext: common/libcommonclient.la ### Requires-ext: common/libcommon.la common/libcommonclient.la +### Requires-ext: common/libcommonversion.la ### Requires-ext: common/libparseconf.la ### Requires-int: libupsclient.la all-libs-local/clients: all-libs-local/common @@ -239,6 +242,7 @@ all-libs-local/tools: ### Delivers: libnutscan.la ### LIB-Requires-ext: drivers/libserial-nutscan.la ### LIB-Requires-ext: common/libnutwincompat.la common/libcommonstr.la +### LIB-Requires-ext: common/libcommonversion.la ### HDR-Requires-ext: clients/libupsclient-version.h ### HDR-Requires-ext: nut-scanner/nutscan-snmp.h nut-scanner/nutscan-usb.h ### (generated by nut-scanner-deps/tools aliased as all-libs-local/tools) @@ -311,12 +315,14 @@ all/common: all/include all-libs-local/common ### Requires-ext: common/libcommon.la common/libcommonclient.la ### Requires-ext: common/libparseconf.la +### Requires-ext: common/libcommonversion.la ### Requires-int: libupsclient.la all/clients: all/common all-libs-local/clients +@$(SUBDIR_TGT_RULE) ### Summary of drivers/ subdir dependencies: ### Requires-ext: common/libcommon.la common/libparseconf.la +### Requires-ext: common/libcommonversion.la ### Requires-ext: clients/libupsclient.la (dummy-ups only) ### Requires-int: libdummy.la libdummy_upsdrvquery.la ### Requires-int: libdummy_serial.la @@ -356,11 +362,13 @@ all-drivers: dummy-ups$(EXEEXT)/drivers all/drivers endif !SOME_DRIVERS ### Requires-ext: common/libcommon.la common/libparseconf.la +### Requires-ext: common/libcommonversion.la all/server: all-libs-local/common +@$(SUBDIR_TGT_RULE) ### LIB-Requires-ext: drivers/libserial-nutscan.la ### LIB-Requires-ext: common/libnutwincompat.la common/libcommonstr.la +### LIB-Requires-ext: common/libcommonversion.la ### Requires-ext: include/nut_version.h ### Requires-ext: clients/libupsclient-version.h ### Requires-int: libnutscan.la @@ -372,6 +380,7 @@ all/tools/nut-scanner: all-libs-local/include all-libs-local/common \ # only libnutscan is needed for nutconf, # but we do wholesale subdir all-libs-local at the moment... ### Requires-ext: common/libcommon.la common/libnutconf.la +### Requires-ext: common/libcommonversion.la ### Requires-ext: tools/nut-scanner/libnutscan.la all/tools/nutconf: all-libs-local/tools/nut-scanner all-libs-local/common +@$(SUBDIR_TGT_RULE) @@ -403,6 +412,7 @@ all-recursive/tests: all/tests/NIT all/tests if HAVE_MINGW_RESGEN if HAVE_WINDOWS ### Requires-ext: common/libcommon.la +### Requires-ext: common/libcommonversion.la all/scripts/Windows: all-libs-local/common +@$(SUBDIR_TGT_RULE) else !HAVE_WINDOWS diff --git a/clients/Makefile.am b/clients/Makefile.am index 1c24d3c314..45014b62fc 100644 --- a/clients/Makefile.am +++ b/clients/Makefile.am @@ -20,15 +20,24 @@ AM_CXXFLAGS = -DHAVE_NUTCOMMON=1 -I$(top_srcdir)/include # Make sure out-of-dir dependencies exist (especially when dev-building parts): $(top_builddir)/common/libcommon.la \ $(top_builddir)/common/libcommonclient.la \ +$(top_builddir)/common/libcommonversion.la \ $(top_builddir)/common/libparseconf.la: dummy +@cd $(@D) && $(MAKE) $(AM_MAKEFLAGS) $(@F) -LDADD_FULL = $(top_builddir)/common/libcommon.la libupsclient.la $(NETLIBS) +LDADD_FULL = \ + $(top_builddir)/common/libcommon.la \ + $(top_builddir)/common/libcommonversion.la \ + libupsclient.la \ + $(NETLIBS) if WITH_SSL LDADD_FULL += $(LIBSSL_LIBS) $(LIBSSL_LDFLAGS_RPATH) endif WITH_SSL -LDADD_CLIENT = $(top_builddir)/common/libcommonclient.la libupsclient.la $(NETLIBS) +LDADD_CLIENT = \ + $(top_builddir)/common/libcommonclient.la \ + $(top_builddir)/common/libcommonversion.la \ + libupsclient.la \ + $(NETLIBS) if WITH_SSL LDADD_CLIENT += $(LIBSSL_LIBS) $(LIBSSL_LDFLAGS_RPATH) endif WITH_SSL @@ -87,7 +96,11 @@ message_SOURCES = message.c endif HAVE_WINDOWS_SOCKETS upssched_SOURCES = upssched.c upssched.h -upssched_LDADD = $(top_builddir)/common/libcommonclient.la $(top_builddir)/common/libparseconf.la $(NETLIBS) +upssched_LDADD = \ + $(top_builddir)/common/libcommonclient.la \ + $(top_builddir)/common/libcommonversion.la \ + $(top_builddir)/common/libparseconf.la \ + $(NETLIBS) upsimage_cgi_SOURCES = upsimage.c upsclient.h upsimagearg.h cgilib.c cgilib.h upsimage_cgi_LDADD = $(LDADD) $(LIBGD_LDFLAGS) @@ -98,7 +111,9 @@ upsstats_cgi_SOURCES = upsstats.c upsclient.h status.h upsstats.h \ # not LDADD... why? libupsclient_la_SOURCES = upsclient.c upsclient.h -libupsclient_la_LIBADD = $(top_builddir)/common/libcommonclient.la +libupsclient_la_LIBADD = \ + $(top_builddir)/common/libcommonclient.la \ + $(top_builddir)/common/libcommonversion.la if HAVE_WINDOWS_SOCKETS libupsclient_la_LIBADD += -lws2_32 endif HAVE_WINDOWS_SOCKETS @@ -167,7 +182,9 @@ libnutclient_la_SOURCES = nutclient.h nutclient.cpp libnutclient_la_LDFLAGS = -version-info 2:2:0 # Needed in not-standalone builds with -DHAVE_NUTCOMMON=1 # which is defined for in-tree CXX builds above: -libnutclient_la_LIBADD = $(top_builddir)/common/libcommonclient.la +libnutclient_la_LIBADD = \ + $(top_builddir)/common/libcommonclient.la \ + $(top_builddir)/common/libcommonversion.la if HAVE_WINDOWS # Many versions of MingW seem to fail to build non-static DLL without this libnutclient_la_LDFLAGS += -no-undefined diff --git a/common/Makefile.am b/common/Makefile.am index 364ec298ee..3d90e1a59e 100644 --- a/common/Makefile.am +++ b/common/Makefile.am @@ -38,7 +38,7 @@ libparseconf_la_SOURCES = parseconf.c # BUILT_SOURCES (in ../include) will ensure nut_version.h will # be built before anything else... but do depend on its build area: if BUILDING_IN_TREE -# No need for symlink hack +# No need for symlink hack, just rebuild if header gets updated: common-nut_version.c: $(top_builddir)/include/nut_version.h else !BUILDING_IN_TREE # Surprisingly, for some "make" implementations this dependency means that @@ -54,6 +54,9 @@ else !BUILDING_IN_TREE echo " LN $(top_srcdir)/common/common-nut_version.c => $@ (relative to `pwd`)" ; \ ln -s -f "$(top_srcdir)/common/common-nut_version.c" "$@" ; \ fi + + CLEANFILES += $(top_builddir)/common/nut_version.c + BUILT_SOURCES = common-nut_version.c endif !BUILDING_IN_TREE $(top_builddir)/include/nut_version.h: @@ -73,8 +76,16 @@ libcommonstr_la_SOURCES = str.c libcommonstr_la_CFLAGS = $(AM_CFLAGS) -DWITHOUT_LIBSYSTEMD=1 libcommonstr_la_LIBADD = @LTLIBOBJS@ @BSDKVMPROCLIBS@ +# This one includes only version-related data and methods and should be +# linked along with one of the other libcommon*.la for logging methods: +noinst_LTLIBRARIES += libcommonversion.la +libcommonversion_la_SOURCES = common-nut_version.c +#libcommonversion_la_CFLAGS = $(AM_CFLAGS) -DWITHOUT_LIBSYSTEMD=1 +#libcommonversion_la_LIBADD = @LTLIBOBJS@ @BSDKVMPROCLIBS@ + +# Eventually we expect more sources as the big common.c source gets split +# into smaller better-focused files. COMMON_SRC = \ - common-nut_version.c \ common.c if BUILDING_IN_TREE @@ -85,8 +96,6 @@ else !BUILDING_IN_TREE nodist_libcommon_la_SOURCES = $(COMMON_SRC) nodist_libcommonstr_la_SOURCES = $(COMMON_SRC) nodist_libcommonclient_la_SOURCES = $(COMMON_SRC) - CLEANFILES += $(top_builddir)/common/nut_version.c - BUILT_SOURCES = common-nut_version.c endif !BUILDING_IN_TREE if HAVE_STRPTIME diff --git a/drivers/Makefile.am b/drivers/Makefile.am index 98d19eeca7..3bf648187c 100644 --- a/drivers/Makefile.am +++ b/drivers/Makefile.am @@ -11,6 +11,7 @@ # Make sure out-of-dir dependencies exist (especially when dev-building parts): $(top_builddir)/common/libcommon.la \ +$(top_builddir)/common/libcommonversion.la \ $(top_builddir)/common/libparseconf.la \ $(top_builddir)/clients/libupsclient.la: dummy +@cd $(@D) && $(MAKE) $(AM_MAKEFLAGS) $(@F) @@ -18,7 +19,10 @@ $(top_builddir)/clients/libupsclient.la: dummy # by default, link programs in this directory with libcommon.la # (libtool version of the static lib, in order to access LTLIBOBJS) #FIXME: SERLIBS is only useful for LDADD_DRIVERS_SERIAL not for LDADD_COMMON -LDADD_COMMON = $(top_builddir)/common/libcommon.la $(top_builddir)/common/libparseconf.la +LDADD_COMMON = \ + $(top_builddir)/common/libcommon.la \ + $(top_builddir)/common/libcommonversion.la \ + $(top_builddir)/common/libparseconf.la LDADD_DRIVERS = libdummy.la libdummy_upsdrvquery.la $(LDADD_COMMON) LDADD_DRIVERS_SERIAL = libdummy_serial.la $(LDADD_DRIVERS) $(SERLIBS) @@ -440,7 +444,11 @@ libdummy_upsdrvquery_la_LDFLAGS = -no-undefined -static EXTRA_LTLIBRARIES += libdummy_mockdrv.la libdummy_mockdrv_la_SOURCES = main.c dstate.c libdummy_mockdrv_la_CFLAGS = $(AM_CFLAGS) -DDRIVERS_MAIN_WITHOUT_MAIN=1 -libdummy_mockdrv_la_LDFLAGS = -static $(top_builddir)/common/libcommon.la $(top_builddir)/common/libparseconf.la +libdummy_mockdrv_la_LDFLAGS = \ + -static \ + $(top_builddir)/common/libcommon.la \ + $(top_builddir)/common/libcommonversion.la \ + $(top_builddir)/common/libparseconf.la # Also define a library with serial-port UPS routines needed for nut-scanner noinst_LTLIBRARIES = libserial-nutscan.la diff --git a/scripts/Windows/Makefile.am b/scripts/Windows/Makefile.am index 85572b7b87..e7dc9c3558 100644 --- a/scripts/Windows/Makefile.am +++ b/scripts/Windows/Makefile.am @@ -2,6 +2,7 @@ AM_CFLAGS = -I$(top_srcdir)/include +$(top_builddir)/common/libcommonversion.la \ $(top_builddir)/common/libcommon.la: FORCE +@cd $(@D) && $(MAKE) $(AM_MAKEFLAGS) $(@F) @@ -63,7 +64,10 @@ if HAVE_WINDOWS bin_PROGRAMS += nut halt nut_SOURCES = wininit.c -nut_LDADD = $(top_builddir)/common/libcommon.la winevent.o +nut_LDADD = \ + $(top_builddir)/common/libcommon.la \ + $(top_builddir)/common/libcommonversion.la \ + winevent.o halt_SOURCES = halt.c endif HAVE_WINDOWS diff --git a/server/Makefile.am b/server/Makefile.am index 8833e2eec0..d4c186916d 100644 --- a/server/Makefile.am +++ b/server/Makefile.am @@ -11,6 +11,7 @@ # Make sure out-of-dir dependencies exist (especially when dev-building parts): $(top_builddir)/common/libcommon.la \ +$(top_builddir)/common/libcommonversion.la \ $(top_builddir)/common/libparseconf.la: dummy +@cd $(@D) && $(MAKE) $(AM_MAKEFLAGS) $(@F) @@ -18,7 +19,11 @@ $(top_builddir)/common/libparseconf.la: dummy # files. In any case, CFLAGS are only -I options, so there is no harm, # but only add them if we really use the target. AM_CFLAGS = -I$(top_srcdir)/include -LDADD = $(top_builddir)/common/libcommon.la $(top_builddir)/common/libparseconf.la $(NETLIBS) +LDADD = \ + $(top_builddir)/common/libcommon.la \ + $(top_builddir)/common/libcommonversion.la \ + $(top_builddir)/common/libparseconf.la \ + $(NETLIBS) sbin_PROGRAMS = upsd EXTRA_PROGRAMS = sockdebug diff --git a/tools/nut-scanner/Makefile.am b/tools/nut-scanner/Makefile.am index 96197589d0..f7fd90383e 100644 --- a/tools/nut-scanner/Makefile.am +++ b/tools/nut-scanner/Makefile.am @@ -34,6 +34,7 @@ $(top_builddir)/clients/libupsclient-version.h \ $(top_builddir)/common/libnutwincompat.la \ $(top_builddir)/drivers/libserial-nutscan.la \ $(top_builddir)/common/libcommonstr.la \ +$(top_builddir)/common/libcommonversion.la \ $(top_builddir)/common/libcommon.la: dummy +@cd $(@D) && $(MAKE) $(AM_MAKEFLAGS) $(@F) @@ -116,7 +117,9 @@ libnutscan_la_CFLAGS = \ -I$(top_builddir)/include -I$(top_srcdir)/include \ $(LIBLTDL_CFLAGS) -I$(top_srcdir)/drivers -libnutscan_la_LIBADD += $(top_builddir)/common/libcommonstr.la +libnutscan_la_LIBADD += \ + $(top_builddir)/common/libcommonversion.la \ + $(top_builddir)/common/libcommonstr.la nut_scanner_SOURCES = nut-scanner.c nut_scanner_CFLAGS = \ diff --git a/tools/nutconf/Makefile.am b/tools/nutconf/Makefile.am index 885ddc7c25..bc05741832 100644 --- a/tools/nutconf/Makefile.am +++ b/tools/nutconf/Makefile.am @@ -19,8 +19,10 @@ if WITH_NUTCONF bin_PROGRAMS += nutconf nutconf_SOURCES = nutconf-cli.cpp nutconf_CXXFLAGS = -I$(top_builddir)/include -I$(top_srcdir)/include -nutconf_LDADD = $(top_builddir)/common/libcommon.la \ - $(top_builddir)/common/libnutconf.la +nutconf_LDADD = \ + $(top_builddir)/common/libcommon.la \ + $(top_builddir)/common/libcommonversion.la \ + $(top_builddir)/common/libnutconf.la # Add support for device scanning if WITH_LIBLTDL @@ -32,6 +34,7 @@ endif WITH_NUTCONF # Make sure out-of-dir dependencies exist (especially when dev-building parts): $(top_builddir)/common/libcommon.la \ +$(top_builddir)/common/libcommonversion.la \ $(top_builddir)/common/libnutconf.la \ $(top_builddir)/tools/nut-scanner/libnutscan.la: dummy +@cd $(@D) && $(MAKE) $(AM_MAKEFLAGS) $(@F) From 581ccb79e9b56216b968d2d6482e3449cedf01ba Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Wed, 23 Apr 2025 17:45:39 +0200 Subject: [PATCH 4/8] Makefile.am, tools/nut-scanner/Makefile.am: current nut-scanner does not actually depend on nut_version.h (or not directly, just via libcommonversion.la) [#2097] Signed-off-by: Jim Klimov --- Makefile.am | 1 - tools/nut-scanner/Makefile.am | 10 +++------- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/Makefile.am b/Makefile.am index d6db01669c..f6c1566c43 100644 --- a/Makefile.am +++ b/Makefile.am @@ -369,7 +369,6 @@ all/server: all-libs-local/common ### LIB-Requires-ext: drivers/libserial-nutscan.la ### LIB-Requires-ext: common/libnutwincompat.la common/libcommonstr.la ### LIB-Requires-ext: common/libcommonversion.la -### Requires-ext: include/nut_version.h ### Requires-ext: clients/libupsclient-version.h ### Requires-int: libnutscan.la all/tools/nut-scanner: all-libs-local/include all-libs-local/common \ diff --git a/tools/nut-scanner/Makefile.am b/tools/nut-scanner/Makefile.am index f7fd90383e..e7c8a1e299 100644 --- a/tools/nut-scanner/Makefile.am +++ b/tools/nut-scanner/Makefile.am @@ -29,7 +29,6 @@ $(NUT_SCANNER_DEPS): dummy +@cd .. && $(MAKE) $(AM_MAKEFLAGS) nut-scanner-deps # Make sure out-of-dir dependencies exist (especially when dev-building parts): -$(top_builddir)/include/nut_version.h \ $(top_builddir)/clients/libupsclient-version.h \ $(top_builddir)/common/libnutwincompat.la \ $(top_builddir)/drivers/libserial-nutscan.la \ @@ -38,17 +37,14 @@ $(top_builddir)/common/libcommonversion.la \ $(top_builddir)/common/libcommon.la: dummy +@cd $(@D) && $(MAKE) $(AM_MAKEFLAGS) $(@F) -# do not hard depend on '../include/nut_version.h', since it blocks +# do not hard depend on '../clients/libupsclient-version.h', since it blocks # 'dist', and is only required for actual build, in which case -# BUILT_SOURCES (in ../include) will ensure nut_version.h will +# BUILT_SOURCES (in ../clients) will ensure libupsclient-version.h will # be built before anything else -# FIXME: this can cause rebuilds of nut_version.h for every mention -# (especially if we `configire --enable-force-nut-version-header`, -# which is default). This also causes binary build of libupsclient.la +# FIXME: this can cause re-evaluation, possibly rebuilds, of libupsclient.la # to look up its metadata and generate libupsclient-version.h which # may be a bit of overkill (especially in cross-build cases etc.) # Notably this pops up in `configure && make dist(check)` rituals. -nut-scanner.c: $(top_builddir)/include/nut_version.h nutscan-init.c: $(top_builddir)/clients/libupsclient-version.h # We optionally append values to this below From 98608ddd295f42b8ef7d24e1f44b01ca4cfa7e45 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Wed, 23 Apr 2025 17:46:19 +0200 Subject: [PATCH 5/8] Makefile.am: add a goal for libupsclient-version.h shortcut, just to be on par with an existing nut_version.h goal [#2097] Signed-off-by: Jim Klimov --- Makefile.am | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Makefile.am b/Makefile.am index f6c1566c43..9d638c7789 100644 --- a/Makefile.am +++ b/Makefile.am @@ -976,6 +976,10 @@ ChangeLog.adoc: ChangeLog nut_version.h include/nut_version.h: +cd $(abs_top_builddir)/include && $(MAKE) $(AM_MAKEFLAGS) nut_version.h +# May involve (re-)build of libupsclient.la +libupsclient-version.h clients/libupsclient-version.h: + +cd $(abs_top_builddir)/include && $(MAKE) $(AM_MAKEFLAGS) libupsclient-version.h + tools/gitlog2changelog.py: tools/gitlog2changelog.py.in +cd $(@D) && $(MAKE) $(AM_MAKEFLAGS) -s $(@F) From c99339ebd495cfd37b7c9178534791e44fb80ea8 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Wed, 23 Apr 2025 17:47:30 +0200 Subject: [PATCH 6/8] clients/Makefile.am: libupsclient.la and libnutclient.la do not actually include libcommonversion.la [#2097] Signed-off-by: Jim Klimov --- clients/Makefile.am | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/clients/Makefile.am b/clients/Makefile.am index 45014b62fc..e9f913c0a0 100644 --- a/clients/Makefile.am +++ b/clients/Makefile.am @@ -111,9 +111,9 @@ upsstats_cgi_SOURCES = upsstats.c upsclient.h status.h upsstats.h \ # not LDADD... why? libupsclient_la_SOURCES = upsclient.c upsclient.h +# NOTE: The library does not require libcommonversion.la libupsclient_la_LIBADD = \ - $(top_builddir)/common/libcommonclient.la \ - $(top_builddir)/common/libcommonversion.la + $(top_builddir)/common/libcommonclient.la if HAVE_WINDOWS_SOCKETS libupsclient_la_LIBADD += -lws2_32 endif HAVE_WINDOWS_SOCKETS @@ -183,8 +183,7 @@ libnutclient_la_LDFLAGS = -version-info 2:2:0 # Needed in not-standalone builds with -DHAVE_NUTCOMMON=1 # which is defined for in-tree CXX builds above: libnutclient_la_LIBADD = \ - $(top_builddir)/common/libcommonclient.la \ - $(top_builddir)/common/libcommonversion.la + $(top_builddir)/common/libcommonclient.la if HAVE_WINDOWS # Many versions of MingW seem to fail to build non-static DLL without this libnutclient_la_LDFLAGS += -no-undefined From 2d32a2ec1f222f8925ce2e2423ce9b7ec7904dd1 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Wed, 23 Apr 2025 18:10:39 +0200 Subject: [PATCH 7/8] common/common-nut_version.c: nut_report_config_flags(): report not only bitness but also target CPU if available [#2097] Signed-off-by: Jim Klimov --- common/common-nut_version.c | 45 ++++++++++++++++++++++++------------- 1 file changed, 29 insertions(+), 16 deletions(-) diff --git a/common/common-nut_version.c b/common/common-nut_version.c index 6ffc00a5b7..419e97bdca 100644 --- a/common/common-nut_version.c +++ b/common/common-nut_version.c @@ -30,11 +30,12 @@ # include "wincompat.h" #endif /* WIN32 */ -/* the reason we define UPS_VERSION as a static string, rather than a - macro, is to make dependency tracking easier (only common.o depends - on nut_version.h), and also to prevent all sources from - having to be recompiled each time the version changes (they only - need to be re-linked). */ +/* the reason we define UPS_VERSION as a static string, rather than a macro, + * is to make dependency tracking easier (only common-nut_version.o file + * depends on nut_version.h), and also to prevent all sources from having + * to be recompiled each time the version changes (they only need to be + * re-linked). Similarly for other variables below in the code. + */ #include "nut_version.h" const char *UPS_VERSION = NUT_VERSION_MACRO; @@ -165,20 +166,26 @@ void nut_report_config_flags(void) * of compiled codepaths: */ const char *compiler_ver = CC_VERSION; const char *config_flags = CONFIG_FLAGS; - const char *bitness_str = NULL; + const char *BITNESS_STR = NULL; + const char *CPU_TYPE_STR = NULL; struct timeval now; if (nut_debug_level < 1) return; #ifdef BUILD_64 - bitness_str = "64"; + BITNESS_STR = "64"; #else # ifdef BUILD_32 - bitness_str = "32"; + BITNESS_STR = "32"; # endif #endif +#ifdef CPU_TYPE + if (CPU_TYPE && *CPU_TYPE) + CPU_TYPE_STR = CPU_TYPE; +#endif + #if 0 /* Only report git revision if NUT_VERSION_MACRO in nut_version.h aka * UPS_VERSION here is remarkably different from PACKAGE_VERSION from @@ -222,13 +229,16 @@ void nut_report_config_flags(void) } if (xbit_test(upslog_flags, UPSLOG_STDERR)) { - fprintf(stderr, "%4.0f.%06ld\t[D1] Network UPS Tools version %s%s%s%s%s%s%s %s%s\n", + fprintf(stderr, "%4.0f.%06ld\t[D1] Network UPS Tools version %s%s%s%s%s%s%s%s%s%s %s%s\n", difftime(now.tv_sec, upslog_start.tv_sec), (long)(now.tv_usec - upslog_start.tv_usec), describe_NUT_VERSION_once(), - bitness_str ? " (" : "", - bitness_str ? bitness_str : "", - bitness_str ? "-bit build)" : "", + BITNESS_STR ? ", " : "", + BITNESS_STR ? BITNESS_STR : "", + BITNESS_STR ? "-bit build" : "", + CPU_TYPE_STR ? " for " : "", + CPU_TYPE_STR ? CPU_TYPE_STR : "", + BITNESS_STR ? "," : "", (compiler_ver && *compiler_ver != '\0' ? " built with " : ""), (compiler_ver && *compiler_ver != '\0' ? compiler_ver : ""), (compiler_ver && *compiler_ver != '\0' ? " and" : ""), @@ -243,11 +253,14 @@ void nut_report_config_flags(void) /* NOTE: May be ignored or truncated by receiver if that syslog server * (and/or OS sender) does not accept messages of such length */ if (xbit_test(upslog_flags, UPSLOG_SYSLOG)) { - syslog(LOG_DEBUG, "Network UPS Tools version %s%s%s%s%s%s%s %s%s", + syslog(LOG_DEBUG, "Network UPS Tools version %s%s%s%s%s%s%s%s%s%s %s%s", describe_NUT_VERSION_once(), - bitness_str ? " (" : "", - bitness_str ? bitness_str : "", - bitness_str ? "-bit build)" : "", + BITNESS_STR ? ", " : "", + BITNESS_STR ? BITNESS_STR : "", + BITNESS_STR ? "-bit build" : "", + CPU_TYPE_STR ? " for " : "", + CPU_TYPE_STR ? CPU_TYPE_STR : "", + BITNESS_STR ? "," : "", (compiler_ver && *compiler_ver != '\0' ? " built with " : ""), (compiler_ver && *compiler_ver != '\0' ? compiler_ver : ""), (compiler_ver && *compiler_ver != '\0' ? " and" : ""), From 660b70cff3082344f272f90a051a8b5120c0d0ba Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Wed, 23 Apr 2025 18:35:52 +0200 Subject: [PATCH 8/8] Makefile.am: group check-files-quick (spellcheck-quick check-man) before check-recursive which is the Autotools implementation behind "make check" Signed-off-by: Jim Klimov --- Makefile.am | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Makefile.am b/Makefile.am index 9d638c7789..d2169dc5ce 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1415,3 +1415,12 @@ git-realclean-check: done; \ done ; \ fi + +# Simply group recipes which depend on a ton of source files but are generally +# quickly handled by external tools, to group (in life and log) various checks +# separately from the probably slower/louder stages for test programs like +# check-NIT: +check-files-quick: spellcheck-quick check-man + +# Autotools hook: run the quick checks before recursing for defaults: +check-recursive: check-files-quick