Jim Klimov
2023-11-09 d102d57f3de9998bf8dc7d524fdb6652dd070e40
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
#
# This file and its contents are supplied under the terms of the
# Common Development and Distribution License ("CDDL"), version 1.0.
# You may only use this file in accordance with the terms of version
# 1.0 of the CDDL.
#
# A full copy of the text of the CDDL should have accompanied this
# source.  A copy of the CDDL is also available via the Internet at
# http://www.illumos.org/license/CDDL.
#
 
#
# Copyright 2016-2023 Jim Klimov
#
 
# NUT 2.8.0+ is diligently tested to benefit from parallel builds and succeed
USE_PARALLEL_BUILD=    yes
 
include ../../../make-rules/shared-macros.mk
 
COMPONENT_NAME=    nut
COMPONENT_VERSION=    2.8.1
COMPONENT_SUMMARY=    Network UPS Tools (NUT)
COMPONENT_DESCRIPTION=    Network UPS Tools (NUT) is a versatile power-device monitoring toolkit to facilitate safe shutdowns
COMPONENT_SRC=    $(COMPONENT_NAME)-$(COMPONENT_VERSION)
COMPONENT_ARCHIVE=    $(COMPONENT_SRC).tar.gz
COMPONENT_ARCHIVE_HASH=    \
  sha256:7da48ee23b1f0d8d72560bb0af84f5c5ae4dbe35452b84cb49840132e47f099c
COMPONENT_ARCHIVE_URL=    \
  https://github.com/networkupstools/$(COMPONENT_NAME)/releases/download/v$(COMPONENT_VERSION)/$(COMPONENT_SRC).tar.gz
COMPONENT_PROJECT_URL=    https://networkupstools.org
COMPONENT_FMRI=    system/management/$(COMPONENT_NAME)
COMPONENT_CLASSIFICATION=    System/Administration and Configuration
COMPONENT_LICENSE=    GPLv2+
COMPONENT_LICENSE_FILE=    COPYING
 
include $(WS_MAKE_RULES)/common.mk
 
CXXFLAGS += $(CXXFLAGS.$(BITS))
CFLAGS   += $(CFLAGS.$(BITS))
 
# Drop *.8 man pages (we patch to regenerate them into *.1m - see patches/07-man.patch)
# Fix up upsmon.txt encoding that might have gone wrong into the 2.8.1 release tarball
COMPONENT_PREP_ACTION =    ( cd $(SOURCE_DIR) && ./autogen.sh && cd docs/man && rm -f *.8 && { dos2unix upsmon.txt > upsmon.txt.tmp && mv -f upsmon.txt.tmp upsmon.txt; }  )
 
COMPONENT_PRE_CONFIGURE_ACTION =    ( $(CLONEY) $(SOURCE_DIR) $(@D) )
 
# We deliver only 64-bit binaries
CONFIGURE_BINDIR.64 =    $(USRBINDIR)
CONFIGURE_SBINDIR.64 =    $(USRSBINDIR)
 
CONFIGURE_ENV     +=    LDFLAGS="$(LDFLAGS.64)"
 
CONFIGURE_OPTIONS +=    LDFLAGS="$(LDFLAGS.64)"
 
CONFIGURE_OPTIONS +=    --disable-static
CONFIGURE_OPTIONS +=    --enable-shared
 
CONFIGURE_OPTIONS +=    --with-solaris-smf=yes
CONFIGURE_OPTIONS +=    --with-solaris-init=no
CONFIGURE_OPTIONS +=    --with-solaris-pkg-svr4=no
CONFIGURE_OPTIONS +=    --with-solaris-pkg-ips=no
 
CONFIGURE_OPTIONS +=    --with-systemdsystemunitdir=no
CONFIGURE_OPTIONS +=    --with-systemdshutdowndir=no
CONFIGURE_OPTIONS +=    --with-systemdtmpfilesdir=no
 
CONFIGURE_OPTIONS +=    --with-user=nut
CONFIGURE_OPTIONS +=    --with-group=nut
CONFIGURE_OPTIONS +=    --sysconfdir=/etc/nut
CONFIGURE_OPTIONS +=    --sharedstatedir=/usr/share/nut
CONFIGURE_OPTIONS +=    --datarootdir=/usr/share/nut
CONFIGURE_OPTIONS +=    --with-hotplug-dir=no
CONFIGURE_OPTIONS +=    --with-udev-dir=no
 
#  --with-statepath=PATH   path for ups state files (${STATEPATH}, typically
#                          /var/state/ups)
#  --with-altpidpath=PATH  path for NUT driver/upsd .pid files not running as
#                          root (<statepath>)
#  --with-pidpath=PATH     Path for root-owned .pid files (${PIDPATH},
#                          typically /var/run)
#  --with-powerdownflag=PATH
#                          default path for upsmon POWERDOWNFLAG file
#                          (${POWERDOWNFLAG}, typically /etc/killpower)
CONFIGURE_OPTIONS +=    --with-pidpath=/var/run/nut
CONFIGURE_OPTIONS +=    --with-altpidpath=/var/run/nut
CONFIGURE_OPTIONS +=    --with-powerdownflag=/var/run/nut/killpower
CONFIGURE_OPTIONS +=    --with-statepath=/var/db/nut
 
CONFIGURE_OPTIONS +=    --with-dev
CONFIGURE_OPTIONS +=    --with-libltdl
CONFIGURE_OPTIONS +=    --with-ssl
CONFIGURE_OPTIONS +=    --with-openssl
CONFIGURE_OPTIONS +=    --with-gd-includes=-I/usr/include/gd2
 
CONFIGURE_OPTIONS +=    --libexecdir=/usr/lib/nut/bin
CONFIGURE_OPTIONS +=    --with-drvpath=/usr/lib/nut/bin
CONFIGURE_OPTIONS +=    --with-cgipath=/usr/lib/nut/cgi-bin
CONFIGURE_OPTIONS +=    --with-gd-libs=-L/usr/lib/$(MACH64)
 
CONFIGURE_OPTIONS +=    --with-nut-scanner=yes
 
# Minimize guesswork: these are features we can and do build and deliver in
# package manifest, so the build host must have relevant packages installed
CONFIGURE_OPTIONS +=    --with-serial=yes
#CONFIGURE_OPTIONS +=    --with-usb=yes
CONFIGURE_OPTIONS +=    --with-usb=libusb-1.0
CONFIGURE_OPTIONS +=    --with-modbus=yes
CONFIGURE_OPTIONS +=    --with-neon=yes
CONFIGURE_OPTIONS +=    --with-avahi=yes
CONFIGURE_OPTIONS +=    --with-powerman=yes
CONFIGURE_OPTIONS +=    --with-cgi=yes
CONFIGURE_OPTIONS +=    --with-ipmi=yes
CONFIGURE_OPTIONS +=    --with-freeipmi=yes
 
# Likely we'll not have this backend working any time soon
CONFIGURE_OPTIONS +=    --with-linux_i2c=no
CONFIGURE_OPTIONS +=    --with-macosx_ups=no
 
# Note: Link with the correct ISA of net-snmp (for drivers) and gdlib (for cgi)
CONFIGURE_OPTIONS +=    --with-snmp
CONFIGURE_OPTIONS +=    --with-net-snmp-config=$(USRBINDIR)/net-snmp-config-$(BITS)
 
# Note: building the numerous documents of this projects is time-consuming
# and we only need one copy. Also, we don't ship "dblatex" (needed here for
# compiling PDFs) and probably don't require "html-chunked" chapters.
CONFIGURE_OPTIONS +=    --with-doc="man=yes"
 
# NUT-Monitor GUI client
CONFIGURE_OPTIONS +=    --with-nut-monitor=yes
CONFIGURE_OPTIONS +=    --with-pynut=yes
CONFIGURE_OPTIONS +=    --with-python2=no
CONFIGURE_OPTIONS +=    --with-python=python$(PYTHON_VERSION)
 
# Be sure package is squeaky clean
CONFIGURE_OPTIONS +=    --enable-Werror --enable-warnings --enable-Wcolor
CONFIGURE_OPTIONS +=    --enable-keep_nut_report_feature
CONFIGURE_OPTIONS +=    --enable-silent-rules
 
# What do we run in case of `make check`?
CONFIGURE_OPTIONS +=    --enable-spellcheck
# NUT Integration Test suite, can take time and might fail due
# to environment (busy ports, congested hsots and timeouts):
#CONFIGURE_OPTIONS +=    --enable-check-NIT
# No CPPCHECK here yet:
CONFIGURE_OPTIONS +=    --disable-cppcheck
 
CONFIGURE_OPTIONS +=    $(CONFIGURE_OPTIONS.$(BITS))
 
# TOTHINK? variant.opensolaris.zone=global
$(BUILD_DIR)/nut-usb-driver.p5m.include: $(BUILD_DIR)/$(MACH64)/scripts/udev/nut-usbups.rules
    (echo "# NUT USB VID:PID pairs supported by some USB-capable driver"; \
     echo "# Parsed from $< during package build"; \
     echo "driver name=ugen \\" ; \
     grep -E 'ATTR.*idVendor.*idProduct' < "$<" | \
     $(GSED) 's/^.*ATTR{idVendor}=="0*\([a-fA-F0-9][a-fA-F0-9]*\)".*ATTR{idProduct}=="0*\([a-fA-F0-9][a-fA-F0-9]*\)".*$$/    alias="usb\1,\2.*" \\/' ; \
     echo '    perms="* 0664 root nut"' ; \
    ) > "$@"
 
# Inject into build chain, to patch .mogrified file used to create .mangled and beyond
$(BUILD_DIR)/.injected.nut-usb-driver.p5m.include: $(BUILD_DIR)/manifest-$(MACH)-nut-drivers-usb.mogrified $(BUILD_DIR)/nut-usb-driver.p5m.include
    cat "$(BUILD_DIR)/nut-usb-driver.p5m.include" >> "$(BUILD_DIR)/manifest-$(MACH)-nut-drivers-usb.mogrified"
    touch "$@"
 
$(BUILD_DIR)/manifest-$(MACH)-nut-drivers-usb.mangled: $(BUILD_DIR)/nut-usb-driver.p5m.include $(BUILD_DIR)/.injected.nut-usb-driver.p5m.include
 
# NUT-Monitor UI has two similar implementations, for py2gtk and py3qt5.
# The PyNUT.py (general binding) module is written to work with both 2.x
# and 3.x interpreters as the same source file (patched for shebang and
# installed to different vendor/site locations several times in practice).
# Fiddle with packaging:
# * move man1m pages to target directory (see also patches/07-man.patch)
# * move python stuff to vendor-packages
# * make sure full python program name is in the shebang
#   (and note we can not use ...\1${PYVER} because it is
#    also numbers and SED gets confused about group \12 or so)
# * pre-compile PYC files
# * apply a little hack to comment away the import which
#   confuses pkgdepend (it looks for "import" lines and
#   disregards "try/except" around it)
COMPONENT_POST_INSTALL_ACTION += \
    $(MKDIR) $(PROTOUSRSHAREMANDIR)/man1m \
        && $(MV) $(PROTOUSRSHAREMANDIR)/man1/*.1m $(PROTOUSRSHAREMANDIR)/man1m/ \
        || { echo "FAILED to fix up man1m" >&2 ; exit 1; } ; \
    for PYVER in $(PYTHON_VERSIONS) ; do \
        $(MKDIR) "$(PROTOUSRLIBDIR)/python$${PYVER}/vendor-packages" \
            && $(MV) "$(PROTOUSRLIBDIR)/python$${PYVER}/site-packages/"* "$(PROTOUSRLIBDIR)/python$${PYVER}/vendor-packages/" \
            && find "$(PROTOUSRLIBDIR)/python$${PYVER}/vendor-packages/" -name '*.py' | while read F ; do \
                $(GSED) '/^\(\#\!.*\/python\)$$/ s/$$/'"$${PYVER}"'/' -i "$$F" || exit ; \
            done \
        && python$${PYVER} -m compileall "$(PROTOUSRLIBDIR)/python$${PYVER}/vendor-packages" || exit ; \
        case "$${PYVER}" in \
        2.*) python$${PYVER} -c "import pygtk;pygtk.require('2.0');import pynotify" >/dev/null || { \
                echo "Neutering import of pynotify in NUT-Monitor-py2gtk2 for this build with python$${PYVER}" >&2 ; \
                $(GSED) -i "$(PROTOUSRSHAREDIR)/nut/nut-monitor/app/NUT-Monitor-py2gtk2" \
                    -e 's,\(\s\)\(import pynotify\),\1return; \#\#\#NOT_HERE_\2,' || exit ; \
            } ; \
        esac ; \
    done;
 
# Manually added dependencies:
REQUIRED_PACKAGES += text/asciidoc
REQUIRED_PACKAGES += library/augeas-tools
 
# Auto-generated dependencies
PYTHON_REQUIRED_PACKAGES += runtime/python
REQUIRED_PACKAGES += $(GCC_RUNTIME_PKG)
REQUIRED_PACKAGES += $(GXX_RUNTIME_PKG)
REQUIRED_PACKAGES += library/gd
REQUIRED_PACKAGES += library/libmodbus
REQUIRED_PACKAGES += library/libtool/libltdl
REQUIRED_PACKAGES += library/libusb-1
REQUIRED_PACKAGES += library/neon
REQUIRED_PACKAGES += library/python/pyqt5
REQUIRED_PACKAGES += library/security/openssl-31
REQUIRED_PACKAGES += shell/ksh93
REQUIRED_PACKAGES += system/library
REQUIRED_PACKAGES += system/library/math
REQUIRED_PACKAGES += system/management/freeipmi
REQUIRED_PACKAGES += system/management/powerman
REQUIRED_PACKAGES += system/management/snmp/net-snmp