Skip to content
Open
12 changes: 12 additions & 0 deletions config/ext.json
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,18 @@
],
"lib-depends-windows": []
},
"gmagick": {
"support": {
"Windows": "wip",
"BSD": "wip"
},
"type": "external",
"source": "ext-gmagick",
"arg-type": "custom",
"lib-depends": [
"graphicsmagick"
]
},
"gmp": {
"support": {
"Windows": "wip",
Expand Down
21 changes: 21 additions & 0 deletions config/lib.json
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,27 @@
"Security"
]
},
"graphicsmagick": {
"source": "graphicsmagick",
"pkg-configs": [
"GraphicsMagick",
"GraphicsMagickWand"
],
"lib-depends": [
"zlib",
"libpng",
"libjpeg",
"bzip2",
"libxml2"
],
"lib-suggests": [
"libwebp",
"libtiff",
"freetype",
"zstd",
"xz"
]
},
"grpc": {
"source": "grpc",
"pkg-configs": [
Expand Down
18 changes: 18 additions & 0 deletions config/source.json
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,16 @@
"path": "LICENSE"
}
},
"ext-gmagick": {
"type": "url",
"url": "https://pecl.php.net/get/gmagick",
"path": "php-src/ext/gmagick",
"filename": "gmagick.tgz",
"license": {
"type": "file",
"path": "LICENSE"
}
},
"ext-gmssl": {
"type": "ghtar",
"repo": "gmssl/GmSSL-PHP",
Expand Down Expand Up @@ -401,6 +411,14 @@
"path": "LICENSE"
}
},
"graphicsmagick": {
"type": "url",
"url": "https://downloads.sourceforge.net/project/graphicsmagick/graphicsmagick/1.3.46/GraphicsMagick-1.3.46.tar.xz",
"license": {
"type": "file",
"path": "Copyright.txt"
}
},
"grpc": {
"type": "git",
"rev": "v1.75.x",
Expand Down
34 changes: 34 additions & 0 deletions src/SPC/builder/extension/gmagick.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

declare(strict_types=1);

namespace SPC\builder\extension;

use SPC\builder\Extension;
use SPC\store\FileSystem;
use SPC\util\CustomExt;

#[CustomExt('gmagick')]
class gmagick extends Extension
{
public function patchBeforeBuildconf(): bool
{
// PHP 8.5 removed zend_exception_get_default(), use zend_ce_exception instead
FileSystem::replaceFileStr($this->source_dir . '/gmagick.c', 'zend_exception_get_default()', 'zend_ce_exception');

// Remove the entire OpenMP check block from config.m4 to avoid linking
// against libgomp in static builds. gmagick's config.m4 uses PHP_CHECK_FUNC
// which does not honour ac_cv cache variables, so we must patch the source.
FileSystem::replaceFileRegex(
SOURCE_PATH . '/php-src/ext/gmagick/config.m4',
'/AC_MSG_CHECKING\(omp_pause_resource_all usability\).*?AC_MSG_RESULT\(no\)\n\t\t\]\)/s',
'dnl OMP check removed for static build'
);
return true;
}

public function getUnixConfigureArg(bool $shared = false): string
{
return '--with-gmagick=' . ($shared ? 'shared,' : '') . BUILD_ROOT_PATH;
}
}
12 changes: 12 additions & 0 deletions src/SPC/builder/linux/library/graphicsmagick.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

declare(strict_types=1);

namespace SPC\builder\linux\library;

class graphicsmagick extends LinuxLibraryBase
{
use \SPC\builder\unix\library\graphicsmagick;

public const NAME = 'graphicsmagick';
}
12 changes: 12 additions & 0 deletions src/SPC/builder/macos/library/graphicsmagick.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

declare(strict_types=1);

namespace SPC\builder\macos\library;

class graphicsmagick extends MacOSLibraryBase
{
use \SPC\builder\unix\library\graphicsmagick;

public const NAME = 'graphicsmagick';
}
54 changes: 54 additions & 0 deletions src/SPC/builder/unix/library/graphicsmagick.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php

declare(strict_types=1);

namespace SPC\builder\unix\library;

use SPC\util\executor\UnixAutoconfExecutor;
use SPC\util\SPCTarget;

trait graphicsmagick
{
protected function build(): void
{
$ac = UnixAutoconfExecutor::create($this)
->optionalLib('zlib', ...ac_with_args('zlib'))
->optionalLib('libpng', ...ac_with_args('png'))
->optionalLib('libjpeg', ...ac_with_args('jpeg'))
->optionalLib('libwebp', ...ac_with_args('webp'))
->optionalLib('libtiff', ...ac_with_args('tiff'))
->optionalLib('freetype', ...ac_with_args('ttf'))
->optionalLib('bzip2', ...ac_with_args('bzlib'))
->addConfigureArgs(
'--disable-openmp',
'--without-x',
'--without-perl',
// HEIF/JXL: GraphicsMagick auto-detects libheif/libjxl from the
// buildroot but the API versions are often incompatible (e.g.
// GM 1.3.46 expects libheif symbols added in 2.4+). Exclude them
// to avoid compile errors. Neither format is needed for typical
// WordPress/web image processing (JPEG/PNG/WebP/GIF suffice).
'--without-heif',
'--without-jxl',
'--enable-shared=no',
'--enable-static=yes',
);

// special: linux-static target needs `-static`
$ldflags = SPCTarget::isStatic() ? '-static -ldl' : '-ldl';

// special: macOS needs -liconv
$libs = SPCTarget::getTargetOS() === 'Darwin' ? '-liconv' : '';

$ac->appendEnv([
'LDFLAGS' => $ldflags,
'LIBS' => $libs,
'PKG_CONFIG' => '$PKG_CONFIG --static',
]);

$ac->configure()->make();

$this->patchPkgconfPrefix(['GraphicsMagick.pc', 'GraphicsMagick++.pc', 'GraphicsMagickWand.pc']);
$this->patchLaDependencyPrefix();
}
}
7 changes: 7 additions & 0 deletions src/globals/ext-tests/gmagick.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

declare(strict_types=1);

assert(class_exists('Gmagick'));
assert(in_array('JPEG', (new Gmagick())->queryformats()));
assert(in_array('PNG', (new Gmagick())->queryformats()));
9 changes: 5 additions & 4 deletions src/globals/test-extensions.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,16 @@
$upx = false;

// whether to test frankenphp build, only available for macOS and linux
$frankenphp = false;
$frankenphp = true;

// prefer downloading pre-built packages to speed up the build process
$prefer_pre_built = false;

// If you want to test your added extensions and libs, add below (comma separated, example `bcmath,openssl`).
$extensions = match (PHP_OS_FAMILY) {
'Linux', 'Darwin' => 'decimal',
'Windows' => 'decimal',
'Linux' => 'gmagick',
'Darwin' => 'gmagick',
'Windows' => 'gmagick',
};

// If you want to test shared extensions, add them below (comma separated, example `bcmath,openssl`).
Expand All @@ -66,7 +67,7 @@

// If you want to test extra libs for extensions, add them below (comma separated, example `libwebp,libavif`). Unnecessary, when $with_suggested_libs is true.
$with_libs = match (PHP_OS_FAMILY) {
'Linux', 'Darwin' => 'krb5',
'Linux', 'Darwin' => '',
'Windows' => '',
};

Expand Down