why do we have prefix= calls instead of prefix=BUILD_ROOT_DIR?

This commit is contained in:
DubbleClick 2025-05-20 22:19:09 +07:00
parent a9f81dd38e
commit 03ca3f4f59
6 changed files with 94 additions and 12 deletions

View File

@ -456,9 +456,6 @@
"openssl": {
"notes": true,
"type": "builtin",
"target": [
"static"
],
"arg-type": "custom",
"arg-type-windows": "with",
"lib-depends": [

View File

@ -5,6 +5,7 @@ declare(strict_types=1);
namespace SPC\builder\extension;
use SPC\builder\Extension;
use SPC\builder\linux\LinuxBuilder;
use SPC\builder\macos\MacOSBuilder;
use SPC\exception\FileSystemException;
use SPC\exception\WrongUsageException;
@ -54,4 +55,76 @@ class curl extends Extension
FileSystem::replaceFileRegex(SOURCE_PATH . '/php-src/configure', '/-lcurl/', $this->getLibFilesString() . $frameworks);
return true;
}
public function patchBeforeSharedConfigure(): bool
{
$file = SOURCE_PATH . '/php-src/ext/curl/config.m4';
$content = FileSystem::readFile($file);
// Inject patch before it
$patch = ' save_LIBS="$LIBS"
LIBS="$LIBS $CURL_LIBS"
';
// Check if already patched
if (str_contains($content, $patch)) {
return false; // Already patched
}
// Match the line containing PHP_CHECK_LIBRARY for curl
$pattern = '/(PHP_CHECK_LIBRARY\(\[curl],\s*\[curl_easy_perform],)/';
// Restore LIBS after the check — append this just after the macro block
$restore = '
LIBS="$save_LIBS"';
// Apply patch
$patched = preg_replace_callback($pattern, function ($matches) use ($patch) {
return $patch . $matches[1];
}, $content, 1);
// Inject restore after the matching PHP_CHECK_LIBRARY block
$patched = preg_replace(
'/(PHP_CHECK_LIBRARY\(\[curl],\s*\[curl_easy_perform],.*?\)\n)/s',
"$1$restore\n",
$patched,
1
);
if ($patched === null) {
throw new \RuntimeException("Failed to patch config.m4 due to a regex error");
}
FileSystem::writeFile($file, $patched);
return true;
}
public function getUnixConfigureArg(bool $shared = false): string
{
return '--with-curl';
}
public function buildUnixShared(): void
{
if (!$this->builder instanceof LinuxBuilder) {
parent::buildUnixShared();
return;
}
FileSystem::replaceFileStr(
$this->source_dir . '/config.m4',
['$ext_dir/phar.1', '$ext_dir/phar.phar.1'],
['${ext_dir}phar.1', '${ext_dir}phar.phar.1']
);
try {
parent::buildUnixShared();
} finally {
FileSystem::replaceFileStr(
$this->source_dir . '/config.m4',
['${ext_dir}phar.1', '${ext_dir}phar.phar.1'],
['$ext_dir/phar.1', '$ext_dir/phar.phar.1']
);
}
}
}

View File

@ -59,6 +59,7 @@ class libpng extends MacOSLibraryBase
->cd(BUILD_LIB_PATH)
->exec('ln -sf libpng16.a libpng.a');
$this->patchPkgconfPrefix(['libpng16.pc'], PKGCONF_PATCH_PREFIX);
$this->patchLaDependencyPrefix(['libpng16.la']);
$this->cleanLaFiles();
}
}

View File

@ -84,6 +84,23 @@ trait UnixLibraryTrait
}
}
public function patchLaDependencyPrefix(array $files): void
{
logger()->info('Patching library [' . static::NAME . '] la files');
foreach ($files as $name) {
$realpath = realpath(BUILD_LIB_PATH . '/' . $name);
if ($realpath === false) {
throw new RuntimeException('Cannot find library [' . static::NAME . '] la file [' . $name . '] !');
}
logger()->debug('Patching ' . $realpath);
// replace prefix
$file = FileSystem::readFile($realpath);
$file = str_replace(' /lib/', ' ' . BUILD_LIB_PATH . '/', $file);
$file = preg_replace("/^libdir=.*$/m", "libdir='" . BUILD_LIB_PATH . "'", $file);
FileSystem::writeFile($realpath, $file);
}
}
/**
* remove libtool archive files
*

View File

@ -80,17 +80,10 @@ trait imagemagick
'includearchdir=${prefix}/include/ImageMagick-7'
);
}
$filelist = [
$this->patchLaDependencyPrefix([
'libMagick++-7.Q16HDRI.la',
'libMagickCore-7.Q16HDRI.la',
'libMagickWand-7.Q16HDRI.la',
];
foreach ($filelist as $file) {
FileSystem::replaceFileStr(
BUILD_LIB_PATH . '/' . $file,
' /lib/',
' ' . BUILD_LIB_PATH . '/',
);
}
]);
}
}

View File

@ -50,5 +50,6 @@ trait ldap
->exec("make -j{$this->builder->concurrency}")
->exec('make install DESTDIR=' . BUILD_ROOT_PATH);
$this->patchPkgconfPrefix(['ldap.pc', 'lber.pc']);
$this->patchLaDependencyPrefix(['libldap.la', 'liblber.la']);
}
}