diff --git a/src/SPC/builder/Extension.php b/src/SPC/builder/Extension.php index d25f1f12..aea8ba8c 100644 --- a/src/SPC/builder/Extension.php +++ b/src/SPC/builder/Extension.php @@ -9,6 +9,7 @@ use SPC\exception\RuntimeException; use SPC\exception\WrongUsageException; use SPC\store\Config; use SPC\store\FileSystem; +use SPC\store\SourcePatcher; use SPC\util\SPCConfigUtil; class Extension @@ -189,7 +190,7 @@ class Extension } /** - * Patch code before shared extension ./configure + * Patch code before shared extension phpize * If you need to patch some code, overwrite this * return true if you patched something, false if not */ @@ -198,6 +199,16 @@ class Extension return false; } + /** + * Patch code before shared extension ./configure + * If you need to patch some code, overwrite this + * return true if you patched something, false if not + */ + public function patchBeforeSharedConfigure(): bool + { + return false; + } + /** * Run shared extension check when cli is enabled * @throws RuntimeException @@ -316,7 +327,14 @@ class Extension // prepare configure args shell()->cd($this->source_dir) ->setEnv($env) - ->execWithEnv(BUILD_BIN_PATH . '/phpize') + ->execWithEnv(BUILD_BIN_PATH . '/phpize'); + + if ($this->patchBeforeSharedConfigure()) { + logger()->info('ext [ . ' . $this->getName() . '] patching before shared configure'); + } + + shell()->cd($this->source_dir) + ->setEnv($env) ->execWithEnv('./configure ' . $this->getUnixConfigureArg(true) . ' --with-php-config=' . BUILD_BIN_PATH . '/php-config --enable-shared --disable-static') ->execWithEnv('make clean') ->execWithEnv('make -j' . $this->builder->concurrency) diff --git a/src/SPC/builder/extension/mbregex.php b/src/SPC/builder/extension/mbregex.php index 4bf28544..492c4fbb 100644 --- a/src/SPC/builder/extension/mbregex.php +++ b/src/SPC/builder/extension/mbregex.php @@ -21,6 +21,11 @@ class mbregex extends Extension return ''; } + public function buildUnixShared(): void + { + print('mbregex is already built as part of mbstring, skipping build' . PHP_EOL); + } + /** * mbregex is not an extension, we need to overwrite the default check. */ diff --git a/src/SPC/builder/extension/mbstring.php b/src/SPC/builder/extension/mbstring.php index 5fcb88bd..aa86ee53 100644 --- a/src/SPC/builder/extension/mbstring.php +++ b/src/SPC/builder/extension/mbstring.php @@ -20,4 +20,15 @@ class mbstring extends Extension } return $arg; } + + public function getUnixConfigureArg(bool $shared = false): string + { + $arg = '--enable-mbstring'; + if ($this->builder->getExt('mbregex') === null) { + $arg .= ' --disable-mbregex'; + } else { + $arg .= ' --enable-mbregex'; + } + return $arg; + } } diff --git a/src/SPC/builder/extension/readline.php b/src/SPC/builder/extension/readline.php index 120fa42f..71c82a8b 100644 --- a/src/SPC/builder/extension/readline.php +++ b/src/SPC/builder/extension/readline.php @@ -29,4 +29,22 @@ class readline extends Extension { return '--without-libedit --with-readline=' . BUILD_ROOT_PATH; } + + public function patchBeforeSharedConfigure(): bool + { + FileSystem::replaceFileStr($this->source_dir . '/configure', + 'test "$PHP_LIBEDIT" = "no" && PHP_LIBEDIT=yes', + '' + ); + return true; + } + + public function buildUnixShared(): void + { + if (!file_exists(BUILD_BIN_PATH . '/php') || !file_exists(BUILD_INCLUDE_PATH . '/php/sapi/cli/cli.h')) { + logger()->warning('CLI mode is not enabled, skipping readline build'); + return; + } + parent::buildUnixShared(); + } }