From 05e3898e7a497f53f84b9fa9f7835cdbcc4ffd3d Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Fri, 16 Feb 2024 01:28:10 +0800 Subject: [PATCH] add gettext support --- README-zh.md | 2 +- README.md | 2 +- config/ext.json | 2 +- config/lib.json | 16 +++++++++++++ config/source.json | 9 ++++++++ src/SPC/builder/extension/gettext.php | 27 ++++++++++++++++++++++ src/SPC/builder/linux/library/gettext.php | 12 ++++++++++ src/SPC/builder/macos/library/gettext.php | 12 ++++++++++ src/SPC/builder/unix/library/gettext.php | 27 ++++++++++++++++++++++ src/SPC/command/BuildCliCommand.php | 2 +- src/globals/objs/test.mo | Bin 0 -> 376 bytes src/globals/test-extensions.php | 2 +- src/globals/tests/gettext.php | 23 ++++++++++++++++++ 13 files changed, 131 insertions(+), 5 deletions(-) create mode 100644 src/SPC/builder/extension/gettext.php create mode 100644 src/SPC/builder/linux/library/gettext.php create mode 100644 src/SPC/builder/macos/library/gettext.php create mode 100644 src/SPC/builder/unix/library/gettext.php create mode 100644 src/globals/objs/test.mo create mode 100644 src/globals/tests/gettext.php diff --git a/README-zh.md b/README-zh.md index 7fb1384c..a4b73279 100755 --- a/README-zh.md +++ b/README-zh.md @@ -248,7 +248,7 @@ bin/spc micro:combine my-app.phar -I "memory_limit=4G" -I "disable_functions=sys ## 赞助本项目 -你可以在 [我的个人赞助页](https://github.com/crazywhalecc/crazywhalecc/blob/master/FUNDING.md) 支持我和我的项目。 +你可以在 [我的个人赞助页](https://github.com/crazywhalecc/crazywhalecc/blob/master/FUNDING.md) 支持我和我的项目。你捐赠的一部分将会被用于维护 **static-php.dev** 服务器。 ## 开源协议 diff --git a/README.md b/README.md index 9f5a5d47..15e0f556 100755 --- a/README.md +++ b/README.md @@ -272,7 +272,7 @@ Now there is a [static-php](https://github.com/static-php) organization, which i ## Sponsor this project -You can sponsor my project on [this page](https://github.com/crazywhalecc/crazywhalecc/blob/master/FUNDING.md). +You can sponsor my project on [this page](https://github.com/crazywhalecc/crazywhalecc/blob/master/FUNDING.md). A portion of your donation will be used to maintain the **static-php.dev** server. ## Open-Source License diff --git a/config/ext.json b/config/ext.json index 3ee4cd32..ed63bf4a 100644 --- a/config/ext.json +++ b/config/ext.json @@ -95,7 +95,7 @@ }, "gettext": { "type": "builtin", - "arg-type": "with", + "arg-type": "with-prefix", "lib-depends": [ "gettext" ] diff --git a/config/lib.json b/config/lib.json index d9400b76..6f3b058e 100644 --- a/config/lib.json +++ b/config/lib.json @@ -83,6 +83,22 @@ "brotli" ] }, + "gettext": { + "source": "gettext", + "static-libs-unix": [ + "libintl.a" + ], + "lib-depends": [ + "libiconv" + ], + "lib-suggests": [ + "ncurses", + "libxml2" + ], + "frameworks": [ + "CoreFoundation" + ] + }, "glfw": { "source": "ext-glfw", "static-libs-unix": [ diff --git a/config/source.json b/config/source.json index b62ac334..73212640 100644 --- a/config/source.json +++ b/config/source.json @@ -129,6 +129,15 @@ "path": "LICENSE.TXT" } }, + "gettext": { + "type": "filelist", + "url": "https://ftp.gnu.org/pub/gnu/gettext/", + "regex": "/href=\"(?gettext-(?[^\"]+)\\.tar\\.xz)\"/", + "license": { + "type": "file", + "path": "COPYING" + } + }, "gmp": { "type": "ghtagtar", "repo": "alisw/GMP", diff --git a/src/SPC/builder/extension/gettext.php b/src/SPC/builder/extension/gettext.php new file mode 100644 index 00000000..19f48f7e --- /dev/null +++ b/src/SPC/builder/extension/gettext.php @@ -0,0 +1,27 @@ +builder instanceof MacOSBuilder ? ' ' . $this->builder->getFrameworks(true) . ' ' : ''; + FileSystem::replaceFileRegex(SOURCE_PATH . '/php-src/configure', '/-lintl/', $this->getLibFilesString() . $frameworks); + return true; + } +} diff --git a/src/SPC/builder/linux/library/gettext.php b/src/SPC/builder/linux/library/gettext.php new file mode 100644 index 00000000..58b54b82 --- /dev/null +++ b/src/SPC/builder/linux/library/gettext.php @@ -0,0 +1,12 @@ +builder->getLib('ncurses') ? ('--with-libncurses-prefix=' . BUILD_ROOT_PATH . ' ') : ''; + $extra .= $this->builder->getLib('libxml2') ? ('--with-libxml2-prefix=' . BUILD_ROOT_PATH . ' ') : ''; + shell()->cd($this->source_dir) + ->exec( + './configure ' . + '--enable-static ' . + '--disable-shared ' . + '--disable-java ' . + $extra . + '--with-libiconv-prefix=' . BUILD_ROOT_PATH . ' ' . + '--prefix=' . BUILD_ROOT_PATH + ) + ->exec('make clean') + ->exec("make -j{$this->builder->concurrency}") + ->exec('make install'); + } +} diff --git a/src/SPC/command/BuildCliCommand.php b/src/SPC/command/BuildCliCommand.php index fa5e40b6..24d241e3 100644 --- a/src/SPC/command/BuildCliCommand.php +++ b/src/SPC/command/BuildCliCommand.php @@ -32,7 +32,7 @@ class BuildCliCommand extends BuildCommand $this->addOption('enable-zts', null, null, 'enable ZTS support'); $this->addOption('disable-opcache-jit', null, null, 'disable opcache jit'); $this->addOption('with-hardcoded-ini', 'I', InputOption::VALUE_IS_ARRAY | InputOption::VALUE_REQUIRED, 'Patch PHP source code, inject hardcoded INI'); - $this->addOption('with-micro-fake-cli', null, null, 'Enable phpmicro fake cli'); + $this->addOption('with-micro-fake-cli', null, null, 'Let phpmicro\'s PHP_SAPI use "cli" instead of "micro"'); $this->addOption('with-suggested-libs', 'L', null, 'Build with suggested libs for selected exts and libs'); $this->addOption('with-suggested-exts', 'E', null, 'Build with suggested extensions for selected exts'); $this->addOption('with-added-patch', 'P', InputOption::VALUE_IS_ARRAY | InputOption::VALUE_REQUIRED, 'Inject patch script outside'); diff --git a/src/globals/objs/test.mo b/src/globals/objs/test.mo new file mode 100644 index 0000000000000000000000000000000000000000..208349ee17b90f7980242e3c3ffc61dc78a5dd8f GIT binary patch literal 376 zcmYL@y-ve06h;H$N6N^;!r&cTV5>|)HH}*$>?EXV1#G4@!6?{~Cfn?Mg}lL1@66|lP&1lRCx12yb0|7q|4^7H=j z{rMVX&OWM{$MGCbm20#$1Z8w^Nkczgy` zQ!ZqwaG~TAL7XO|No&&MykF^#b>*r91|k-0rG4Bv3J2DBW#GG)8hpH3`op@C+MJ-- lgLIAZr;}ocyQ^NSb*~&|W@hKwlmvC}v=0Neluvb~f?s;kWEcPd literal 0 HcmV?d00001 diff --git a/src/globals/test-extensions.php b/src/globals/test-extensions.php index 9bc07eba..38c97f31 100644 --- a/src/globals/test-extensions.php +++ b/src/globals/test-extensions.php @@ -13,7 +13,7 @@ declare(strict_types=1); // If you want to test your added extensions and libs, add below (comma separated, example `bcmath,openssl`). $extensions = match (PHP_OS_FAMILY) { - 'Linux', 'Darwin' => 'event', + 'Linux', 'Darwin' => 'gettext', 'Windows' => 'mbstring,openssl', }; diff --git a/src/globals/tests/gettext.php b/src/globals/tests/gettext.php new file mode 100644 index 00000000..dacc512c --- /dev/null +++ b/src/globals/tests/gettext.php @@ -0,0 +1,23 @@ +