extra dependencies for extensions

This commit is contained in:
DubbleClick
2025-05-22 12:27:41 +07:00
parent 310be957b6
commit 3713ae8c93
5 changed files with 56 additions and 19 deletions

View File

@@ -11,6 +11,7 @@ use SPC\exception\FileSystemException;
use SPC\exception\RuntimeException;
use SPC\exception\WrongUsageException;
use SPC\store\Config;
use SPC\store\FileSystem;
use Symfony\Component\Console\Input\ArgvInput;
class SPCConfigUtil
@@ -42,7 +43,7 @@ class SPCConfigUtil
* @throws WrongUsageException
* @throws \Throwable
*/
public function config(array $extensions = [], array $libraries = [], bool $include_suggest_ext = false, bool $include_suggest_lib = false): array
public function config(array $extensions = [], array $libraries = [], bool $include_suggest_ext = false, bool $include_suggest_lib = false, $with_dependencies = false): array
{
[$extensions, $libraries] = DependencyUtil::getExtsAndLibs($extensions, $libraries, $include_suggest_ext, $include_suggest_lib);
@@ -54,7 +55,7 @@ class SPCConfigUtil
}
ob_get_clean();
$ldflags = $this->getLdflagsString();
$libs = $this->getLibsString($libraries);
$libs = $this->getLibsString($libraries, $with_dependencies);
$cflags = $this->getIncludesString();
// embed
@@ -97,13 +98,39 @@ class SPCConfigUtil
return '-L' . BUILD_LIB_PATH;
}
private function getLibsString(array $libraries): string
private function getLibsString(array $libraries, bool $withDependencies = false): string
{
$short_name = [];
foreach (array_reverse($libraries) as $library) {
$libs = Config::getLib($library, 'static-libs', []);
foreach ($libs as $lib) {
$short_name[] = $this->getShortLibName($lib);
if ($withDependencies) {
$noExt = str_replace('.a', '', $lib);
$requiredLibs = [];
$pkgconfFile = BUILD_LIB_PATH . "/pkgconfig/{$noExt}.pc";
if (file_exists($pkgconfFile)) {
$lines = file($pkgconfFile);
foreach ($lines as $value) {
if (str_starts_with($value, 'Libs')) {
$items = explode(' ', $value);
foreach ($items as $item) {
$item = trim($item);
if (str_starts_with($item, '-l')) {
$requiredLibs[] = $item;
}
}
}
}
}
foreach ($requiredLibs as $requiredLib) {
if (!in_array($requiredLib, $short_name)) {
$short_name[] = $requiredLib;
}
}
}
else {
$short_name[] = $this->getShortLibName($lib);
}
}
if (PHP_OS_FAMILY !== 'Darwin') {
continue;