Skip to content

Commit b05bdcd

Browse files
Add snmp and net-snmp support for macOS and Linux (#946)
Co-authored-by: Marc <[email protected]>
1 parent 6a4ad34 commit b05bdcd

File tree

12 files changed

+234
-3
lines changed

12 files changed

+234
-3
lines changed

config/ext.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -756,6 +756,18 @@
756756
"apcu"
757757
]
758758
},
759+
"snmp": {
760+
"support": {
761+
"Windows": "wip",
762+
"BSD": "wip"
763+
},
764+
"type": "builtin",
765+
"arg-type-unix": "with",
766+
"arg-type-windows": "with",
767+
"lib-depends": [
768+
"net-snmp"
769+
]
770+
},
759771
"soap": {
760772
"support": {
761773
"BSD": "wip"

config/lib.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -697,6 +697,17 @@
697697
"libncurses.a"
698698
]
699699
},
700+
"net-snmp": {
701+
"source": "net-snmp",
702+
"pkg-configs": [
703+
"netsnmp",
704+
"netsnmp-agent"
705+
],
706+
"lib-depends": [
707+
"openssl",
708+
"zlib"
709+
]
710+
},
700711
"nghttp2": {
701712
"source": "nghttp2",
702713
"static-libs-unix": [

config/source.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -820,6 +820,14 @@
820820
"path": "COPYING"
821821
}
822822
},
823+
"net-snmp": {
824+
"type": "ghtagtar",
825+
"repo": "net-snmp/net-snmp",
826+
"license": {
827+
"type": "file",
828+
"path": "COPYING"
829+
}
830+
},
823831
"nghttp2": {
824832
"type": "ghrel",
825833
"repo": "nghttp2/nghttp2",

src/SPC/builder/extension/snmp.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace SPC\builder\extension;
6+
7+
use SPC\builder\Extension;
8+
use SPC\store\FileSystem;
9+
use SPC\util\CustomExt;
10+
use SPC\util\PkgConfigUtil;
11+
12+
#[CustomExt('snmp')]
13+
class snmp extends Extension
14+
{
15+
public function patchBeforeBuildconf(): bool
16+
{
17+
// Overwrite m4 config using newer PHP version
18+
if ($this->builder->getPHPVersionID() < 80400) {
19+
FileSystem::copy(ROOT_DIR . '/src/globals/extra/snmp-ext-config-old.m4', "{$this->source_dir}/config.m4");
20+
}
21+
$libs = implode(' ', PkgConfigUtil::getLibsArray('netsnmp'));
22+
FileSystem::replaceFileStr(
23+
"{$this->source_dir}/config.m4",
24+
'PHP_EVAL_LIBLINE([$SNMP_LIBS], [SNMP_SHARED_LIBADD])',
25+
"SNMP_LIBS=\"{$libs}\"\nPHP_EVAL_LIBLINE([\$SNMP_LIBS], [SNMP_SHARED_LIBADD])"
26+
);
27+
return true;
28+
}
29+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace SPC\builder\linux\library;
6+
7+
class net_snmp extends LinuxLibraryBase
8+
{
9+
use \SPC\builder\unix\library\net_snmp;
10+
11+
public const NAME = 'net-snmp';
12+
}

src/SPC/builder/linux/library/openssl.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public function build(): void
7878
if (!str_contains($file = FileSystem::readFile(BUILD_LIB_PATH . '/pkgconfig/libcrypto.pc'), 'prefix=')) {
7979
FileSystem::writeFile(BUILD_LIB_PATH . '/pkgconfig/libcrypto.pc', 'prefix=' . BUILD_ROOT_PATH . "\n" . $file);
8080
}
81-
FileSystem::replaceFileRegex(BUILD_LIB_PATH . '/pkgconfig/libcrypto.pc', '/Libs.private:.*/m', 'Libs.private: ${libdir}/libz.a');
81+
FileSystem::replaceFileRegex(BUILD_LIB_PATH . '/pkgconfig/libcrypto.pc', '/Libs.private:.*/m', 'Requires.private: zlib');
8282
FileSystem::replaceFileRegex(BUILD_LIB_PATH . '/cmake/OpenSSL/OpenSSLConfig.cmake', '/set\(OPENSSL_LIBCRYPTO_DEPENDENCIES .*\)/m', 'set(OPENSSL_LIBCRYPTO_DEPENDENCIES "${OPENSSL_LIBRARY_DIR}/libz.a")');
8383
}
8484
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace SPC\builder\macos\library;
6+
7+
class net_snmp extends MacOSLibraryBase
8+
{
9+
use \SPC\builder\unix\library\net_snmp;
10+
11+
public const NAME = 'net-snmp';
12+
}

src/SPC/builder/macos/library/openssl.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ protected function build(): void
6363
if (!str_contains($file = FileSystem::readFile(BUILD_LIB_PATH . '/pkgconfig/libcrypto.pc'), 'prefix=')) {
6464
FileSystem::writeFile(BUILD_LIB_PATH . '/pkgconfig/libcrypto.pc', 'prefix=' . BUILD_ROOT_PATH . "\n" . $file);
6565
}
66-
FileSystem::replaceFileRegex(BUILD_LIB_PATH . '/pkgconfig/libcrypto.pc', '/Libs.private:.*/m', 'Libs.private: ${libdir}/libz.a');
66+
FileSystem::replaceFileRegex(BUILD_LIB_PATH . '/pkgconfig/libcrypto.pc', '/Libs.private:.*/m', 'Requires.private: zlib');
6767
FileSystem::replaceFileRegex(BUILD_LIB_PATH . '/cmake/OpenSSL/OpenSSLConfig.cmake', '/set\(OPENSSL_LIBCRYPTO_DEPENDENCIES .*\)/m', 'set(OPENSSL_LIBCRYPTO_DEPENDENCIES "${OPENSSL_LIBRARY_DIR}/libz.a")');
6868
}
6969
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace SPC\builder\unix\library;
6+
7+
use SPC\store\FileSystem;
8+
use SPC\util\executor\UnixAutoconfExecutor;
9+
10+
trait net_snmp
11+
{
12+
public function patchBeforeBuild(): bool
13+
{
14+
if (PHP_OS_FAMILY === 'Linux') {
15+
FileSystem::replaceFileStr("{$this->source_dir}/configure", 'LIBS="-lssl ${OPENSSL_LIBS}"', 'LIBS="-lssl ${OPENSSL_LIBS} -lpthread -ldl"');
16+
return true;
17+
}
18+
return false;
19+
}
20+
21+
protected function build(): void
22+
{
23+
// use --static for PKG_CONFIG
24+
UnixAutoconfExecutor::create($this)
25+
->setEnv(['PKG_CONFIG' => getenv('PKG_CONFIG') . ' --static'])
26+
->configure(
27+
'--disable-mibs',
28+
'--without-nl',
29+
'--disable-agent',
30+
'--disable-applications',
31+
'--disable-manuals',
32+
'--disable-scripts',
33+
'--disable-embedded-perl',
34+
'--without-perl-modules',
35+
'--with-out-mib-modules="if-mib host disman/event-mib ucd-snmp/diskio mibII"',
36+
'--with-out-transports="Unix"',
37+
'--with-mib-modules=""',
38+
'--enable-mini-agent',
39+
'--with-default-snmp-version="3"',
40+
'--with-sys-contact="@@no.where"',
41+
'--with-sys-location="Unknown"',
42+
'--with-logfile="/var/log/snmpd.log"',
43+
'--with-persistent-directory="/var/lib/net-snmp"',
44+
'--with-openssl=' . BUILD_ROOT_PATH,
45+
'--with-zlib=' . BUILD_ROOT_PATH,
46+
)->make(with_install: 'installheaders installlibs install_pkgconfig');
47+
$this->patchPkgconfPrefix();
48+
}
49+
}

src/SPC/doctor/item/LinuxToolCheckList.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class LinuxToolCheckList
4040
'tar', 'unzip', 'gzip', 'gcc', 'g++',
4141
'bzip2', 'cmake', 'patch', 'which',
4242
'xz', 'libtool', 'gettext-devel',
43-
'patchelf',
43+
'patchelf', 'file',
4444
];
4545

4646
public const TOOLS_ARCH = [

0 commit comments

Comments
 (0)