From 03ca3f4f59951a2f438edfccfb04989b371513b5 Mon Sep 17 00:00:00 2001 From: DubbleClick Date: Tue, 20 May 2025 22:19:09 +0700 Subject: [PATCH] why do we have prefix= calls instead of prefix=BUILD_ROOT_DIR? --- config/ext.json | 3 - src/SPC/builder/extension/curl.php | 73 ++++++++++++++++++++ src/SPC/builder/macos/library/libpng.php | 1 + src/SPC/builder/traits/UnixLibraryTrait.php | 17 +++++ src/SPC/builder/unix/library/imagemagick.php | 11 +-- src/SPC/builder/unix/library/ldap.php | 1 + 6 files changed, 94 insertions(+), 12 deletions(-) diff --git a/config/ext.json b/config/ext.json index d051526a..ee1c68db 100644 --- a/config/ext.json +++ b/config/ext.json @@ -456,9 +456,6 @@ "openssl": { "notes": true, "type": "builtin", - "target": [ - "static" - ], "arg-type": "custom", "arg-type-windows": "with", "lib-depends": [ diff --git a/src/SPC/builder/extension/curl.php b/src/SPC/builder/extension/curl.php index d4f8b078..5ed224f6 100644 --- a/src/SPC/builder/extension/curl.php +++ b/src/SPC/builder/extension/curl.php @@ -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'] + ); + } + } } diff --git a/src/SPC/builder/macos/library/libpng.php b/src/SPC/builder/macos/library/libpng.php index b61cc898..f273bff6 100644 --- a/src/SPC/builder/macos/library/libpng.php +++ b/src/SPC/builder/macos/library/libpng.php @@ -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(); } } diff --git a/src/SPC/builder/traits/UnixLibraryTrait.php b/src/SPC/builder/traits/UnixLibraryTrait.php index 8e69f6d3..45de0cf4 100644 --- a/src/SPC/builder/traits/UnixLibraryTrait.php +++ b/src/SPC/builder/traits/UnixLibraryTrait.php @@ -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 * diff --git a/src/SPC/builder/unix/library/imagemagick.php b/src/SPC/builder/unix/library/imagemagick.php index 345cf6f0..deb1e402 100644 --- a/src/SPC/builder/unix/library/imagemagick.php +++ b/src/SPC/builder/unix/library/imagemagick.php @@ -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 . '/', - ); - } + ]); } } diff --git a/src/SPC/builder/unix/library/ldap.php b/src/SPC/builder/unix/library/ldap.php index 2831f094..93f889f0 100644 --- a/src/SPC/builder/unix/library/ldap.php +++ b/src/SPC/builder/unix/library/ldap.php @@ -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']); } }