74 lines
2.4 KiB
PHP
Raw Normal View History

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;
use SPC\builder\linux\LinuxBuilder;
use SPC\exception\FileSystemException;
use SPC\exception\RuntimeException;
2023-05-17 22:08:13 +08:00
use SPC\store\FileSystem;
trait imagemagick
{
/**
* @throws RuntimeException
* @throws FileSystemException
*/
2023-05-17 22:08:13 +08:00
protected function build(): void
{
// TODO: imagemagick build with bzip2 failed with bugs, we need to fix it in the future
$extra = '--without-jxl --without-x --disable-openmp --without-bzlib ';
$required_libs = '';
$optional_libs = [
'libzip' => 'zip',
'libjpeg' => 'jpeg',
'libpng' => 'png',
'libwebp' => 'webp',
'libxml2' => 'xml',
'zlib' => 'zlib',
'xz' => 'lzma',
'zstd' => 'zstd',
'freetype' => 'freetype',
];
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) {
$required_libs .= ' ' . $this->builder->getLib($lib)->getStaticLibFiles();
}
}
2023-05-17 22:08:13 +08:00
shell()->cd($this->source_dir)
->exec(
($this->builder instanceof LinuxBuilder ? ('LDFLAGS="-static -L' . BUILD_LIB_PATH . '" ') : '') .
"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) {
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'
);
}
}
}