98 lines
3.9 KiB
PHP
Raw Normal View History

<?php
declare(strict_types=1);
namespace SPC\builder\unix\library;
use SPC\exception\FileSystemException;
use SPC\exception\RuntimeException;
use SPC\store\FileSystem;
trait curl
{
/**
* @throws RuntimeException
* @throws FileSystemException
*/
protected function build(): void
{
$extra = '';
// lib:openssl
2025-06-04 13:44:18 +07:00
if ($this->builder->getLib('openssl')) {
$extra .=
'-DCURL_USE_OPENSSL=ON ' .
'-DCURL_CA_BUNDLE=OFF ' .
'-DCURL_CA_PATH=OFF ' .
'-DCURL_CA_FALLBACK=ON ';
} else {
$extra .= '-DCURL_USE_OPENSSL=OFF -DCURL_ENABLE_SSL=OFF ';
}
// lib:brotli
$extra .= $this->builder->getLib('brotli') ? '-DCURL_BROTLI=ON ' : '-DCURL_BROTLI=OFF ';
// lib:libssh2
$libssh2 = $this->builder->getLib('libssh2');
if ($this->builder->getLib('libssh2')) {
2023-04-29 19:02:41 +08:00
/* @phpstan-ignore-next-line */
$extra .= '-DLIBSSH2_LIBRARY="' . $libssh2->getStaticLibFiles(style: 'cmake') . '" ' .
'-DLIBSSH2_INCLUDE_DIR="' . BUILD_INCLUDE_PATH . '" ';
} else {
$extra .= '-DCURL_USE_LIBSSH2=OFF ';
}
// lib:nghttp2
if ($nghttp2 = $this->builder->getLib('nghttp2')) {
$extra .= '-DUSE_NGHTTP2=ON ' .
2023-04-29 19:02:41 +08:00
/* @phpstan-ignore-next-line */
'-DNGHTTP2_LIBRARY="' . $nghttp2->getStaticLibFiles(style: 'cmake') . '" ' .
'-DNGHTTP2_INCLUDE_DIR="' . BUILD_INCLUDE_PATH . '" ';
} else {
$extra .= '-DUSE_NGHTTP2=OFF ';
}
2025-06-05 09:44:03 +07:00
// lib:nghttp3
if ($nghttp3 = $this->builder->getLib('nghttp3')) {
$extra .= '-DUSE_NGHTTP3=ON ' .
/* @phpstan-ignore-next-line */
'-DNGHTTP3_LIBRARY="' . $nghttp3->getStaticLibFiles(style: 'cmake') . '" ' .
'-DNGHTTP3_INCLUDE_DIR="' . BUILD_INCLUDE_PATH . '" ';
} else {
$extra .= '-DUSE_NGHTTP3=OFF ';
}
// lib:ngtcp2
if ($ngtcp2 = $this->builder->getLib('ngtcp2')) {
2025-06-05 09:50:14 +07:00
$extra .= '-DUSE_NGTCP2=ON ' .
/* @phpstan-ignore-next-line */
2025-06-05 09:44:03 +07:00
'-DNGTCP2_LIBRARY="' . $ngtcp2->getStaticLibFiles(style: 'cmake') . '" ' .
'-DNGTCP2_INCLUDE_DIR="' . BUILD_INCLUDE_PATH . '" ';
} else {
$extra .= '-DUSE_NGTCP2=OFF ';
}
2023-09-18 13:43:58 +02:00
// lib:ldap
$extra .= $this->builder->getLib('ldap') ? '-DCURL_DISABLE_LDAP=OFF ' : '-DCURL_DISABLE_LDAP=ON ';
// lib:zstd
$extra .= $this->builder->getLib('zstd') ? '-DCURL_ZSTD=ON ' : '-DCURL_ZSTD=OFF ';
// lib:idn2
$extra .= $this->builder->getLib('idn2') ? '-DUSE_LIBIDN2=ON ' : '-DUSE_LIBIDN2=OFF ';
// lib:psl
$extra .= $this->builder->getLib('psl') ? '-DCURL_USE_LIBPSL=ON ' : '-DCURL_USE_LIBPSL=OFF ';
2024-08-08 01:12:07 +08:00
// lib:libcares
$extra .= $this->builder->getLib('libcares') ? '-DENABLE_ARES=ON ' : '';
FileSystem::resetDir($this->source_dir . '/build');
2025-01-28 19:37:50 +08:00
// compile
shell()->cd($this->source_dir . '/build')
2025-01-28 19:37:50 +08:00
->setEnv([
'CFLAGS' => $this->getLibExtraCFlags(),
2025-01-28 19:37:50 +08:00
'LDFLAGS' => $this->getLibExtraLdFlags(),
2025-03-11 07:15:07 +01:00
'LIBS' => $this->getLibExtraLibs(),
2025-01-28 19:37:50 +08:00
])
2023-08-27 03:23:11 +08:00
->exec('sed -i.save s@\${CMAKE_C_IMPLICIT_LINK_LIBRARIES}@@ ../CMakeLists.txt')
2024-04-07 15:52:24 +08:00
->execWithEnv("cmake {$this->builder->makeCmakeArgs()} -DBUILD_SHARED_LIBS=OFF -DBUILD_CURL_EXE=OFF -DBUILD_LIBCURL_DOCS=OFF {$extra} ..")
->execWithEnv("make -j{$this->builder->concurrency}")
->execWithEnv('make install');
// patch pkgconf
$this->patchPkgconfPrefix(['libcurl.pc']);
shell()->cd(BUILD_LIB_PATH . '/cmake/CURL/')
->exec("sed -ie 's|\"/lib/libcurl.a\"|\"" . BUILD_LIB_PATH . "/libcurl.a\"|g' CURLTargets-release.cmake");
}
}