mirror of
https://github.com/crazywhalecc/static-php-cli.git
synced 2026-07-05 07:45:39 +08:00
use pkgconfig to determine libs
This commit is contained in:
@@ -106,10 +106,33 @@ class SPCConfigUtil
|
||||
foreach (array_reverse($libraries) as $library) {
|
||||
$libs = Config::getLib($library, 'static-libs', []);
|
||||
foreach ($libs as $lib) {
|
||||
if ($withDependencies) {
|
||||
$noExt = str_replace('.a', '', $lib);
|
||||
$noExtNoLib = str_replace('lib', '', $noExt);
|
||||
$pkgconfFileNoExt = BUILD_LIB_PATH . "/pkgconfig/{$noExt}.pc";
|
||||
$pkgconfFileNoExtNoLib = BUILD_LIB_PATH . "/pkgconfig/{$noExtNoLib}.pc";
|
||||
$llibs = null;
|
||||
if (file_exists($pkgconfFileNoExt)) {
|
||||
$llibs = shell()->execWithResult("pkg-config --libs --static {$noExt}")[1][0];
|
||||
} elseif (file_exists($pkgconfFileNoExtNoLib)) {
|
||||
$llibs = shell()->execWithResult("pkg-config --libs --static {$noExtNoLib}")[1][0];
|
||||
}
|
||||
|
||||
if (!empty($llibs)) {
|
||||
$filtered = str_replace('-pthread', '', $llibs);
|
||||
$filtered = preg_replace('/-L\S+/', '', $filtered);
|
||||
$filtered = preg_replace('/(?:\S*\/)?lib([a-zA-Z0-9_+-]+)\.a\b/', '-l$1', $filtered);
|
||||
$filtered = preg_replace('/\s+/', ' ', $filtered);
|
||||
foreach (explode(' ', $filtered) as $item) {
|
||||
$short_name[] = $item;
|
||||
}
|
||||
} elseif ($withDependencies) {
|
||||
$noExt = str_replace('.a', '', $lib);
|
||||
$requiredLibs = [];
|
||||
$pkgconfFile = BUILD_LIB_PATH . "/pkgconfig/{$noExt}.pc";
|
||||
if (!file_exists($pkgconfFile)) {
|
||||
$noExtNoLib = str_replace('lib', '', $noExt);
|
||||
$pkgconfFile = BUILD_LIB_PATH . "/pkgconfig/{$noExtNoLib}.pc";
|
||||
}
|
||||
if (file_exists($pkgconfFile)) {
|
||||
$lines = file($pkgconfFile);
|
||||
foreach ($lines as $value) {
|
||||
|
||||
@@ -24,6 +24,8 @@ class UnixCMakeExecutor extends Executor
|
||||
|
||||
protected bool $reset = true;
|
||||
|
||||
protected array $extra_env = [];
|
||||
|
||||
public function build(string $build_pos = '..'): void
|
||||
{
|
||||
// set cmake dir
|
||||
@@ -34,7 +36,7 @@ class UnixCMakeExecutor extends Executor
|
||||
}
|
||||
|
||||
// prepare shell
|
||||
$shell = shell()->cd($this->build_dir)->initializeEnv($this->library);
|
||||
$shell = shell()->cd($this->build_dir)->initializeEnv($this->library)->appendEnv($this->extra_env);
|
||||
|
||||
// config
|
||||
$this->steps >= 1 && $shell->exec("cmake {$this->getConfigureArgs()} {$this->getDefaultCMakeArgs()} {$build_pos}");
|
||||
@@ -77,6 +79,15 @@ class UnixCMakeExecutor extends Executor
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add extra environment flags
|
||||
*/
|
||||
public function addExtraEnv(array $env): static
|
||||
{
|
||||
$this->extra_env = [...$this->extra_env, ...$env];
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* To build steps.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user