Skip to content

Commit

Permalink
tools/nut-scanner/nutscan-init.c, tools/nut-scanner/Makefile.am, NEWS…
Browse files Browse the repository at this point in the history
….adoc: use client/libupsclient-version.h for SOFILE_LIBUPSCLIENT/SOPATH_LIBUPSCLIENT [networkupstools#2431]

Signed-off-by: Jim Klimov <[email protected]>
  • Loading branch information
jimklimov committed Jul 15, 2024
1 parent 759c2c7 commit 1d0a132
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 6 deletions.
4 changes: 2 additions & 2 deletions NEWS.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,8 @@ https://github.com/networkupstools/nut/milestone/11
we can store and try to use the file name which was present on the build
system, while we search for a suitable library. [#2431]
+
NOTE: Currently both the long and short names for `libupsclient` should be
installed.
NOTE: A different but functionally equivalent trick is done for `libupsclient`
during a NUT build.
* fixed support for IPv6 addresses (passed in square brackets) for both
`-s` start/`-e` end command-line options, and for `-m cidr/mask` option.
[issue #2512, PR #2518]
Expand Down
12 changes: 10 additions & 2 deletions tools/nut-scanner/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

# Generally, list headers and/or sources which are re-generated
# for nut-scanner in the parent dir
# Note there is also a libupsclient-version.h which we ensure and
# manage via usual `make` dependencies below.
NUT_SCANNER_DEPS_H = nutscan-usb.h nutscan-snmp.h
NUT_SCANNER_DEPS_C =

Expand All @@ -28,6 +30,7 @@ $(NUT_SCANNER_DEPS): dummy

# 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 \
$(top_builddir)/common/libcommonstr.la \
Expand All @@ -39,6 +42,7 @@ $(top_builddir)/common/libcommon.la: dummy
# BUILT_SOURCES (in ../include) will ensure nut_version.h will
# be built before anything else
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
bin_PROGRAMS =
Expand Down Expand Up @@ -97,13 +101,17 @@ libnutscan_la_LDFLAGS += -version-info 2:6:0
# One solution to tackle if needed for those cases would be to make some
# dynamic/shared libnutcommon (etc.)
libnutscan_la_LDFLAGS += -export-symbols-regex '^(nutscan_|nut_debug_level|s_upsdebug|fatalx|fatal_with_errno|xcalloc|snprintfcat|max_threads|curr_threads|nut_report_config_flags|upsdebugx_report_search_paths|nut_prepare_search_paths)'
libnutscan_la_CFLAGS = -I$(top_srcdir)/clients -I$(top_srcdir)/include \
libnutscan_la_CFLAGS = \
-I$(top_builddir)/clients -I$(top_srcdir)/clients \
-I$(top_builddir)/include -I$(top_srcdir)/include \
$(LIBLTDL_CFLAGS) -I$(top_srcdir)/drivers

libnutscan_la_LIBADD += $(top_builddir)/common/libcommonstr.la

nut_scanner_SOURCES = nut-scanner.c
nut_scanner_CFLAGS = -I$(top_srcdir)/clients -I$(top_srcdir)/include
nut_scanner_CFLAGS = \
-I$(top_builddir)/clients -I$(top_srcdir)/clients \
-I$(top_builddir)/include -I$(top_srcdir)/include
nut_scanner_LDADD = libnutscan.la

if WITH_SSL
Expand Down
29 changes: 27 additions & 2 deletions tools/nut-scanner/nutscan-init.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@
#include "nut_platform.h"
#include "nut_stdint.h"

/* Note: generated during build in $(top_builddir)/clients/
* and should be ensured to be here at the right moment by
* the nut-scanner Makefile. */
#include "libupsclient-version.h"

#ifdef WIN32
# if defined HAVE_WINSOCK2_H && HAVE_WINSOCK2_H
# include <winsock2.h>
Expand Down Expand Up @@ -542,12 +547,22 @@ void nutscan_init(void)
#endif /* WITH_FREEIPMI */

/* start of libupsclient for "old NUT" (vs. Avahi) protocol - unconditional */
#ifdef SOFILE_LIBUPSCLIENT
if (!libname) {
libname = get_libname(SOFILE_LIBUPSCLIENT);
}
#endif /* SOFILE_LIBUPSCLIENT */
if (!libname) {
libname = get_libname("libupsclient" SOEXT);
}
#ifdef SOPATH_LIBUPSCLIENT
if (!libname) {
libname = get_libname(SOPATH_LIBUPSCLIENT);
}
#endif /* SOPATH_LIBUPSCLIENT */
#ifdef WIN32
/* TODO: Detect DLL name at build time, or rename it at install time? */
/* e.g. see clients/Makefile.am for version-info value */
/* NOTE: Normally we should detect DLL name at build time,
* see clients/Makefile.am for libupsclient-version.h */
if (!libname) {
libname = get_libname("libupsclient-6" SOEXT);
}
Expand All @@ -566,6 +581,11 @@ void nutscan_init(void)
upsdebugx(1, "%s: get_libname() did not resolve libname for %s, "
"trying to load it with libtool default resolver",
__func__, "NUT Client library");
#ifdef SOFILE_LIBUPSCLIENT
if (!nutscan_avail_nut) {
nutscan_avail_xml_http = nutscan_load_upsclient_library(SOFILE_LIBUPSCLIENT);
}
#endif /* SOFILE_LIBUPSCLIENT */
nutscan_avail_nut = nutscan_load_upsclient_library("libupsclient" SOEXT);
#ifdef WIN32
if (!nutscan_avail_nut) {
Expand All @@ -575,6 +595,11 @@ void nutscan_init(void)
nutscan_avail_nut = nutscan_load_upsclient_library("libupsclient-3" SOEXT);
}
#endif /* WIN32 */
#ifdef SOPATH_LIBUPSCLIENT
if (!nutscan_avail_nut) {
nutscan_avail_xml_http = nutscan_load_upsclient_library(SOPATH_LIBUPSCLIENT);
}
#endif /* SOFILE_LIBUPSCLIENT */
}
upsdebugx(1, "%s: %s to load the library for %s",
__func__, nutscan_avail_nut ? "succeeded" : "failed", "NUT Client library");
Expand Down

0 comments on commit 1d0a132

Please sign in to comment.