76 lines
2.5 KiB
PHP
Raw Normal View History

2023-05-17 22:08:13 +08:00
<?php
declare(strict_types=1);
namespace SPC\builder\unix\library;
use SPC\store\FileSystem;
2025-06-09 19:32:31 +08:00
use SPC\util\executor\UnixAutoconfExecutor;
use SPC\util\SPCTarget;
2023-05-17 22:08:13 +08:00
trait imagemagick
{
protected function build(): void
{
$original_ldflags = $this->builder->arch_ld_flags;
if (str_contains($this->builder->arch_ld_flags, '-Wl,--as-needed')) {
$this->builder->arch_ld_flags = str_replace('-Wl,--as-needed', '', $original_ldflags);
}
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'))
2025-07-20 00:10:30 +07:00
->optionalLib('libjxl', ...ac_with_args('jxl'))
->optionalLib('jbig', ...ac_with_args('jbig'))
2025-06-09 19:32:31 +08:00
->addConfigureArgs(
2025-06-28 23:08:17 +08:00
'--disable-openmp',
2025-06-09 19:32:31 +08:00
'--without-x',
);
2023-05-17 22:08:13 +08:00
2025-06-29 16:00:17 +08:00
// special: linux-static target needs `-static`
$ldflags = SPCTarget::isStatic() ? '-static -ldl' : '-ldl';
2023-11-29 00:51:05 +08:00
2025-06-09 19:32:31 +08:00
// special: macOS needs -iconv
2025-06-29 16:00:17 +08:00
$libs = SPCTarget::getTargetOS() === 'Darwin' ? '-liconv' : '';
2025-06-09 19:32:31 +08:00
$ac->appendEnv([
'LDFLAGS' => $ldflags,
'LIBS' => $libs,
'PKG_CONFIG' => '$PKG_CONFIG --static',
]);
$ac->configure()->make();
$this->builder->arch_ld_flags = $original_ldflags;
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) {
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'
);
}
$this->patchLaDependencyPrefix();
2023-05-17 22:08:13 +08:00
}
}