Skip to content

Commit cc832ca

Browse files
authored
修复 macos 环境下,启用 gettext 扩展 缺失依赖库 libintl (#932)
* 修复 macos 环境下,启用gettext 扩展 缺失依赖库 libintl * macos 环境构建添加 链接 framework 去重
1 parent f73a55b commit cc832ca

File tree

5 files changed

+50
-11
lines changed

5 files changed

+50
-11
lines changed

docs/extensions.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
| protobuf |||||
5151
| uuid |||||
5252
| mailparse |||||
53-
| gettext || |||
53+
| gettext || |||
5454
| xslwriter |||||
5555

5656
## 查看 新增的扩展 和 移除的扩展

sapi/src/Preprocessor.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,18 @@ public function withExportVariable(string $key, string $value): static
455455
return $this;
456456
}
457457

458+
protected array $frameworks = ['LDFLAGS' => []];
459+
460+
public function withFramework(string $key, string $value): static
461+
{
462+
if ($this->isMacos()) {
463+
if (isset($this->frameworks[$key]) && !in_array($value, $this->frameworks[$key])) {
464+
$this->frameworks[$key][] = $value;
465+
}
466+
}
467+
return $this;
468+
}
469+
458470
public function getExtension(string $name): ?Extension
459471
{
460472
if (!isset($this->extensionMap[$name])) {

sapi/src/builder/enabled_extensions.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,6 @@
3737
'yaml',
3838
'imagick',
3939
'mongodb',
40-
'xlswriter'
40+
'xlswriter',
41+
'gettext'
4142
];

sapi/src/builder/library/gettext.php

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,50 +6,73 @@
66
return function (Preprocessor $p) {
77

88
// gettext 包含 libintl 库
9-
9+
// 在常见的 Linux 发行版里,libintl 是由 libc 提供的,此时 gettext 编译的时候就不会附带 libintl;
10+
// 而如果在 macOS 上,由于 macOS 的 libc 没有 libintl 的 API,所以 gettext 编译的时候就要附带 libintl
11+
// 详情: https://jia.je/devops/2023/07/08/gentoo-prefix-m1/#libintl
1012
$gettext_prefix = GETTEXT_PREFIX;
1113
$libunistring_prefix = LIBUNISTRING_PREFIX;
1214
$iconv_prefix = ICONV_PREFIX;
1315
$libxml2_prefix = LIBXML2_PREFIX;
1416
$ncurses_prefix = NCURSES_PREFIX;
17+
$options = '';
18+
if ($p->isMacos()) {
19+
$options .= ' --with-included-gettext ';
20+
}
21+
1522
$p->addLibrary(
1623
(new Library('gettext'))
1724
->withHomePage('https://www.gnu.org/software/gettext/')
1825
->withLicense('https://www.gnu.org/licenses/licenses.html', Library::LICENSE_GPL)
1926
->withManual('https://www.gnu.org/software/gettext/')
20-
//->withUrl('https://ftp.gnu.org/gnu/gettext/gettext-0.22.tar.xz')
21-
->withUrl('https://ftpmirror.gnu.org/gnu/gettext/gettext-0.22.tar.xz')
27+
->withUrl('https://ftpmirror.gnu.org/gettext/gettext-0.22.5.tar.gz')
28+
->withFileHash('sha256', "ec1705b1e969b83a9f073144ec806151db88127f5e40fe5a94cb6c8fa48996a0")
2229
->withPrefix($gettext_prefix)
2330
->withConfigure(
2431
<<<EOF
2532
2633
./configure --help
2734
35+
PACKAGES='zlib '
36+
PACKAGES="\$PACKAGES libxml-2.0"
37+
PACKAGES="\$PACKAGES ncursesw"
38+
39+
CPPFLAGS="$(pkg-config --cflags-only-I --static \$PACKAGES) "
40+
LDFLAGS="$(pkg-config --libs-only-L --static \$PACKAGES) "
41+
LIBS="$(pkg-config --libs-only-l --static \$PACKAGES) "
42+
43+
CPPFLAGS="\${CPPFLAGS} -I{$libunistring_prefix}/include/ -I{$iconv_prefix}/include/" \
44+
LDFLAGS="\${LDFLAGS} -L{$libunistring_prefix}/lib/ -L{$iconv_prefix}/lib/" \
45+
LIBS="\${LIBS} -liconv -lunistring " \
2846
./configure \
2947
--prefix={$gettext_prefix} \
3048
--enable-shared=no \
3149
--enable-static=yes \
3250
--enable-relocatable \
3351
--enable-year2038 \
52+
--with-pic \
3453
--with-libiconv-prefix={$iconv_prefix} \
3554
--with-libncurses-prefix={$ncurses_prefix} \
3655
--with-libxml2-prefix={$libxml2_prefix} \
3756
--with-libunistring-prefix={$libunistring_prefix} \
3857
--without-emacs \
3958
--without-lispdir \
40-
--without-cvs \
4159
--disable-acl \
4260
--disable-java \
4361
--disable-csharp \
44-
--without-git
45-
62+
--without-cvs \
63+
--without-git \
64+
--without-xz \
65+
{$options} \
4666
4767
EOF
4868
)
49-
->withDependentLibraries('libunistring', 'libiconv', 'ncurses', 'libxml2')
69+
->withDependentLibraries('libunistring', 'libiconv', 'ncurses', 'libxml2', 'zlib')
5070
);
5171

5272
$p->withVariable('CPPFLAGS', '$CPPFLAGS -I' . $gettext_prefix . '/include');
5373
$p->withVariable('LDFLAGS', '$LDFLAGS -L' . $gettext_prefix . '/lib');
5474
$p->withVariable('LIBS', '$LIBS -lintl ');
75+
if ($p->isMacos()) {
76+
$p->withFramework('LDFLAGS', '-framework CoreFoundation');
77+
}
5578
};

sapi/src/template/make.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
mkdir -p <?= $this->getBuildDir() ?>/<?= $item->name . PHP_EOL ?>
5757
<?php if ($item->untarArchiveCommand == 'tar') : ?>
5858
tar --strip-components=1 -C <?= $this->getBuildDir() ?>/<?= $item->name ?> -xf <?= $this->workDir ?>/pool/lib/<?= $item->file ?>;
59-
<?php elseif($item->untarArchiveCommand == 'unzip') :?>
59+
<?php elseif ($item->untarArchiveCommand == 'unzip') :?>
6060
unzip -d <?=$this->getBuildDir()?>/<?=$item->name?> <?=$this->workDir?>/pool/lib/<?=$item->file ?>;
6161
<?php elseif ($item->untarArchiveCommand == 'tar-default') :?>
6262
tar -C <?= $this->getBuildDir() ?>/<?= $item->name ?> -xf <?= $this->workDir ?>/pool/lib/<?= $item->file ?>;
@@ -198,7 +198,10 @@
198198
export CPPFLAGS=$(echo $CPPFLAGS | tr ' ' '\n' | sort | uniq | tr '\n' ' ')
199199
export LDFLAGS=$(echo $LDFLAGS | tr ' ' '\n' | sort | uniq | tr '\n' ' ')
200200
export LIBS=$(echo $LIBS | tr ' ' '\n' | sort | uniq | tr '\n' ' ')
201-
201+
<?php if ($this->isMacos() && !empty($this->frameworks['LDFLAGS'])):?>
202+
# MACOS 链接 framework
203+
export LDFLAGS="$LDFLAGS <?= implode(" ", $this->frameworks['LDFLAGS']) ?>"
204+
<?php endif; ?>
202205
result_code=$?
203206
[[ $result_code -ne 0 ]] && echo " [ export_variables FAILURE ]" && exit $result_code;
204207
set +x

0 commit comments

Comments
 (0)