2023-05-17 22:08:13 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
|
|
namespace SPC\builder\unix\library;
|
|
|
|
|
|
2023-10-17 20:16:41 +02:00
|
|
|
use SPC\builder\linux\library\LinuxLibraryBase;
|
2023-11-29 00:51:05 +08:00
|
|
|
use SPC\builder\macos\library\MacOSLibraryBase;
|
2023-08-20 19:51:45 +08:00
|
|
|
use SPC\exception\FileSystemException;
|
|
|
|
|
use SPC\exception\RuntimeException;
|
2023-05-17 22:08:13 +08:00
|
|
|
use SPC\store\FileSystem;
|
2025-06-09 19:32:31 +08:00
|
|
|
use SPC\util\executor\UnixAutoconfExecutor;
|
2023-05-17 22:08:13 +08:00
|
|
|
|
|
|
|
|
trait imagemagick
|
|
|
|
|
{
|
2023-08-20 19:51:45 +08:00
|
|
|
/**
|
|
|
|
|
* @throws RuntimeException
|
|
|
|
|
* @throws FileSystemException
|
|
|
|
|
*/
|
2023-05-17 22:08:13 +08:00
|
|
|
protected function build(): void
|
|
|
|
|
{
|
2025-06-09 19:32:31 +08:00
|
|
|
$ac = UnixAutoconfExecutor::create($this)
|
|
|
|
|
->optionalLib('libzip', ...ac_with_args('zip'))
|
|
|
|
|
->optionalLib('libjpeg', ...ac_with_args('jpeg'))
|
|
|
|
|
->optionalLib('libpng', ...ac_with_args('png'))
|
|
|
|
|
->optionalLib('libwebp', ...ac_with_args('webp'))
|
|
|
|
|
->optionalLib('libxml2', ...ac_with_args('xml'))
|
|
|
|
|
->optionalLib('libheif', ...ac_with_args('heic'))
|
|
|
|
|
->optionalLib('zlib', ...ac_with_args('zlib'))
|
|
|
|
|
->optionalLib('xz', ...ac_with_args('lzma'))
|
|
|
|
|
->optionalLib('zstd', ...ac_with_args('zstd'))
|
|
|
|
|
->optionalLib('freetype', ...ac_with_args('freetype'))
|
|
|
|
|
->optionalLib('bzip2', ...ac_with_args('bzlib'))
|
|
|
|
|
->addConfigureArgs(
|
|
|
|
|
// TODO: glibc rh 10 toolset's libgomp.a was built without -fPIC so we can't use openmp without depending on libgomp.so
|
2025-06-11 15:01:16 +07:00
|
|
|
getenv('SPC_LIBC') === 'musl' ? '--enable-openmp' : '--disable-openmp',
|
2025-06-09 19:32:31 +08:00
|
|
|
'--without-jxl',
|
|
|
|
|
'--without-x',
|
|
|
|
|
);
|
2023-05-17 22:08:13 +08:00
|
|
|
|
2025-06-09 19:32:31 +08:00
|
|
|
// special: linux musl needs `-static`
|
2025-03-14 18:22:50 +08:00
|
|
|
$ldflags = ($this instanceof LinuxLibraryBase) && getenv('SPC_LIBC') !== 'glibc' ? ('-static -ldl') : '-ldl';
|
2023-11-29 00:51:05 +08:00
|
|
|
|
2025-06-09 19:32:31 +08:00
|
|
|
// special: macOS needs -iconv
|
|
|
|
|
$libs = $this instanceof MacOSLibraryBase ? '-liconv' : '';
|
|
|
|
|
|
|
|
|
|
$ac->appendEnv([
|
|
|
|
|
'LDFLAGS' => $ldflags,
|
|
|
|
|
'LIBS' => $libs,
|
|
|
|
|
'PKG_CONFIG' => '$PKG_CONFIG --static',
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$ac->configure()->make();
|
|
|
|
|
|
2023-05-17 22:08:13 +08:00
|
|
|
$filelist = [
|
|
|
|
|
'ImageMagick.pc',
|
|
|
|
|
'ImageMagick-7.Q16HDRI.pc',
|
|
|
|
|
'Magick++.pc',
|
|
|
|
|
'Magick++-7.Q16HDRI.pc',
|
|
|
|
|
'MagickCore.pc',
|
|
|
|
|
'MagickCore-7.Q16HDRI.pc',
|
|
|
|
|
'MagickWand.pc',
|
|
|
|
|
'MagickWand-7.Q16HDRI.pc',
|
|
|
|
|
];
|
|
|
|
|
$this->patchPkgconfPrefix($filelist);
|
|
|
|
|
foreach ($filelist as $file) {
|
2023-08-20 19:51:45 +08:00
|
|
|
FileSystem::replaceFileRegex(
|
2023-05-17 22:08:13 +08:00
|
|
|
BUILD_LIB_PATH . '/pkgconfig/' . $file,
|
|
|
|
|
'#includearchdir=/include/ImageMagick-7#m',
|
|
|
|
|
'includearchdir=${prefix}/include/ImageMagick-7'
|
|
|
|
|
);
|
|
|
|
|
}
|
2025-06-10 19:46:55 +07:00
|
|
|
$this->patchLaDependencyPrefix();
|
2023-05-17 22:08:13 +08:00
|
|
|
}
|
|
|
|
|
}
|