2023-06-30 20:36:51 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
|
|
namespace SPC\builder\unix\library;
|
|
|
|
|
|
2023-10-31 00:59:22 +08:00
|
|
|
use SPC\builder\linux\library\LinuxLibraryBase;
|
2023-07-22 15:07:53 +08:00
|
|
|
use SPC\builder\macos\library\MacOSLibraryBase;
|
2023-06-30 20:36:51 +08:00
|
|
|
use SPC\exception\FileSystemException;
|
|
|
|
|
use SPC\exception\RuntimeException;
|
|
|
|
|
use SPC\store\FileSystem;
|
|
|
|
|
|
|
|
|
|
trait postgresql
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* @throws RuntimeException
|
|
|
|
|
* @throws FileSystemException
|
|
|
|
|
*/
|
2023-08-20 19:51:45 +08:00
|
|
|
protected function build(): void
|
2023-06-30 20:36:51 +08:00
|
|
|
{
|
|
|
|
|
$builddir = BUILD_ROOT_PATH;
|
2023-10-23 00:37:28 +08:00
|
|
|
$envs = '';
|
2023-10-16 21:03:26 +02:00
|
|
|
$packages = 'openssl zlib readline libxml-2.0 zlib';
|
2023-10-17 19:37:13 +02:00
|
|
|
$optional_packages = [
|
|
|
|
|
'zstd' => 'libzstd',
|
|
|
|
|
'ldap' => 'ldap',
|
|
|
|
|
'libxslt' => 'libxslt',
|
|
|
|
|
'icu' => 'icu-i18n',
|
|
|
|
|
];
|
2023-11-29 16:52:53 +08:00
|
|
|
|
2023-10-17 19:37:13 +02:00
|
|
|
foreach ($optional_packages as $lib => $pkg) {
|
2023-10-16 21:03:26 +02:00
|
|
|
if ($this->getBuilder()->getLib($lib)) {
|
2023-10-17 19:37:13 +02:00
|
|
|
$packages .= ' ' . $pkg;
|
2023-11-29 22:06:30 +08:00
|
|
|
$output = shell()->execWithResult("pkg-config --cflags --libs --static {$pkg}")[1][0];
|
|
|
|
|
if (!empty($output[1][0])) {
|
|
|
|
|
logger()->info($output[1][0]);
|
|
|
|
|
}
|
2023-10-16 21:03:26 +02:00
|
|
|
}
|
|
|
|
|
}
|
2023-06-30 20:36:51 +08:00
|
|
|
|
2023-10-23 00:37:28 +08:00
|
|
|
$output = shell()->execWithResult("pkg-config --cflags-only-I --static {$packages}");
|
2023-06-30 20:36:51 +08:00
|
|
|
if (!empty($output[1][0])) {
|
|
|
|
|
$cppflags = $output[1][0];
|
|
|
|
|
$envs .= " CPPFLAGS=\"{$cppflags}\"";
|
|
|
|
|
}
|
2023-10-23 00:37:28 +08:00
|
|
|
$output = shell()->execWithResult("pkg-config --libs-only-L --static {$packages}");
|
2023-06-30 20:36:51 +08:00
|
|
|
if (!empty($output[1][0])) {
|
|
|
|
|
$ldflags = $output[1][0];
|
2023-07-22 15:07:53 +08:00
|
|
|
$envs .= $this instanceof MacOSLibraryBase ? " LDFLAGS=\"{$ldflags}\" " : " LDFLAGS=\"{$ldflags} -static\" ";
|
2023-06-30 20:36:51 +08:00
|
|
|
}
|
2023-10-23 00:37:28 +08:00
|
|
|
$output = shell()->execWithResult("pkg-config --libs-only-l --static {$packages}");
|
2023-06-30 20:36:51 +08:00
|
|
|
if (!empty($output[1][0])) {
|
|
|
|
|
$libs = $output[1][0];
|
2023-10-31 00:59:22 +08:00
|
|
|
$libcpp = '';
|
|
|
|
|
if ($this->builder->getLib('icu')) {
|
|
|
|
|
$libcpp = $this instanceof LinuxLibraryBase ? ' -lstdc++' : ' -lc++';
|
|
|
|
|
}
|
|
|
|
|
$envs .= " LIBS=\"{$libs}{$libcpp}\" ";
|
2023-06-30 20:36:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FileSystem::resetDir($this->source_dir . '/build');
|
|
|
|
|
|
|
|
|
|
# 有静态链接配置 参考文件: src/interfaces/libpq/Makefile
|
2023-07-22 16:12:12 +08:00
|
|
|
shell()->cd($this->source_dir . '/build')
|
2023-11-29 15:06:17 +08:00
|
|
|
->exec('sed -i.backup "s/invokes exit\'; exit 1;/invokes exit\';/" ../src/interfaces/libpq/Makefile')
|
|
|
|
|
->exec('sed -i.backup "278 s/^/# /" ../src/Makefile.shlib')
|
|
|
|
|
->exec('sed -i.backup "402 s/^/# /" ../src/Makefile.shlib');
|
2023-06-30 20:36:51 +08:00
|
|
|
|
2023-07-22 16:12:12 +08:00
|
|
|
// configure
|
2023-06-30 20:36:51 +08:00
|
|
|
shell()->cd($this->source_dir . '/build')
|
|
|
|
|
->exec(
|
2023-07-22 16:29:46 +08:00
|
|
|
"{$envs} ../configure " .
|
2023-07-22 16:12:12 +08:00
|
|
|
"--prefix={$builddir} " .
|
|
|
|
|
'--disable-thread-safety ' .
|
|
|
|
|
'--enable-coverage=no ' .
|
|
|
|
|
'--with-ssl=openssl ' .
|
|
|
|
|
'--with-readline ' .
|
|
|
|
|
'--with-libxml ' .
|
2023-07-23 22:56:04 +08:00
|
|
|
($this->builder->getLib('icu') ? '--with-icu ' : '--without-icu ') .
|
2023-10-17 19:37:13 +02:00
|
|
|
($this->builder->getLib('ldap') ? '--with-ldap ' : '--without-ldap ') .
|
2023-10-16 21:03:26 +02:00
|
|
|
($this->builder->getLib('libxslt') ? '--with-libxslt ' : '--without-libxslt ') .
|
2023-10-17 19:37:13 +02:00
|
|
|
($this->builder->getLib('zstd') ? '--with-zstd ' : '--without-zstd ') .
|
2023-07-22 16:12:12 +08:00
|
|
|
'--without-lz4 ' .
|
|
|
|
|
'--without-perl ' .
|
|
|
|
|
'--without-python ' .
|
2023-10-31 13:09:01 +01:00
|
|
|
'--without-pam ' .
|
2023-07-22 16:12:12 +08:00
|
|
|
'--without-bonjour ' .
|
|
|
|
|
'--without-tcl '
|
2023-06-30 20:36:51 +08:00
|
|
|
);
|
|
|
|
|
|
2023-07-22 16:12:12 +08:00
|
|
|
// build
|
|
|
|
|
shell()->cd($this->source_dir . '/build')
|
|
|
|
|
->exec($envs . ' make -C src/bin/pg_config install')
|
|
|
|
|
->exec($envs . ' make -C src/include install')
|
|
|
|
|
->exec($envs . ' make -C src/common install')
|
|
|
|
|
->exec($envs . ' make -C src/port install')
|
|
|
|
|
->exec($envs . ' make -C src/interfaces/libpq install');
|
|
|
|
|
|
|
|
|
|
// remove dynamic libs
|
|
|
|
|
shell()->cd($this->source_dir . '/build')
|
|
|
|
|
->exec("rm -rf {$builddir}/lib/*.so.*")
|
|
|
|
|
->exec("rm -rf {$builddir}/lib/*.so")
|
|
|
|
|
->exec("rm -rf {$builddir}/lib/*.dylib");
|
2023-06-30 20:36:51 +08:00
|
|
|
}
|
|
|
|
|
}
|