Skip to content

Commit 54001ab

Browse files
committed
simplify logic a bit
1 parent 890ff47 commit 54001ab

File tree

1 file changed

+5
-44
lines changed

1 file changed

+5
-44
lines changed

src/SPC/builder/linux/LinuxBuilder.php

Lines changed: 5 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ private function getMakeExtraVars(): array
319319
return array_filter([
320320
'EXTRA_CFLAGS' => getenv('SPC_CMD_VAR_PHP_MAKE_EXTRA_CFLAGS'),
321321
'EXTRA_LIBS' => $config['libs'],
322-
'EXTRA_LDFLAGS' => getenv('SPC_CMD_VAR_PHP_MAKE_EXTRA_LDFLAGS'),
322+
'EXTRA_LDFLAGS' => preg_replace('/-release\s+(\S+)/', '', getenv('SPC_CMD_VAR_PHP_MAKE_EXTRA_LDFLAGS')),
323323
'EXTRA_LDFLAGS_PROGRAM' => "-L{$lib} {$static} -pie",
324324
]);
325325
}
@@ -328,14 +328,12 @@ private function processLibphpSoFile(string $libphpSo): void
328328
{
329329
$ldflags = getenv('SPC_CMD_VAR_PHP_MAKE_EXTRA_LDFLAGS') ?: '';
330330
$libDir = BUILD_LIB_PATH;
331-
$modulesDir = BUILD_MODULES_PATH;
332-
$realLibName = 'libphp.so';
333331
$cwd = getcwd();
334332

335333
if (preg_match('/-release\s+(\S+)/', $ldflags, $matches)) {
336334
$release = $matches[1];
337-
$realLibName = "libphp-{$release}.so";
338-
$libphpRelease = "{$libDir}/{$realLibName}";
335+
$releaseName = "libphp-{$release}.so";
336+
$libphpRelease = "{$libDir}/{$releaseName}";
339337
if (!file_exists($libphpRelease) && file_exists($libphpSo)) {
340338
rename($libphpSo, $libphpRelease);
341339
}
@@ -344,52 +342,15 @@ private function processLibphpSoFile(string $libphpSo): void
344342
if (file_exists($libphpSo)) {
345343
unlink($libphpSo);
346344
}
347-
symlink($realLibName, 'libphp.so');
345+
symlink($releaseName, 'libphp.so');
348346
shell()->exec(sprintf(
349347
'patchelf --set-soname %s %s',
350-
escapeshellarg($realLibName),
348+
escapeshellarg($releaseName),
351349
escapeshellarg($libphpRelease)
352350
));
353351
}
354-
if (is_dir($modulesDir)) {
355-
chdir($modulesDir);
356-
foreach ($this->getExts() as $ext) {
357-
if (!$ext->isBuildShared()) {
358-
continue;
359-
}
360-
$name = $ext->getName();
361-
$versioned = "{$name}-{$release}.so";
362-
$unversioned = "{$name}.so";
363-
$src = "{$modulesDir}/{$versioned}";
364-
$dst = "{$modulesDir}/{$unversioned}";
365-
if (is_file($src)) {
366-
rename($src, $dst);
367-
shell()->exec(sprintf(
368-
'patchelf --set-soname %s %s',
369-
escapeshellarg($unversioned),
370-
escapeshellarg($dst)
371-
));
372-
}
373-
}
374-
}
375352
chdir($cwd);
376353
}
377-
378-
$target = "{$libDir}/{$realLibName}";
379-
if (file_exists($target)) {
380-
[, $output] = shell()->execWithResult('readelf -d ' . escapeshellarg($target));
381-
$output = implode("\n", $output);
382-
if (preg_match('/SONAME.*\[(.+)]/', $output, $sonameMatch)) {
383-
$currentSoname = $sonameMatch[1];
384-
if ($currentSoname !== basename($target)) {
385-
shell()->exec(sprintf(
386-
'patchelf --set-soname %s %s',
387-
escapeshellarg(basename($target)),
388-
escapeshellarg($target)
389-
));
390-
}
391-
}
392-
}
393354
}
394355

395356
/**

0 commit comments

Comments
 (0)