2023-05-17 22:08:13 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
|
|
namespace SPC\builder\unix\library;
|
|
|
|
|
|
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
|
|
|
|
|
{
|
2023-10-17 19:37:13 +02:00
|
|
|
$extra = '--without-jxl --without-x --disable-openmp ';
|
|
|
|
|
$required_libs = '';
|
|
|
|
|
$optional_libs = [
|
|
|
|
|
'libzip' => 'zip',
|
|
|
|
|
'libjpeg' => 'jpeg',
|
|
|
|
|
'libpng' => 'png',
|
|
|
|
|
'libwebp' => 'webp',
|
|
|
|
|
'libxml2' => 'xml',
|
|
|
|
|
'zlib' => 'zlib',
|
|
|
|
|
'zstd' => 'zstd',
|
|
|
|
|
'freetype' => 'freetype',
|
|
|
|
|
];
|
|
|
|
|
foreach ($optional_libs as $lib => $option) {
|
|
|
|
|
$extra .= $this->builder->getLib($lib) ? "--with-{$option} " : "--without-{$option} ";
|
|
|
|
|
if ($this->builder->getLib($lib)) {
|
|
|
|
|
$required_libs .= ' ' . $this->builder->getLib($lib)->getStaticLibFiles();
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-05-17 22:08:13 +08:00
|
|
|
|
|
|
|
|
shell()->cd($this->source_dir)
|
|
|
|
|
->exec(
|
2023-10-17 19:37:13 +02:00
|
|
|
"{$this->builder->configure_env} " .
|
|
|
|
|
'LDFLAGS="-static" ' .
|
|
|
|
|
"LIBS='{$required_libs}' " .
|
|
|
|
|
'./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'
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|