2023-04-29 18:59:47 +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-04-29 18:59:47 +08:00
|
|
|
use SPC\store\FileSystem;
|
|
|
|
|
|
|
|
|
|
trait brotli
|
|
|
|
|
{
|
2023-08-20 19:51:45 +08:00
|
|
|
/**
|
|
|
|
|
* @throws FileSystemException
|
|
|
|
|
* @throws RuntimeException
|
|
|
|
|
*/
|
2023-04-29 18:59:47 +08:00
|
|
|
protected function build(): void
|
|
|
|
|
{
|
|
|
|
|
FileSystem::resetDir($this->source_dir . '/build-dir');
|
|
|
|
|
shell()->cd($this->source_dir . '/build-dir')
|
2024-04-07 15:52:24 +08:00
|
|
|
->setEnv(['CFLAGS' => $this->getLibExtraCFlags(), 'LDFLAGS' => $this->getLibExtraLdFlags(), 'LIBS' => $this->getLibExtraLibs()])
|
|
|
|
|
->execWithEnv(
|
2023-10-23 00:37:28 +08:00
|
|
|
'cmake ' .
|
2025-03-10 00:39:20 +08:00
|
|
|
'-DCMAKE_BUILD_TYPE=Release ' .
|
|
|
|
|
"-DCMAKE_TOOLCHAIN_FILE={$this->builder->cmake_toolchain_file} " .
|
|
|
|
|
'-DCMAKE_INSTALL_PREFIX=' . BUILD_ROOT_PATH . ' ' .
|
|
|
|
|
'-DCMAKE_INSTALL_LIBDIR=lib ' .
|
|
|
|
|
'-DSHARE_INSTALL_PREFIX=' . BUILD_ROOT_PATH . ' ' .
|
2023-04-29 18:59:47 +08:00
|
|
|
'-DBUILD_SHARED_LIBS=OFF ' .
|
|
|
|
|
'..'
|
|
|
|
|
)
|
2024-04-07 15:52:24 +08:00
|
|
|
->execWithEnv("cmake --build . -j {$this->builder->concurrency}")
|
2025-03-10 00:39:20 +08:00
|
|
|
->execWithEnv('make install');
|
2023-04-29 18:59:47 +08:00
|
|
|
$this->patchPkgconfPrefix(['libbrotlicommon.pc', 'libbrotlidec.pc', 'libbrotlienc.pc']);
|
2024-01-07 10:54:49 +08:00
|
|
|
shell()->cd(BUILD_ROOT_PATH . '/lib')->exec('ln -sf libbrotlicommon.a libbrotli.a');
|
2023-04-29 18:59:47 +08:00
|
|
|
foreach (FileSystem::scanDirFiles(BUILD_ROOT_PATH . '/lib/', false, true) as $filename) {
|
|
|
|
|
if (str_starts_with($filename, 'libbrotli') && (str_contains($filename, '.so') || str_ends_with($filename, '.dylib'))) {
|
|
|
|
|
unlink(BUILD_ROOT_PATH . '/lib/' . $filename);
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-07-08 13:27:03 +08:00
|
|
|
|
|
|
|
|
if (file_exists(BUILD_BIN_PATH . '/brotli')) {
|
|
|
|
|
unlink(BUILD_BIN_PATH . '/brotli');
|
|
|
|
|
}
|
2023-04-29 18:59:47 +08:00
|
|
|
}
|
|
|
|
|
}
|