mirror of
https://github.com/crazywhalecc/static-php-cli.git
synced 2026-03-18 04:44:53 +08:00
simplify logic a bit
This commit is contained in:
parent
890ff475f1
commit
54001ab868
@ -319,7 +319,7 @@ class LinuxBuilder extends UnixBuilderBase
|
|||||||
return array_filter([
|
return array_filter([
|
||||||
'EXTRA_CFLAGS' => getenv('SPC_CMD_VAR_PHP_MAKE_EXTRA_CFLAGS'),
|
'EXTRA_CFLAGS' => getenv('SPC_CMD_VAR_PHP_MAKE_EXTRA_CFLAGS'),
|
||||||
'EXTRA_LIBS' => $config['libs'],
|
'EXTRA_LIBS' => $config['libs'],
|
||||||
'EXTRA_LDFLAGS' => getenv('SPC_CMD_VAR_PHP_MAKE_EXTRA_LDFLAGS'),
|
'EXTRA_LDFLAGS' => preg_replace('/-release\s+(\S+)/', '', getenv('SPC_CMD_VAR_PHP_MAKE_EXTRA_LDFLAGS')),
|
||||||
'EXTRA_LDFLAGS_PROGRAM' => "-L{$lib} {$static} -pie",
|
'EXTRA_LDFLAGS_PROGRAM' => "-L{$lib} {$static} -pie",
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
@ -328,14 +328,12 @@ class LinuxBuilder extends UnixBuilderBase
|
|||||||
{
|
{
|
||||||
$ldflags = getenv('SPC_CMD_VAR_PHP_MAKE_EXTRA_LDFLAGS') ?: '';
|
$ldflags = getenv('SPC_CMD_VAR_PHP_MAKE_EXTRA_LDFLAGS') ?: '';
|
||||||
$libDir = BUILD_LIB_PATH;
|
$libDir = BUILD_LIB_PATH;
|
||||||
$modulesDir = BUILD_MODULES_PATH;
|
|
||||||
$realLibName = 'libphp.so';
|
|
||||||
$cwd = getcwd();
|
$cwd = getcwd();
|
||||||
|
|
||||||
if (preg_match('/-release\s+(\S+)/', $ldflags, $matches)) {
|
if (preg_match('/-release\s+(\S+)/', $ldflags, $matches)) {
|
||||||
$release = $matches[1];
|
$release = $matches[1];
|
||||||
$realLibName = "libphp-{$release}.so";
|
$releaseName = "libphp-{$release}.so";
|
||||||
$libphpRelease = "{$libDir}/{$realLibName}";
|
$libphpRelease = "{$libDir}/{$releaseName}";
|
||||||
if (!file_exists($libphpRelease) && file_exists($libphpSo)) {
|
if (!file_exists($libphpRelease) && file_exists($libphpSo)) {
|
||||||
rename($libphpSo, $libphpRelease);
|
rename($libphpSo, $libphpRelease);
|
||||||
}
|
}
|
||||||
@ -344,52 +342,15 @@ class LinuxBuilder extends UnixBuilderBase
|
|||||||
if (file_exists($libphpSo)) {
|
if (file_exists($libphpSo)) {
|
||||||
unlink($libphpSo);
|
unlink($libphpSo);
|
||||||
}
|
}
|
||||||
symlink($realLibName, 'libphp.so');
|
symlink($releaseName, 'libphp.so');
|
||||||
shell()->exec(sprintf(
|
shell()->exec(sprintf(
|
||||||
'patchelf --set-soname %s %s',
|
'patchelf --set-soname %s %s',
|
||||||
escapeshellarg($realLibName),
|
escapeshellarg($releaseName),
|
||||||
escapeshellarg($libphpRelease)
|
escapeshellarg($libphpRelease)
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
if (is_dir($modulesDir)) {
|
|
||||||
chdir($modulesDir);
|
|
||||||
foreach ($this->getExts() as $ext) {
|
|
||||||
if (!$ext->isBuildShared()) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
$name = $ext->getName();
|
|
||||||
$versioned = "{$name}-{$release}.so";
|
|
||||||
$unversioned = "{$name}.so";
|
|
||||||
$src = "{$modulesDir}/{$versioned}";
|
|
||||||
$dst = "{$modulesDir}/{$unversioned}";
|
|
||||||
if (is_file($src)) {
|
|
||||||
rename($src, $dst);
|
|
||||||
shell()->exec(sprintf(
|
|
||||||
'patchelf --set-soname %s %s',
|
|
||||||
escapeshellarg($unversioned),
|
|
||||||
escapeshellarg($dst)
|
|
||||||
));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
chdir($cwd);
|
chdir($cwd);
|
||||||
}
|
}
|
||||||
|
|
||||||
$target = "{$libDir}/{$realLibName}";
|
|
||||||
if (file_exists($target)) {
|
|
||||||
[, $output] = shell()->execWithResult('readelf -d ' . escapeshellarg($target));
|
|
||||||
$output = implode("\n", $output);
|
|
||||||
if (preg_match('/SONAME.*\[(.+)]/', $output, $sonameMatch)) {
|
|
||||||
$currentSoname = $sonameMatch[1];
|
|
||||||
if ($currentSoname !== basename($target)) {
|
|
||||||
shell()->exec(sprintf(
|
|
||||||
'patchelf --set-soname %s %s',
|
|
||||||
escapeshellarg(basename($target)),
|
|
||||||
escapeshellarg($target)
|
|
||||||
));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user