Add ext-snmp

This commit is contained in:
crazywhalecc 2026-03-16 16:48:50 +08:00
parent 3f812fe5fc
commit 21e2a0194c
No known key found for this signature in database
GPG Key ID: 1F4BDD59391F2680
2 changed files with 40 additions and 0 deletions

View File

@ -241,6 +241,12 @@ ext-simplexml:
arg-type@unix: '--enable-simplexml@shared_suffix@ --with-libxml=@build_root_path@' arg-type@unix: '--enable-simplexml@shared_suffix@ --with-libxml=@build_root_path@'
arg-type@windows: with arg-type@windows: with
build-with-php: true build-with-php: true
ext-snmp:
type: php-extension
depends:
- net-snmp
php-extension:
arg-type: with
ext-sockets: ext-sockets:
type: php-extension type: php-extension
ext-sqlite3: ext-sqlite3:

View File

@ -0,0 +1,34 @@
<?php
declare(strict_types=1);
namespace Package\Extension;
use Package\Target\php;
use StaticPHP\Attribute\Package\BeforeStage;
use StaticPHP\Attribute\Package\Extension;
use StaticPHP\Attribute\PatchDescription;
use StaticPHP\Package\PhpExtensionPackage;
use StaticPHP\Util\FileSystem;
use StaticPHP\Util\PkgConfigUtil;
#[Extension('snmp')]
class snmp extends PhpExtensionPackage
{
#[BeforeStage('php', [php::class, 'buildconfForUnix'], 'ext-snmp')]
#[PatchDescription('Fix snmp extension compile error when building with older PHP version and newer net-snmp library')]
public function patchBeforeBuildconf(): bool
{
// Overwrite m4 config using newer PHP version
if (php::getPHPVersionID() < 80400) {
FileSystem::copy(ROOT_DIR . '/src/globals/extra/snmp-ext-config-old.m4', "{$this->getSourceDir()}/config.m4");
}
$libs = implode(' ', PkgConfigUtil::getLibsArray('netsnmp'));
FileSystem::replaceFileStr(
"{$this->getSourceDir()}/config.m4",
'PHP_EVAL_LIBLINE([$SNMP_LIBS], [SNMP_SHARED_LIBADD])',
"SNMP_LIBS=\"{$libs}\"\nPHP_EVAL_LIBLINE([\$SNMP_LIBS], [SNMP_SHARED_LIBADD])"
);
return true;
}
}