Files
static-php-cli/src/Package/Extension/imagick.php

58 lines
2.3 KiB
PHP
Raw Normal View History

2026-03-10 22:19:01 +08:00
<?php
declare(strict_types=1);
namespace Package\Extension;
2026-06-14 11:51:07 +07:00
use Package\Target\php;
use StaticPHP\Attribute\Package\BeforeStage;
2026-03-10 22:19:01 +08:00
use StaticPHP\Attribute\Package\CustomPhpConfigureArg;
use StaticPHP\Attribute\Package\Extension;
2026-06-14 11:51:07 +07:00
use StaticPHP\Attribute\PatchDescription;
2026-03-10 22:19:01 +08:00
use StaticPHP\Package\PackageBuilder;
2026-06-14 11:51:07 +07:00
use StaticPHP\Package\PhpExtensionPackage;
use StaticPHP\Util\FileSystem;
2026-03-10 22:19:01 +08:00
#[Extension('imagick')]
2026-06-14 11:51:07 +07:00
class imagick extends PhpExtensionPackage
2026-03-10 22:19:01 +08:00
{
#[CustomPhpConfigureArg('Darwin')]
#[CustomPhpConfigureArg('Linux')]
public function getUnixConfigureArg(bool $shared, PackageBuilder $builder): string
{
$disable_omp = ' ac_cv_func_omp_pause_resource_all=no';
return '--with-imagick=' . ($shared ? 'shared,' : '') . $builder->getBuildRootPath() . $disable_omp;
}
2026-06-14 11:51:07 +07:00
#[CustomPhpConfigureArg('Windows')]
public function getWindowsConfigureArg(bool $shared): string
{
// config.w32 uses PHP_IMAGICK as an extra search path for CORE_RL_*.lib; the static
// ImageMagick libs are installed flat in buildroot/lib (headers in buildroot/include/imagemagick).
return '--with-imagick=' . BUILD_LIB_PATH;
}
#[BeforeStage('php', [php::class, 'buildconfForWindows'], 'ext-imagick')]
#[PatchDescription('Add the Win32 system libraries the static ImageMagick stack needs')]
public function patchConfigW32ForWindows(): void
{
$config = $this->getSourceDir() . '/config.w32';
// Idempotency guard (the source dir may be patched in place and reused across builds).
if (str_contains(FileSystem::readFile($config), 'LIBS_IMAGICK')) {
return;
}
2026-07-08 17:02:32 +09:00
// The static ImageMagick stack needs several Win32 system libraries (GDI/GDI+, WIC, urlmon, ...)
2026-06-14 11:51:07 +07:00
// that aren't already pulled in by the other extensions. (imagick itself builds as plain C:
// ImageMagick is built with a 32-bit channel mask, see imagemagick.php buildWin, so the
// MagickCore headers don't require a C++ translation unit.)
FileSystem::replaceFileStr(
$config,
"AC_DEFINE('HAVE_IMAGICK', 1);",
2026-07-08 17:02:32 +09:00
'ADD_FLAG("LIBS_IMAGICK", "gdi32.lib gdiplus.lib urlmon.lib msimg32.lib oleaut32.lib windowscodecs.lib iphlpapi.lib");' . "\n\t\t" .
2026-06-14 11:51:07 +07:00
"AC_DEFINE('HAVE_IMAGICK', 1);"
);
}
2026-03-10 22:19:01 +08:00
}