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;
|
|
|
|
|
|
|
|
|
|
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-03-30 22:07:56 +07:00
|
|
|
// TODO: glibc rh 10 toolset's libgomp.a was built without -fPIC -fPIE so we can't use openmp without depending on libgomp.so
|
|
|
|
|
$openmp = getenv('SPC_LIBC') === 'musl' ? '--enable-openmp' : '--disable-openmp';
|
|
|
|
|
$extra = "--without-jxl --without-x {$openmp} ";
|
2023-10-17 19:37:13 +02:00
|
|
|
$required_libs = '';
|
|
|
|
|
$optional_libs = [
|
|
|
|
|
'libzip' => 'zip',
|
|
|
|
|
'libjpeg' => 'jpeg',
|
|
|
|
|
'libpng' => 'png',
|
|
|
|
|
'libwebp' => 'webp',
|
|
|
|
|
'libxml2' => 'xml',
|
|
|
|
|
'zlib' => 'zlib',
|
2023-10-23 00:37:28 +08:00
|
|
|
'xz' => 'lzma',
|
2023-10-17 19:37:13 +02:00
|
|
|
'zstd' => 'zstd',
|
|
|
|
|
'freetype' => 'freetype',
|
2025-03-30 14:02:44 +08:00
|
|
|
'bzip2' => 'bzlib',
|
2023-10-17 19:37:13 +02:00
|
|
|
];
|
|
|
|
|
foreach ($optional_libs as $lib => $option) {
|
|
|
|
|
$extra .= $this->builder->getLib($lib) ? "--with-{$option} " : "--without-{$option} ";
|
2023-10-17 20:16:41 +02:00
|
|
|
if ($this->builder->getLib($lib) instanceof LinuxLibraryBase) {
|
2023-10-17 19:37:13 +02:00
|
|
|
$required_libs .= ' ' . $this->builder->getLib($lib)->getStaticLibFiles();
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-05-17 22:08:13 +08:00
|
|
|
|
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
|
|
|
|
|
|
|
|
// libxml iconv patch
|
2024-04-07 15:52:24 +08:00
|
|
|
$required_libs .= $this instanceof MacOSLibraryBase ? ('-liconv') : '';
|
2023-05-17 22:08:13 +08:00
|
|
|
shell()->cd($this->source_dir)
|
2024-04-07 15:52:24 +08:00
|
|
|
->setEnv([
|
|
|
|
|
'CFLAGS' => $this->getLibExtraCFlags(),
|
|
|
|
|
'LDFLAGS' => $this->getLibExtraLdFlags() ?: $ldflags,
|
|
|
|
|
'LIBS' => $this->getLibExtraLibs() ?: $required_libs,
|
|
|
|
|
'PKG_CONFIG' => '$PKG_CONFIG --static',
|
|
|
|
|
])
|
|
|
|
|
->execWithEnv(
|
2023-10-17 19:37:13 +02:00
|
|
|
'./configure ' .
|
2023-05-17 22:08:13 +08:00
|
|
|
'--enable-static --disable-shared ' .
|
|
|
|
|
$extra .
|
|
|
|
|
'--prefix='
|
|
|
|
|
)
|
|
|
|
|
->exec('make clean')
|
|
|
|
|
->exec("make -j{$this->builder->concurrency}")
|
|
|
|
|
->exec('make install DESTDIR=' . BUILD_ROOT_PATH);
|
|
|
|
|
$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'
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|