Skip to content

Commit 0e02f36

Browse files
authored
Merge 684e886 into f502062
2 parents f502062 + 684e886 commit 0e02f36

File tree

24 files changed

+474
-72
lines changed

24 files changed

+474
-72
lines changed

Makefile.am

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ all-libs-local/include:
221221
### (consume only one of these at a time!)
222222
### Delivers: libcommonversion.la (only version methods)
223223
### Delivers: libparseconf.la libnutconf.la libnutwincompat.la
224+
### May deliver: libnutprivate-common-all.la or libnutprivate-common-client.la for dynamic shared-object linking
224225
### Requires-ext: include/nut_version.h
225226
### Requires-int: libparseconf.la libcommonclient.la
226227
all-libs-local/common: all-libs-local/include
@@ -238,12 +239,12 @@ all-libs-local/clients: all-libs-local/common
238239
+@NUT_VERSION_H_GENERATED=true; export NUT_VERSION_H_GENERATED; \
239240
$(SUBDIR_TGT_RULE)
240241

241-
### Delivers: libdummy.la libdummy_serial.la libdummy_upsdrvquery.la
242+
### Delivers: libdummy_main.la libdummy_serial.la libdummy_upsdrvquery.la
242243
### Delivers: libdummy_mockdrv.la libserial-nutscan.la
243244
### LIB-Requires-ext: common/libcommon.la common/libparseconf.la
244245
### Requires-ext: common/libcommon.la common/libparseconf.la
245246
### Requires-ext: clients/libupsclient.la (dummy-ups only)
246-
### Requires-int: libdummy.la libdummy_upsdrvquery.la
247+
### Requires-int: libdummy_main.la libdummy_upsdrvquery.la
247248
### Requires-int: libdummy_serial.la
248249
all-libs-local/drivers: all-libs-local/common
249250
+@NUT_VERSION_H_GENERATED=true; export NUT_VERSION_H_GENERATED; \
@@ -357,7 +358,7 @@ all/clients: all/common all-libs-local/clients
357358
### Requires-ext: common/libcommon.la common/libparseconf.la
358359
### Requires-ext: common/libcommonversion.la
359360
### Requires-ext: clients/libupsclient.la (dummy-ups only)
360-
### Requires-int: libdummy.la libdummy_upsdrvquery.la
361+
### Requires-int: libdummy_main.la libdummy_upsdrvquery.la
361362
### Requires-int: libdummy_serial.la
362363

363364
# TODO in the future: propagate the knowledge of whether we are building

NEWS.adoc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,11 @@ several `FSD` notifications into one executed action. [PR #3097]
276276
and have a consistent look. Revised some typos along the way. [issue #3194]
277277

278278
- `configure` script options:
279+
* Added an option to `--enable-shared-private-libs` to deliver NUT common
280+
libraries as shared objects used by different NUT binaries, rather than
281+
linking just the used bits into each binary. This has some potential
282+
both for mayhem (so disabled by default) and for significant reduction
283+
of installation footprint. [issue #2800]
279284
* For ages, most recipes for building NUT had customized the `sysconfdir` to
280285
be `/etc/nut`, which is not exactly the *system* configuration directory.
281286
This is finally deprecated, with new `--with-confdir` configuration option

UPGRADING.adoc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,14 @@ Changes from 2.8.4 to 2.8.5
2626

2727
- PLANNED: Keep track of any further API clean-up?
2828
29+
- Added a `configure` script option to `--enable-shared-private-libs` which
30+
allows to deliver NUT common libraries as shared objects used by different
31+
NUT binaries, rather than linking just the used bits into each binary.
32+
This has some potential both for mayhem (so disabled by default) and
33+
for significant reduction of installation footprint. If enabled with
34+
a NUT packaging build, note there would be several more NUT shared
35+
library files to deliver with the packages. [issue #2800]
36+
2937
- For ages, most recipes for building NUT had customized the `sysconfdir` to
3038
be `/etc/nut`, which is not exactly the *system* configuration directory.
3139
This is finally deprecated, with new `--with-confdir` configuration option

clients/Makefile.am

Lines changed: 49 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ CLEANFILES =
1515
# nutclient.cpp for some legacy reason (maybe initial detached development?)
1616
# optionally includes "common.h" with the NUT build setup - and this option
1717
# was never triggered in fact, not until pushed through command line like this:
18-
AM_CXXFLAGS = -DHAVE_NUTCOMMON=1 -I$(top_srcdir)/include
18+
AM_CXXFLAGS = -DHAVE_NUTCOMMON=1 -I$(top_builddir)/include -I$(top_srcdir)/include
1919

2020
# Make sure out-of-dir dependencies exist (especially when dev-building parts):
2121
$(top_builddir)/common/libcommon.la \
@@ -31,18 +31,40 @@ $(top_builddir)/common/libparseconf.la: dummy
3131
$(top_builddir)/common/libcommon.la: $(top_builddir)/common/libparseconf.la
3232
$(top_builddir)/common/libcommonclient.la: $(top_builddir)/common/libparseconf.la
3333

34-
LDADD_FULL = \
34+
LDADD_FULL =
35+
LDADD_CLIENT =
36+
37+
if ENABLE_SHARED_PRIVATE_LIBS
38+
$(top_builddir)/common/libnutprivate-common-all.la \
39+
$(top_builddir)/common/libnutprivate-common-client.la: dummy
40+
+@cd $(@D) && $(MAKE) $(AM_MAKEFLAGS) $(@F)
41+
42+
$(top_builddir)/common/libnutprivate-common-all.la: $(top_builddir)/common/libcommon.la
43+
$(top_builddir)/common/libnutprivate-common-client.la: $(top_builddir)/common/libcommonclient.la
44+
45+
LDADD_FULL += \
46+
$(top_builddir)/common/libnutprivate-common-all.la
47+
48+
LDADD_CLIENT += \
49+
$(top_builddir)/common/libnutprivate-common-client.la
50+
else !ENABLE_SHARED_PRIVATE_LIBS
51+
LDADD_FULL += \
3552
$(top_builddir)/common/libcommon.la \
36-
$(top_builddir)/common/libcommonversion.la \
53+
$(top_builddir)/common/libcommonversion.la
54+
55+
LDADD_CLIENT += \
56+
$(top_builddir)/common/libcommonclient.la \
57+
$(top_builddir)/common/libcommonversion.la
58+
endif !ENABLE_SHARED_PRIVATE_LIBS
59+
60+
LDADD_FULL += \
3761
libupsclient.la \
3862
$(NETLIBS)
3963
if WITH_SSL
4064
LDADD_FULL += $(LIBSSL_LIBS) $(LIBSSL_LDFLAGS_RPATH)
4165
endif WITH_SSL
4266

43-
LDADD_CLIENT = \
44-
$(top_builddir)/common/libcommonclient.la \
45-
$(top_builddir)/common/libcommonversion.la \
67+
LDADD_CLIENT += \
4668
libupsclient.la \
4769
$(NETLIBS)
4870
if WITH_SSL
@@ -56,7 +78,7 @@ LDADD = $(LDADD_CLIENT)
5678
# Avoid per-target CFLAGS, because this will prevent re-use of object
5779
# files. In any case, CFLAGS are only -I options, so there is no harm,
5880
# but only add them if we really use the target.
59-
AM_CFLAGS = -I$(top_srcdir)/include
81+
AM_CFLAGS = -I$(top_builddir)/include -I$(top_srcdir)/include
6082
if WITH_SSL
6183
AM_CFLAGS += $(LIBSSL_CFLAGS)
6284
endif WITH_SSL
@@ -93,31 +115,47 @@ endif WITH_CGI
93115

94116
upsc_SOURCES = upsc.c upsclient.h
95117
upsc_LDADD = $(LDADD_CLIENT) $(top_builddir)/common/libcommonstrjson.la
118+
96119
upscmd_SOURCES = upscmd.c upsclient.h
120+
97121
upsrw_SOURCES = upsrw.c upsclient.h
122+
98123
upslog_SOURCES = upslog.c upsclient.h upslog.h
99124
upslog_LDADD = $(LDADD_FULL)
125+
100126
upsmon_SOURCES = upsmon.c upsmon.h upsclient.h
101127
upsmon_LDADD = $(LDADD_FULL)
128+
102129
if HAVE_WINDOWS_SOCKETS
103130
message_SOURCES = message.c
104131
endif HAVE_WINDOWS_SOCKETS
105132

106133
upssched_SOURCES = upssched.c upssched.h
107-
upssched_LDADD = \
134+
upssched_LDADD =
135+
if ENABLE_SHARED_PRIVATE_LIBS
136+
upssched_LDADD += \
137+
$(top_builddir)/common/libnutprivate-common-client.la
138+
else !ENABLE_SHARED_PRIVATE_LIBS
139+
upssched_LDADD += \
108140
$(top_builddir)/common/libcommonclient.la \
109141
$(top_builddir)/common/libcommonversion.la \
110-
$(top_builddir)/common/libparseconf.la \
142+
$(top_builddir)/common/libparseconf.la
143+
endif !ENABLE_SHARED_PRIVATE_LIBS
144+
145+
upssched_LDADD += \
111146
$(NETLIBS)
112147

113148
upsimage_cgi_SOURCES = upsimage.c upsclient.h upsimagearg.h cgilib.c cgilib.h
114149
upsimage_cgi_LDADD = $(LDADD) $(LIBGD_LDFLAGS)
115150

116151
upsset_cgi_SOURCES = upsset.c upsclient.h cgilib.c cgilib.h
152+
117153
upsstats_cgi_SOURCES = upsstats.c upsclient.h status.h upsstats.h \
118154
upsimagearg.h cgilib.c cgilib.h
119155
upsstats_cgi_LDADD = $(LDADD_CLIENT) $(top_builddir)/common/libcommonstrjson.la
120156

157+
################################## Plain C client library (libupsclient) :
158+
121159
# not LDADD... why?
122160
libupsclient_la_SOURCES = upsclient.c upsclient.h
123161
# NOTE: The library does not require libcommonversion.la
@@ -185,6 +223,8 @@ libupsclient-version.h: libupsclient.la
185223
rm -f "$@.tmp.$$$$" ; \
186224
exit $$RES
187225

226+
################################## C++ client library (libnutclient) :
227+
188228
if HAVE_CXX11
189229
# libnutclient version information and build
190230
libnutclient_la_SOURCES = nutclient.h nutclient.cpp

clients/upsc.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,10 @@ int main(int argc, char **argv)
397397
}
398398
upsdebugx(1, "Starting NUT client: %s", prog);
399399

400+
#if (defined NUT_PLATFORM_AIX) && (defined ENABLE_SHARED_PRIVATE_LIBS) && ENABLE_SHARED_PRIVATE_LIBS
401+
callback_upsconf_args = do_upsconf_args;
402+
#endif
403+
400404
while ((i = getopt(argc, argv, "+hlLcVW:j")) != -1) {
401405

402406
switch (i)
@@ -492,6 +496,6 @@ int main(int argc, char **argv)
492496
/* Formal do_upsconf_args implementation to satisfy linker on AIX */
493497
#if (defined NUT_PLATFORM_AIX)
494498
void do_upsconf_args(char *upsname, char *var, char *val) {
495-
fatalx(EXIT_FAILURE, "INTERNAL ERROR: formal do_upsconf_args called");
499+
fatalx(EXIT_FAILURE, "INTERNAL ERROR: formal do_upsconf_args called");
496500
}
497501
#endif /* end of #if (defined NUT_PLATFORM_AIX) */

clients/upscmd.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,10 @@ int main(int argc, char **argv)
308308
}
309309
upsdebugx(1, "Starting NUT client: %s", prog);
310310

311+
#if (defined NUT_PLATFORM_AIX) && (defined ENABLE_SHARED_PRIVATE_LIBS) && ENABLE_SHARED_PRIVATE_LIBS
312+
callback_upsconf_args = do_upsconf_args;
313+
#endif
314+
311315
while ((i = getopt(argc, argv, "+lhu:p:t:wVW:")) != -1) {
312316

313317
switch (i)

clients/upslog.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,10 @@ int main(int argc, char **argv)
520520
logformat = DEFAULT_LOGFORMAT;
521521
user = RUN_AS_USER;
522522

523+
#if (defined NUT_PLATFORM_AIX) && (defined ENABLE_SHARED_PRIVATE_LIBS) && ENABLE_SHARED_PRIVATE_LIBS
524+
callback_upsconf_args = do_upsconf_args;
525+
#endif
526+
523527
print_banner_once(prog, 0);
524528

525529
while ((i = getopt(argc, argv, "+hDs:l:i:d:Nf:u:Vp:FBm:W:")) != -1) {
@@ -1027,6 +1031,6 @@ int main(int argc, char **argv)
10271031
/* Formal do_upsconf_args implementation to satisfy linker on AIX */
10281032
#if (defined NUT_PLATFORM_AIX)
10291033
void do_upsconf_args(char *upsname, char *var, char *val) {
1030-
fatalx(EXIT_FAILURE, "INTERNAL ERROR: formal do_upsconf_args called");
1034+
fatalx(EXIT_FAILURE, "INTERNAL ERROR: formal do_upsconf_args called");
10311035
}
10321036
#endif /* end of #if (defined NUT_PLATFORM_AIX) */

clients/upsrw.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -666,6 +666,10 @@ int main(int argc, char **argv)
666666
}
667667
upsdebugx(1, "Starting NUT client: %s", prog);
668668

669+
#if (defined NUT_PLATFORM_AIX) && (defined ENABLE_SHARED_PRIVATE_LIBS) && ENABLE_SHARED_PRIVATE_LIBS
670+
callback_upsconf_args = do_upsconf_args;
671+
#endif
672+
669673
while ((i = getopt(argc, argv, "+hls:p:t:u:wVW:")) != -1) {
670674
switch (i)
671675
{

common/Makefile.am

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,35 @@ AM_LDFLAGS = -no-undefined
1515
EXTRA_DIST =
1616
CLEANFILES =
1717

18+
# Track unique NUT implementation-detail libraries that are commonly
19+
# used in different programs, and may get bundled into a shared lib.
20+
# Note that for rebuild-time optimization with static libraries, we
21+
# have historically used a number of source-file selections which may
22+
# overlap (e.g. libcommon includes libcommonclient and some more).
1823
noinst_LTLIBRARIES = libparseconf.la libcommon.la libcommonclient.la
1924
lib_LTLIBRARIES =
2025

26+
if ENABLE_SHARED_PRIVATE_LIBS
27+
### Hopefully we can bundle this code together and
28+
### install this somewhat away from the public eye?..
29+
### We still do build static (noinst) libs to include
30+
### them into shared library files that should remain
31+
### compatible for existing consumers (in/out of tree).
32+
lib_LTLIBRARIES += libnutprivate-common-all.la
33+
libnutprivate_common_all_la_SOURCES =
34+
libnutprivate_common_all_la_LIBADD = libcommon.la libcommonversion.la
35+
36+
lib_LTLIBRARIES += libnutprivate-common-client.la
37+
libnutprivate_common_client_la_SOURCES =
38+
libnutprivate_common_client_la_LIBADD = libcommonclient.la libcommonversion.la
39+
40+
if HAVE_WINDOWS
41+
# Many versions of MingW seem to fail to build non-static DLL without this
42+
libnutprivate_common_all_la_LDFLAGS = -no-undefined
43+
libnutprivate_common_client_la_LDFLAGS = -no-undefined
44+
endif HAVE_WINDOWS
45+
endif ENABLE_SHARED_PRIVATE_LIBS
46+
2147
# We define the recipe below in any case, but only activate it by default
2248
# if the build configuration tells us to:
2349
if WITH_DEV_LIBNUTCONF

common/upsconf.c

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/* upsconf.c - code for handling ups.conf ini-style parsing
22
33
Copyright (C) 2001 Russell Kroll <[email protected]>
4+
2026 Jim Klimov <[email protected]>
45
56
This program is free software; you can redistribute it and/or modify
67
it under the terms of the GNU General Public License as published by
@@ -30,12 +31,24 @@
3031

3132
static char *ups_section;
3233

34+
void (*callback_upsconf_args)(char *upsname, char *var, char *val) = NULL;
35+
3336
/* handle arguments separated by parseconf */
3437
static void conf_args(size_t numargs, char **arg)
3538
{
3639
if (numargs < 1)
3740
return;
3841

42+
if (callback_upsconf_args == NULL) {
43+
#if (defined ENABLE_SHARED_PRIVATE_LIBS) && ENABLE_SHARED_PRIVATE_LIBS
44+
upsdebugx(1, "%s: coding error: when building NUT with ENABLE_SHARED_PRIVATE_LIBS mode, 'callback_upsconf_args' must be initialized early in ultimate program code", __func__);
45+
fatalx(EXIT_FAILURE, "FATAL: Dynamic consumer of a NUT private library was not initialized correctly");
46+
#else
47+
/* We should see the original method in the binary in statically linked scope */
48+
callback_upsconf_args = do_upsconf_args;
49+
#endif
50+
}
51+
3952
/* look for section headers - [upsname] */
4053
if ((arg[0][0] == '[') && (arg[0][strlen(arg[0])-1] == ']')) {
4154

@@ -48,7 +61,7 @@ static void conf_args(size_t numargs, char **arg)
4861

4962
/* handle 'foo' (flag) */
5063
if (numargs == 1) {
51-
do_upsconf_args(ups_section, arg[0], NULL);
64+
callback_upsconf_args(ups_section, arg[0], NULL);
5265
return;
5366
}
5467

@@ -57,7 +70,7 @@ static void conf_args(size_t numargs, char **arg)
5770

5871
/* handle 'foo = bar', 'foo=bar', 'foo =bar' or 'foo= bar' forms */
5972
if (!strcmp(arg[1], "=")) {
60-
do_upsconf_args(ups_section, arg[0], arg[2]);
73+
callback_upsconf_args(ups_section, arg[0], arg[2]);
6174
return;
6275
}
6376
}
@@ -68,7 +81,7 @@ static void upsconf_err(const char *errmsg)
6881
upslogx(LOG_ERR, "Fatal error in parseconf(ups.conf): %s", errmsg);
6982
}
7083

71-
/* open the ups.conf, parse it, and call back do_upsconf_args()
84+
/* open the ups.conf, parse it, and call back callback_upsconf_args()
7285
* returns -1 (or aborts the program) in case of errors;
7386
* returns 1 if processing finished successfully
7487
* See also reload_flag support in main.c for live-reload feature

0 commit comments

Comments
 (0)