Debian Codegraph @

ci/net-snmp-configure

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