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 curl
|
|
|
|
|
|
{
|
2023-08-20 19:51:45 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* @throws RuntimeException
|
|
|
|
|
|
* @throws FileSystemException
|
|
|
|
|
|
*/
|
|
|
|
|
|
protected function build(): void
|
2023-04-29 18:59:47 +08:00
|
|
|
|
{
|
|
|
|
|
|
$extra = '';
|
|
|
|
|
|
// lib:openssl
|
|
|
|
|
|
$extra .= $this->builder->getLib('openssl') ? '-DCURL_USE_OPENSSL=ON ' : '-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 */
|
2023-04-29 18:59:47 +08:00
|
|
|
|
$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 */
|
2023-04-29 18:59:47 +08:00
|
|
|
|
'-DNGHTTP2_LIBRARY="' . $nghttp2->getStaticLibFiles(style: 'cmake') . '" ' .
|
|
|
|
|
|
'-DNGHTTP2_INCLUDE_DIR="' . BUILD_INCLUDE_PATH . '" ';
|
|
|
|
|
|
} else {
|
|
|
|
|
|
$extra .= '-DUSE_NGHTTP2=OFF ';
|
|
|
|
|
|
}
|
2023-09-18 13:43:58 +02:00
|
|
|
|
// lib:ldap
|
|
|
|
|
|
$extra .= $this->builder->getLib('ldap') ? '-DCURL_DISABLE_LDAP=OFF ' : '-DCURL_DISABLE_LDAP=ON ';
|
2023-04-29 18:59:47 +08:00
|
|
|
|
// 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 ';
|
|
|
|
|
|
|
|
|
|
|
|
FileSystem::resetDir($this->source_dir . '/build');
|
|
|
|
|
|
// compile!
|
|
|
|
|
|
shell()->cd($this->source_dir . '/build')
|
2024-04-07 15:52:24 +08:00
|
|
|
|
->setEnv(['CFLAGS' => $this->getLibExtraCFlags(), 'LDFLAGS' => $this->getLibExtraLdFlags(), 'LIBS' => $this->getLibExtraLibs()])
|
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 DESTDIR=' . BUILD_ROOT_PATH);
|
2023-04-29 18:59:47 +08:00
|
|
|
|
// 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");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|