mirror of
https://github.com/crazywhalecc/static-php-cli.git
synced 2026-03-18 21:04:52 +08:00
deduplicate those to make it more readable
This commit is contained in:
parent
40f89d1dca
commit
b0538c09bf
@ -222,11 +222,23 @@ class Extension
|
|||||||
{
|
{
|
||||||
$config = (new SPCConfigUtil($this->builder))->config([$this->getName()], array_map(fn ($l) => $l->getName(), $this->builder->getLibs()));
|
$config = (new SPCConfigUtil($this->builder))->config([$this->getName()], array_map(fn ($l) => $l->getName(), $this->builder->getLibs()));
|
||||||
[$staticLibs, $sharedLibs] = $this->splitLibsIntoStaticAndShared($config['libs']);
|
[$staticLibs, $sharedLibs] = $this->splitLibsIntoStaticAndShared($config['libs']);
|
||||||
FileSystem::replaceFileRegex(
|
$lstdcpp = str_contains($sharedLibs, '-lstdc++') ? '-lstdc++' : '';
|
||||||
$this->source_dir . '/Makefile',
|
|
||||||
'/^(.*_SHARED_LIBADD\s*=.*)$/m',
|
$makefileContent = file_get_contents($this->source_dir . '/Makefile');
|
||||||
clean_spaces("$1 {$staticLibs} {$sharedLibs}")
|
|
||||||
);
|
if (preg_match('/^(.*_SHARED_LIBADD\s*=\s*)(.*)$/m', $makefileContent, $matches)) {
|
||||||
|
$prefix = $matches[1];
|
||||||
|
$currentLibs = trim($matches[2]);
|
||||||
|
$newLibs = trim("{$currentLibs} {$staticLibs} {$lstdcpp}");
|
||||||
|
$deduplicatedLibs = deduplicate_flags($newLibs);
|
||||||
|
|
||||||
|
FileSystem::replaceFileRegex(
|
||||||
|
$this->source_dir . '/Makefile',
|
||||||
|
'/^(.*_SHARED_LIBADD\s*=.*)$/m',
|
||||||
|
$prefix . $deduplicatedLibs
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
if ($objs = getenv('SPC_EXTRA_RUNTIME_OBJECTS')) {
|
if ($objs = getenv('SPC_EXTRA_RUNTIME_OBJECTS')) {
|
||||||
FileSystem::replaceFileRegex(
|
FileSystem::replaceFileRegex(
|
||||||
$this->source_dir . '/Makefile',
|
$this->source_dir . '/Makefile',
|
||||||
|
|||||||
@ -245,6 +245,16 @@ function clean_spaces(string $string): string
|
|||||||
return trim(preg_replace('/\s+/', ' ', $string));
|
return trim(preg_replace('/\s+/', ' ', $string));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function deduplicate_flags(string $flags): string
|
||||||
|
{
|
||||||
|
$tokens = preg_split('/\s+/', trim($flags));
|
||||||
|
|
||||||
|
// Reverse, unique, reverse back - keeps last occurrence of duplicates
|
||||||
|
$deduplicated = array_reverse(array_unique(array_reverse($tokens)));
|
||||||
|
|
||||||
|
return implode(' ', $deduplicated);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register a callback function to handle keyboard interrupts (Ctrl+C).
|
* Register a callback function to handle keyboard interrupts (Ctrl+C).
|
||||||
*
|
*
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user