fix a few accidental array_reverse calls, pkg-config --static instead of pkg-config --libs

This commit is contained in:
DubbleClick 2025-07-23 09:46:32 +07:00
parent 9c4a6b46b6
commit b6be20727d
2 changed files with 18 additions and 12 deletions

View File

@ -39,18 +39,23 @@ class PkgConfigUtil
$libs = explode(' ', trim($result)); $libs = explode(' ', trim($result));
// get other things // get other things
$result = self::execWithResult("pkg-config --static --libs --libs-only-other {$pkg_config_str}"); $result = self::execWithResult("pkg-config --static --libs-only-other {$pkg_config_str}");
// convert libxxx.a to -L{path} -lxxx // convert libxxx.a to -L{path} -lxxx
$exp = explode(' ', trim($result)); $exp = explode(' ', trim($result));
foreach ($exp as $item) { foreach ($exp as $item) {
if (str_starts_with($item, '-L')) {
$libs[] = $item;
continue;
}
// if item ends with .a, convert it to -lxxx // if item ends with .a, convert it to -lxxx
if (str_ends_with($item, '.a') && str_starts_with($item, 'lib') && $force_short_name) { if (str_ends_with($item, '.a') && (str_starts_with($item, 'lib') || str_starts_with($item, BUILD_LIB_PATH))) {
$name = pathinfo($item, PATHINFO_BASENAME); $name = pathinfo($item, PATHINFO_BASENAME);
$name = substr($name, 3, -2); // remove 'lib' prefix and '.a' suffix $name = substr($name, 3, -2); // remove 'lib' prefix and '.a' suffix
$libs[] = "-l{$name}"; $shortlib = "-l{$name}";
} else { if (!in_array($shortlib, $libs)) {
// if item starts with -L, keep it as is $libs[] = $shortlib;
// if item starts with -l, keep it as is }
} elseif (!in_array($item, $libs)) {
$libs[] = $item; $libs[] = $item;
} }
} }

View File

@ -87,9 +87,10 @@ class SPCConfigUtil
$libs .= " {$this->getFrameworksString($extensions)}"; $libs .= " {$this->getFrameworksString($extensions)}";
} }
if ($this->builder->hasCpp()) { if ($this->builder->hasCpp()) {
$libs .= $this->builder instanceof MacOSBuilder ? ' -lc++' : ' -lstdc++'; $libs .= SPCTarget::getTargetOS() === 'Darwin' ? ' -lc++' : ' -lstdc++';
} }
if ($this->libs_only_deps) { if ($this->libs_only_deps) {
$libs = '-L' . BUILD_LIB_PATH . ' ' . $libs;
return [ return [
'cflags' => trim(getenv('CFLAGS') . ' ' . $cflags), 'cflags' => trim(getenv('CFLAGS') . ' ' . $cflags),
'ldflags' => trim(getenv('LDFLAGS') . ' ' . $ldflags), 'ldflags' => trim(getenv('LDFLAGS') . ' ' . $ldflags),
@ -105,6 +106,7 @@ class SPCConfigUtil
if (str_contains($libs, BUILD_LIB_PATH . '/mimalloc.o')) { if (str_contains($libs, BUILD_LIB_PATH . '/mimalloc.o')) {
$libs = BUILD_LIB_PATH . '/mimalloc.o ' . str_replace(BUILD_LIB_PATH . '/mimalloc.o', '', $libs); $libs = BUILD_LIB_PATH . '/mimalloc.o ' . str_replace(BUILD_LIB_PATH . '/mimalloc.o', '', $libs);
} }
$libs = '-L' . BUILD_LIB_PATH . ' ' . $libs;
return [ return [
'cflags' => trim(getenv('CFLAGS') . ' ' . $cflags), 'cflags' => trim(getenv('CFLAGS') . ' ' . $cflags),
'ldflags' => trim(getenv('LDFLAGS') . ' ' . $ldflags), 'ldflags' => trim(getenv('LDFLAGS') . ' ' . $ldflags),
@ -138,8 +140,7 @@ class SPCConfigUtil
} }
} }
$pc_cflags = implode(' ', $pc); $pc_cflags = implode(' ', $pc);
if ($pc_cflags !== '') { if ($pc_cflags !== '' && ($pc_cflags = PkgConfigUtil::getCflags($pc_cflags)) !== '') {
$pc_cflags = PkgConfigUtil::getCflags($pc_cflags);
$includes[] = $pc_cflags; $includes[] = $pc_cflags;
} }
} }
@ -165,7 +166,7 @@ class SPCConfigUtil
if (!file_exists(BUILD_LIB_PATH . "/{$lib}")) { if (!file_exists(BUILD_LIB_PATH . "/{$lib}")) {
throw new WrongUsageException("Library file '{$lib}' for lib [{$library}] does not exist in '" . BUILD_LIB_PATH . "'. Please build it first."); throw new WrongUsageException("Library file '{$lib}' for lib [{$library}] does not exist in '" . BUILD_LIB_PATH . "'. Please build it first.");
} }
$lib_names[] = $use_short_libs ? $this->getShortLibName($lib) : (BUILD_LIB_PATH . "/{$lib}"); $lib_names[] = $this->getShortLibName($lib);
} }
// add frameworks for macOS // add frameworks for macOS
if (SPCTarget::getTargetOS() === 'Darwin') { if (SPCTarget::getTargetOS() === 'Darwin') {
@ -180,13 +181,13 @@ class SPCConfigUtil
} }
$pkg_configs = implode(' ', $pkg_configs); $pkg_configs = implode(' ', $pkg_configs);
if ($pkg_configs !== '') { if ($pkg_configs !== '') {
$pc_libs = array_reverse(PkgConfigUtil::getLibsArray($pkg_configs, $use_short_libs)); $pc_libs = PkgConfigUtil::getLibsArray($pkg_configs);
$lib_names = [...$lib_names, ...$pc_libs]; $lib_names = [...$lib_names, ...$pc_libs];
} }
} }
// post-process // post-process
$lib_names = array_reverse(array_unique($lib_names)); $lib_names = array_reverse(array_unique(array_reverse($lib_names)));
$frameworks = array_unique($frameworks); $frameworks = array_unique($frameworks);
// process frameworks to short_name // process frameworks to short_name