2025-06-05 09:44:03 +07:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
|
|
namespace SPC\builder\unix\library;
|
|
|
|
|
|
|
|
|
|
use SPC\exception\FileSystemException;
|
|
|
|
|
use SPC\exception\RuntimeException;
|
|
|
|
|
use SPC\exception\WrongUsageException;
|
|
|
|
|
|
|
|
|
|
trait ngtcp2
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* @throws FileSystemException
|
|
|
|
|
* @throws RuntimeException
|
|
|
|
|
* @throws WrongUsageException
|
|
|
|
|
*/
|
|
|
|
|
protected function build(): void
|
|
|
|
|
{
|
2025-06-06 16:20:34 +07:00
|
|
|
$args = $this->builder->makeAutoconfArgs(static::NAME, [
|
2025-06-05 09:44:03 +07:00
|
|
|
'openssl' => null,
|
|
|
|
|
'libev' => null,
|
|
|
|
|
'jemalloc' => null,
|
2025-06-06 16:20:34 +07:00
|
|
|
'libnghttp3' => null,
|
|
|
|
|
]);
|
2025-06-06 16:56:08 +07:00
|
|
|
if ($brotli = $this->builder->getLib('brotli')) {
|
2025-06-06 16:59:36 +07:00
|
|
|
/* @phpstan-ignore-next-line */
|
2025-06-06 16:56:08 +07:00
|
|
|
$args .= ' --with-libbrotlidec=yes LIBBROTLIDEC_CFLAGS="-I' . BUILD_ROOT_PATH . '/include" LIBBROTLIDEC_LIBS="' . $brotli->getStaticLibFiles() . '"';
|
2025-06-06 16:59:36 +07:00
|
|
|
/* @phpstan-ignore-next-line */
|
2025-06-06 16:56:08 +07:00
|
|
|
$args .= ' --with-libbrotlienc=yes LIBBROTLIENC_CFLAGS="-I' . BUILD_ROOT_PATH . '/include" LIBBROTLIENC_LIBS="' . $brotli->getStaticLibFiles() . '"';
|
2025-06-06 14:49:09 +07:00
|
|
|
}
|
2025-06-05 09:44:03 +07:00
|
|
|
|
2025-06-09 11:12:34 +08:00
|
|
|
shell()->cd($this->source_dir)->initializeEnv($this)
|
2025-06-09 10:24:06 +08:00
|
|
|
->exec(
|
2025-06-05 09:44:03 +07:00
|
|
|
'./configure ' .
|
|
|
|
|
'--enable-static ' .
|
|
|
|
|
'--disable-shared ' .
|
|
|
|
|
'--with-pic ' .
|
|
|
|
|
'--enable-lib-only ' .
|
|
|
|
|
$args . ' ' .
|
|
|
|
|
'--prefix='
|
|
|
|
|
)
|
2025-06-09 10:24:06 +08:00
|
|
|
->exec('make clean')
|
|
|
|
|
->exec("make -j{$this->builder->concurrency}")
|
|
|
|
|
->exec('make install DESTDIR=' . BUILD_ROOT_PATH);
|
2025-06-06 14:58:18 +07:00
|
|
|
$this->patchPkgconfPrefix(['libngtcp2.pc', 'libngtcp2_crypto_ossl.pc']);
|
2025-06-07 20:29:19 +07:00
|
|
|
$this->patchLaDependencyPrefix(['libngtcp2.la', 'libngtcp2_crypto_ossl.la']);
|
2025-06-07 10:23:10 +07:00
|
|
|
|
|
|
|
|
// on macOS, the static library may contain other static libraries?
|
|
|
|
|
// ld: archive member 'libssl.a' not a mach-o file in libngtcp2_crypto_ossl.a
|
|
|
|
|
shell()->cd(BUILD_LIB_PATH)
|
2025-06-07 10:33:41 +07:00
|
|
|
->exec("ar -t libngtcp2_crypto_ossl.a | grep '\\.a$' | xargs -n1 ar d libngtcp2_crypto_ossl.a");
|
2025-06-05 09:44:03 +07:00
|
|
|
}
|
|
|
|
|
}
|