Debian Codegraph @

ci/net-snmp-configure

raw ◀ ▶
Source reconstructed at patch state 0 of 1 — not the installed (fully patched) source.
1 Debian patch touch this file
1 #!/usr/bin/env bash
2
3 ssl_include_path() {
4 case "$(uname)" in
5 MINGW32*)
6 echo /mingw32/include/openssl;;
7 MINGW64*)
8 echo /mingw64/include/openssl;;
9 *)
10 echo "${with_openssl:-/usr}/include/openssl"
11 ;;
12 esac
13 }
14
15 rpm_version() {
16 if type -p rpm >/dev/null 2>&1; then
17 rpm -q --qf '%{version}\n' "$1" 2>/dev/null | grep -v 'not installed'
18 fi
19 }
20
21 dpkg_version() {
22 type -p dpkg-query >/dev/null 2>&1 &&
23 dpkg-query --show -f '${Version}\n' "$1" 2>/dev/null | grep -v '^$'
24 }
25
26 pacman_version() {
27 if type -p pacman >/dev/null 2>&1; then
28 pacman -Q "$1" 2>/dev/null | sed -n 's/^[^[:blank:]]*[[:blank:]]*//p'
29 fi
30 }
31
32 apk_version() {
33 if type -p apk >/dev/null 2>&1; then
34 apk info -d "$1" | sed -n "s/^$1-\(.*\)-r[0-9]* description:/\1/p"
35 fi
36 }
37
38 freebsd_pkg_version() {
39 local pkg ver
40
41 for pkg in "$@"; do
42 ver=$(pkg info "$pkg" 2>/dev/null |
43 sed -n 's/^Version[[:blank:]]*:[[:blank:]]*//p') &&
44 [ -n "$ver" ] && echo "$ver" && return
45 done
46 return 1
47 }
48
49 # Given the name of a compiler executable ($1), derive the compiler type (gcc,
50 # clang, xlc, ...).
51 compiler_type() {
52 "$1" -v 2>&1 |
53 sed -n 's/^gcc version .*/gcc/p;s/^clang version .*/clang/p;s/.*xlc.*IBM.*xlc.*/xlc/p'
54 }
55
56 scriptdir=$(cd "$(dirname "$0")" && pwd)
57 branch_name="$1"
58 shift
59
60 case "$MODE" in
61 Android)
62 ;;
63 *)
64 libatmver="$(rpm_version linux-atm-devel;
65 dpkg_version libatm1-dev)"
66 echo "libatmver=$libatmver"
67
68 libmysqlver="$(rpm_version libmariadb-devel;
69 for p in libmariadb-dev libmariadb-dev-compat \
70 libmariadbclient-dev libmariadb-client-lgpl-dev; do
71 dpkg_version "$p" && break;
72 done;
73 pacman_version mingw-w64-x86_64-libmariadbclient)"
74 echo "libmysqlver=$libmysqlver"
75
76 libsensorsver="$(rpm_version libsensors4-devel;
77 dpkg_version libsensors-dev libsensors4-dev)"
78 echo "libsensorsver=$libsensorsver"
79
80 if echo "$*" | grep -q wolfssl; then
81 have_ssl=true
82 elif ! echo "$*" | grep -Eq 'with-openssl=(no|internal)|without-openssl'; then
83 have_ssl=true
84 fi
85 echo "have_ssl=$have_ssl"
86
87 case "$(uname)" in
88 FreeBSD*)
89 libssh2ver="$(freebsd_pkg_version libssh2 2>/dev/null)";;
90 Linux*)
91 libssh2ver="$(for p in openssh-devel libssh2-devel libssh-devel
92 do
93 rpm_version "$p";
94 done |
95 head -n1;
96 for p in libopenssh2 libssh2-1-dev libssh-dev; do
97 dpkg_version "$p";
98 done;
99 pacman_version mingw-w64-x86_64-libssh2)"
100 ;;
101 esac
102 echo "libssh2ver=$libssh2ver"
103
104 case "$(uname)" in
105 FreeBSD*)
106 perldevver="$(freebsd_pkg_version perl5 2>/dev/null)";;
107 Linux*)
108 perldevver="$(rpm_version perl;
109 dpkg_version libperl-dev;
110 pacman_version mingw-w64-x86_64-perl)"
111 ;;
112 esac
113 echo "perldevver=$perldevver"
114 # Set the perlcc variable.
115 eval "perl$(perl -V:cc)"
116 perlcc=$(compiler_type "$perlcc")
117 echo "perlcc=$perlcc"
118 ;;
119 esac
120
121 options=()
122 options+=(--enable-developer)
123 options+=("--prefix=/usr/local/net-snmp-${branch_name}")
124 options+=("--with-cflags=$CFLAGS")
125 options+=(--with-defaults)
126 transports=()
127 # Mib names can be found as follows:
128 # (cd agent/mibgroup &&
129 # git grep -lE 'void[[:blank:]]*init_.*\(void\)|config_require\(' |
130 # sed -n 's/\.h$//p')
131 mibs=()
132 mibs+=(agent/extend)
133 case "$MODE" in
134 disable-ipv6)
135 options+=(--disable-ipv6)
136 ;;
137 *)
138 options+=(--enable-ipv6)
139 ;;
140 esac
141 case "$MODE" in
142 read-only)
143 ;;
144 Android)
145 options+=(
146 --disable-embedded-perl
147 --host=aarch64-linux-android33
148 --with-openssl=internal
149 --with-out-mib-modules="if-mib default_modules"
150 --without-perl-modules
151 --without-python-modules
152 )
153 ;;
154 *)
155 mibs+=(examples/data_set)
156 mibs+=(examples/delayed_instance)
157 mibs+=(examples/example)
158 mibs+=(examples/notification)
159 mibs+=(examples/scalar_int)
160 mibs+=(examples/ucdDemoPublic)
161 mibs+=(examples/watched)
162 mibs+=(smux)
163 ;;
164 esac
165
166 case "$(uname):${MODE}" in
167 *:Android*)
168 ;;
169 Linux*)
170 options+=(--enable-new-features)
171 case "$MODE" in
172 mini*|read-only|without-nl)
173 ;;
174 *)
175 mibs+=(deliver/deliverByNotify)
176 mibs+=(disman/event)
177 mibs+=(disman/expression)
178 mibs+=(disman/mteEventNotificationTable)
179 mibs+=(disman/mteEventTable)
180 mibs+=(disman/mteObjectsTable)
181 mibs+=(disman/mteTriggerBooleanTable)
182 mibs+=(disman/mteTriggerDeltaTable)
183 mibs+=(disman/mteTriggerExistenceTable)
184 mibs+=(disman/mteTriggerTable)
185 mibs+=(disman/mteTriggerThresholdTable)
186 mibs+=(disman/nslookup-mib)
187 mibs+=(disman/ping-mib)
188 mibs+=(disman/schedule)
189 mibs+=(disman/traceroute-mib)
190 mibs+=(etherlike-mib)
191 mibs+=(examples/netSnmpHostsTable)
192 mibs+=(hardware/cpu)
193 mibs+=(hardware/fsys)
194 mibs+=(hardware/memory)
195 mibs+=(host)
196 mibs+=(ip-forward-mib)
197 mibs+=(ip-mib/inetNetToMediaTable)
198 mibs+=(ip-mib/ipDefaultRouterTable)
199 mibs+=(ip-mib/ipv4InterfaceTable)
200 mibs+=(ip-mib/ipv6InterfaceTable)
201 mibs+=(ip-mib/ipv6ScopeZoneIndexTable)
202 mibs+=(mibII/mta_sendmail)
203 mibs+=(misc/ipfwacc)
204 mibs+=(sctp-mib)
205 mibs+=(snmp-notification-mib)
206 mibs+=(tcp-mib)
207 mibs+=(testhandler)
208 mibs+=(tunnel)
209 mibs+=(ucd-snmp/diskio)
210 if [ -n "$libsensorsver" ]; then
211 mibs+=(hardware/sensors)
212 mibs+=(ucd-snmp/lmsensorsMib)
213 fi
214 mibs+=(ucd-snmp/extensible)
215 mibs+=(udp-mib)
216 mibs+=(rmon-mib)
217 ;;
218 esac
219 if [ -n "$libmysqlver" ]; then
220 options+=(--with-mysql)
221 fi
222 if [ -n "$perldevver" ] && [ "$perlcc" = "$(compiler_type "${CC:-cc}")" ];
223 then
224 options+=(--with-perl-modules)
225 else
226 options+=(--disable-embedded-perl --without-perl-modules)
227 fi
228 if [ -n "$libatmver" ]; then
229 transports+=(AAL5PVC)
230 fi
231 if [ -e /usr/include/netipx/ipx.h ]; then
232 transports+=(IPX)
233 fi
234 transports+=(STD)
235 transports+=(UDPshared)
236 options+=("--with-default-snmp-version=2")
237 options+=("--with-systemd")
238 # Disabled modules because troublesome: Rmon ipfwchains/ipfwchains ucd-snmp/lmSensors
239 ;;
240 darwin*|Darwin*)
241 case "$MODE" in
242 mini*|read-only)
243 ;;
244 *)
245 mibs+=(disman/nslookup-mib)
246 mibs+=(host)
247 mibs+=(if-mib)
248 mibs+=(mibII/mta_sendmail)
249 mibs+=(misc/ipfwacc)
250 mibs+=(snmp-notification-mib)
251 mibs+=(tcp-mib)
252 mibs+=(ucd-snmp/diskio)
253 mibs+=(ucd-snmp/extensible)
254 mibs+=(udp-mib)
255 mibs+=(Rmon)
256 ;;
257 esac
258 options+=("--with-openssl=$(brew --prefix openssl)")
259 ;;
260 FreeBSD*)
261 case "$MODE" in
262 mini*|read-only)
263 ;;
264 *)
265 mibs+=(disman/nslookup-mib)
266 mibs+=(host)
267 mibs+=(if-mib)
268 mibs+=(mibII/mta_sendmail)
269 mibs+=(misc/ipfwacc)
270 mibs+=(sctp-mib)
271 mibs+=(snmp-notification-mib)
272 mibs+=(tcp-mib)
273 mibs+=(ucd-snmp/diskio)
274 mibs+=(ucd-snmp/extensible)
275 mibs+=(udp-mib)
276 mibs+=(Rmon)
277 ;;
278 esac
279 options+=(--disable-embedded-perl --without-perl-modules)
280 ;;
281 CYGWIN*)
282 export ENV_SEPARATOR=":"
283 mibs+=(ucd-snmp/extensible)
284 mibs+=(winExtDLL)
285 options+=(--disable-embedded-perl --without-perl-modules)
286 ;;
287 MINGW*)
288 options+=(--disable-embedded-perl)
289 mibs+=(host)
290 mibs+=(snmp-notification-mib)
291 mibs+=(ucd-snmp/dlmod)
292 mibs+=(ucd-snmp/extensible)
293 mibs+=(winExtDLL)
294 options+=(--without-perl-modules)
295 ;;
296 MSYS*)
297 options+=(--disable-embedded-perl)
298 mibs+=(host)
299 mibs+=(snmp-notification-mib)
300 mibs+=(ucd-snmp/dlmod)
301 mibs+=(ucd-snmp/extensible)
302 mibs+=(winExtDLL)
303 options+=(--without-perl-modules)
304 # The config.guess script in the Net-SNMP source tree is too old to
305 # recognize the MSYS2 environment. Hence the explicit --build=... option.
306 # See also
307 # http://git.savannah.gnu.org/cgit/automake.git/tree/lib/config.guess.
308 options+=("--build=x86_64-pc-mingw32")
309 ;;
310 *)
311 echo "Unknown OS $(uname)."
312 ;;
313 esac
314
315 with_openssl=""
316 case "$MODE" in
317 wolfssl)
318 with_openssl=wolfssl
319 wolfssl_dir=$(dirname "${scriptdir}")/wolfssl-inst
320 options+=(--with-wolfssl="${wolfssl_dir}")
321 ssl_include_path=${wolfssl_dir}/include/wolfssl/openssl
322 ;;
323 *)
324 with_openssl=""
325 for o in "${options[@]}"; do
326 if [ "${o#--with-openssl=}" != "$o" ]; then
327 with_openssl="${o#--with-openssl=}"
328 fi
329 done
330 ssl_include_path=$(ssl_include_path)
331 ;;
332 esac
333 echo "ssl_include_path=${ssl_include_path}"
334 if [ -z "$have_ssl" ]; then
335 options+=("--with-openssl=internal")
336 with_openssl="internal"
337 else
338 if grep -rq 'BIO_dgram_get_peer(void)\|define BIO_dgram_get_peer' "${ssl_include_path}" 2>/dev/null; then
339 transports+=(DTLSUDP TLSTCP)
340 else
341 echo "BIO_dgram_get_peer() not found:"
342 grep -r BIO_dgram_get_peer "${ssl_include_path}"
343 fi
344 if [ "$MODE" != "read-only" ]; then
345 # these MIB modules do not support read-only
346 if [ -e "${ssl_include_path}/dh.h" ]; then
347 mibs+=(snmp-usm-dh-objects-mib)
348 fi
349 if [ -e "${ssl_include_path}/ssl.h" ] &&
350 [ "${ssl_include_path%/wolfssl/openssl}" = "${ssl_include_path}" ]
351 then
352 mibs+=(tlstm-mib)
353 fi
354 mibs+=(tsm-mib)
355 fi
356 fi
357 if [ "$with_openssl" != "internal" ] &&
358 [ -e "${ssl_include_path}/aes.h" ] &&
359 [ -e "${ssl_include_path}/evp.h" ] &&
360 grep -qw EVP_aes_256_cfb "${ssl_include_path}/evp.h"; then
361 options+=(--enable-blumenthal-aes)
362 fi
363 security_modules=(usm tsm)
364 if [ "${MODE}" != Android ] && [ -e /usr/include/krb5.h ]; then
365 security_modules+=(ksm)
366 fi
367 case "$(uname):${MODE}" in
368 *:Android*)
369 ;;
370 MSYS*|MINGW*)
371 # Do not enable Python support on MinGW32 nor for the MSYS build
372 # environment because the Python interpreter has been built on these
373 # environments with Visual C++. That compiler is incompatible with gcc.
374 ;;
375 Darwin*)
376 case "$(uname -r)" in
377 11.*|12.*)
378 if python3 -c 'import setuptools' 1>/dev/null 2>&1; then
379 options+=(--with-python-modules)
380 fi
381 ;;
382 *)
383 ;;
384 esac
385 ;;
386 *)
387 # To do: fix the build of the Python modules when using WolfSSL.
388 if python3 -c 'import setuptools' 1>/dev/null 2>&1 &&
389 [ "$MODE" != "wolfssl" ]; then
390 options+=(--with-python-modules)
391 fi
392 esac
393
394 case "$MODE" in
395 disable-ipv6)
396 ;;
397 disable-set)
398 options+=(--disable-set-support);;
399 mini)
400 options+=(--enable-mini-agent);;
401 minimalist)
402 options+=(--enable-minimalist);;
403 read-only)
404 options+=(--enable-read-only);;
405 without-nl)
406 options+=(--without-nl);;
407 regular|wolfssl|Android|"")
408 ;;
409 *)
410 echo "Error: unknown build type $MODE"
411 exit 1;;
412 esac
413
414 [ "${libssh2ver#2}" != "${libssh2ver}" ] && transports+=(SSH)
415 set -x
416 ./configure "${options[@]}" --with-transports="${transports[*]}" \
417 --with-security-modules="${security_modules[*]}" \
418 --with-mib-modules="${mibs[*]}" \
419 CFLAGS="$CFLAGS" CPPFLAGS="$CFLAGS" LDFLAGS="$LDFLAGS" "$@"