54 lines
1.6 KiB
PHP
Raw Normal View History

2023-10-31 13:09:01 +01:00
<?php
declare(strict_types=1);
namespace SPC\builder\extension;
use SPC\builder\Extension;
2025-07-10 12:59:27 +08:00
use SPC\builder\linux\SystemUtil;
2023-10-31 13:09:01 +01:00
use SPC\exception\WrongUsageException;
2024-07-28 14:02:17 +08:00
use SPC\store\FileSystem;
2023-10-31 13:09:01 +01:00
use SPC\util\CustomExt;
#[CustomExt('imap')]
class imap extends Extension
{
2024-07-28 14:02:17 +08:00
public function patchBeforeBuildconf(): bool
{
if ($this->builder->getLib('openssl')) {
// sometimes imap with openssl does not contain zlib (required by openssl)
// we need to add it manually
FileSystem::replaceFileStr(SOURCE_PATH . '/php-src/ext/imap/config.m4', 'TST_LIBS="$DLIBS $IMAP_SHARED_LIBADD"', 'TST_LIBS="$DLIBS $IMAP_SHARED_LIBADD -lz"');
return true;
}
return false;
}
public function validate(): void
2023-10-31 13:09:01 +01:00
{
if ($this->builder->getOption('enable-zts')) {
throw new WrongUsageException('ext-imap is not thread safe, do not build it with ZTS builds');
}
}
public function getUnixConfigureArg(bool $shared = false): string
{
2023-10-31 13:09:01 +01:00
$arg = '--with-imap=' . BUILD_ROOT_PATH;
if ($this->builder->getLib('openssl') !== null) {
$arg .= ' --with-imap-ssl=' . BUILD_ROOT_PATH;
}
return $arg;
}
2025-07-10 12:59:27 +08:00
public function patchBeforeMake(): bool
{
$patched = parent::patchBeforeMake();
2025-07-10 12:59:27 +08:00
if (PHP_OS_FAMILY !== 'Linux' || SystemUtil::isMuslDist()) {
return $patched;
2025-07-10 12:59:27 +08:00
}
$extra_libs = trim((getenv('SPC_EXTRA_LIBS') ?: '') . ' -lcrypt');
2025-07-10 12:59:27 +08:00
f_putenv('SPC_EXTRA_LIBS=' . $extra_libs);
return true;
}
2023-10-31 13:09:01 +01:00
}