Skip to content

Commit 3a30c29

Browse files
petkNattyNarwhal
andauthored
Autotools: Add pkg-config support for NET-SNMP library (#15261)
NET-SNMP has pkg-config support since 5.8.1 This optionally finds the NET-SNMP library using pkg-config or falls back to find library on the system with net-snmp-config. The configure option argument (--with-snmp=DIR) works like before (path to the net-snmp-config). When explicitly using the DIR argument, the pkg-config check is silently skipped. When not using DIR argument, the SNMP_CFLAGS and SNMP_LIBS can be also used to find the NET-SNMP library: ./configure --with-snmp \ SNMP_CFLAGS=-I/path/to/net-snmp/include \ SNMP_LIBS="-L/path/to/net-snmp -lnetsnmp" Co-authored-by: Calvin Buckley <[email protected]>
1 parent 8044db1 commit 3a30c29

File tree

2 files changed

+40
-30
lines changed

2 files changed

+40
-30
lines changed

UPGRADING.INTERNALS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,8 @@ PHP 8.4 INTERNALS UPGRADE NOTES
192192
- Added pkg-config support to find GNU MP library. As a fallback default
193193
system paths are searched. When a directory argument is provided
194194
(--with-gmp=DIR), it will be used instead of the pkg-config.
195+
- Added optional pkg-config support to find NET-SNMP library. As a fallback
196+
net-snmp-config utility is used like before.
195197
- Removed BC enable_pear variable check due to --enable-pear configure option
196198
once used (use with_pear variable name).
197199
- Cache variables synced to php_cv_* naming scheme. If you use them for

ext/snmp/config.m4

Lines changed: 38 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,48 @@
11
PHP_ARG_WITH([snmp],
22
[for SNMP support],
33
[AS_HELP_STRING([[--with-snmp[=DIR]]],
4-
[Include SNMP support])])
4+
[Include SNMP support. Use PKG_CONFIG_PATH (or SNMP_CFLAGS and SNMP_LIBS)
5+
environment variables, or alternatively the optional DIR argument to
6+
customize where to look for the net-snmp-config utility of the NET-SNMP
7+
library.])])
58

69
if test "$PHP_SNMP" != "no"; then
10+
snmp_found=no
11+
AS_VAR_IF([PHP_SNMP], [yes],
12+
[PKG_CHECK_MODULES([SNMP], [netsnmp >= 5.3], [snmp_found=yes], [:])])
713

8-
if test "$PHP_SNMP" = "yes"; then
9-
AC_PATH_PROG(SNMP_CONFIG,net-snmp-config,,[/usr/local/bin:$PATH])
10-
else
11-
SNMP_CONFIG="$PHP_SNMP/bin/net-snmp-config"
12-
fi
14+
AS_VAR_IF([snmp_found], [no], [
15+
AS_VAR_IF([PHP_SNMP], [yes],
16+
[AC_PATH_PROG([SNMP_CONFIG], [net-snmp-config],, [/usr/local/bin:$PATH])],
17+
[SNMP_CONFIG="$PHP_SNMP/bin/net-snmp-config"])
1318
14-
if test -x "$SNMP_CONFIG"; then
15-
SNMP_LIBS=`$SNMP_CONFIG --netsnmp-libs`
16-
SNMP_LIBS="$SNMP_LIBS `$SNMP_CONFIG --external-libs`"
17-
SNMP_PREFIX=`$SNMP_CONFIG --prefix`
18-
snmp_full_version=`$SNMP_CONFIG --version`
19-
ac_IFS=$IFS
20-
IFS="."
21-
set $snmp_full_version
22-
IFS=$ac_IFS
23-
SNMP_VERSION=`expr [$]1 \* 1000 + [$]2`
24-
if test "$SNMP_VERSION" -ge "5003"; then
25-
if test -n "$SNMP_LIBS" && test -n "$SNMP_PREFIX"; then
26-
PHP_ADD_INCLUDE([${SNMP_PREFIX}/include])
27-
PHP_EVAL_LIBLINE([$SNMP_LIBS], [SNMP_SHARED_LIBADD])
28-
SNMP_LIBNAME=netsnmp
29-
else
30-
AC_MSG_ERROR([Could not find the required paths. Please check your net-snmp installation.])
31-
fi
32-
else
33-
AC_MSG_ERROR([Net-SNMP version 5.3 or greater required (detected $snmp_full_version).])
34-
fi
35-
else
36-
AC_MSG_ERROR([Could not find net-snmp-config binary. Please check your net-snmp installation.])
37-
fi
19+
AS_IF([test ! -x "$SNMP_CONFIG"],
20+
[AC_MSG_ERROR(m4_text_wrap([
21+
Could not find net-snmp-config binary. Please check your net-snmp
22+
installation.
23+
]))])
24+
25+
snmp_version=$($SNMP_CONFIG --version)
26+
AS_VERSION_COMPARE([$snmp_version], [5.3],
27+
[AC_MSG_ERROR(m4_text_wrap([
28+
Net-SNMP version 5.3 or greater required (detected $snmp_version).
29+
]))])
30+
31+
SNMP_PREFIX=$($SNMP_CONFIG --prefix)
32+
SNMP_CFLAGS="-I${SNMP_PREFIX}/include"
33+
SNMP_LIBS=$($SNMP_CONFIG --netsnmp-libs)
34+
SNMP_LIBS="$SNMP_LIBS $($SNMP_CONFIG --external-libs)"
35+
36+
AS_IF([test -z "$SNMP_LIBS" || test -z "$SNMP_PREFIX"],
37+
[AC_MSG_ERROR(m4_text_wrap([
38+
Could not find the required paths. Please check your net-snmp
39+
installation.
40+
]))])
41+
])
42+
43+
PHP_EVAL_INCLINE([$SNMP_CFLAGS])
44+
PHP_EVAL_LIBLINE([$SNMP_LIBS], [SNMP_SHARED_LIBADD])
45+
SNMP_LIBNAME=netsnmp
3846

3947
dnl Test build.
4048
PHP_CHECK_LIBRARY([$SNMP_LIBNAME], [init_snmp],

0 commit comments

Comments
 (0)