59 lines
2.1 KiB
PHP
Raw Normal View History

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,
]);
if ($brotli = $this->builder->getLib('brotli')) {
2025-06-06 16:59:36 +07:00
/* @phpstan-ignore-next-line */
$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 */
$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
shell()->cd($this->source_dir)
->setEnv([
'CFLAGS' => $this->getLibExtraCFlags(),
'LDFLAGS' => $this->getLibExtraLdFlags(),
2025-06-05 09:50:14 +07:00
'LIBS' => $this->getLibExtraLibs(),
2025-06-05 09:44:03 +07:00
])
->execWithEnv(
'./configure ' .
'--enable-static ' .
'--disable-shared ' .
'--with-pic ' .
'--enable-lib-only ' .
$args . ' ' .
'--prefix='
)
->execWithEnv('make clean')
->execWithEnv("make -j{$this->builder->concurrency}")
->execWithEnv('make install DESTDIR=' . BUILD_ROOT_PATH);
2025-06-06 14:58:18 +07:00
$this->patchPkgconfPrefix(['libngtcp2.pc', 'libngtcp2_crypto_ossl.pc']);
// 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)
->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
}
}