-
Notifications
You must be signed in to change notification settings - Fork 1
/
prepare.php
executable file
·238 lines (186 loc) · 6.98 KB
/
prepare.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
<?php
require __DIR__ . '/vendor/autoload.php';
use SwooleCli\Preprocessor;
use SwooleCli\Library;
$homeDir = getenv('HOME');
$p = Preprocessor::getInstance();
$p->parseArguments($argc, $argv);
$buildType = $p->getBuildType();
if ($p->getInputOption('with-build-type')) {
$buildType = $p->getInputOption('with-build-type');
$p->setBuildType($buildType);
}
# clean
# clean old make.sh
$p->cleanFile(__DIR__ . '/make.sh');
$p->cleanFile(__DIR__ . '/make-install-deps.sh');
$p->cleanFile(__DIR__ . '/make-env.sh');
$p->cleanFile(__DIR__ . '/make-export-variables.sh');
$p->cleanFile(__DIR__ . '/make-download-box.sh');
$p->cleanFile(__DIR__ . '/cppflags.log');
$p->cleanFile(__DIR__ . '/ldflags.log');
$p->cleanFile(__DIR__ . '/libs.log');
$p->cleanFile(__DIR__ . '/configure.backup');
# PHP 默认版本 (此文件配置 /sapi/PHP-VERSION.conf 在 build_native_php分支 和 衍生分支 无效)
$php_version = '8.2.13';
$php_version_id = '802013';
$php_version_tag = 'php-8.2.13';
if ($p->getInputOption('with-php-version')) {
$subject = $p->getInputOption('with-php-version');
$pattern = '/(\d{1,2})\.(\d{1,2})\.(\d{1,})\w*/';
if (preg_match($pattern, $subject, $match)) {
$php_version = $match[0];
$php_version_id =
str_pad($match[1], 2, '0') .
str_pad($match[2], 2, '0') .
sprintf('%02d', $match[3]);
$php_version_tag = 'php-' . $match[0];
echo PHP_EOL;
}
}
define('BUILD_PHP_VERSION', $php_version);
define('BUILD_PHP_VERSION_ID', intval($php_version_id));
define('BUILD_PHP_VERSION_TAG', $php_version_tag);
define('BUILD_CUSTOM_PHP_VERSION_ID', intval(substr($php_version_id, 0, 4))); //取主版本号和次版本号
// Sync code from php-src
$p->setPhpSrcDir($p->getWorkDir() . '/var/php-' . BUILD_PHP_VERSION);
// Compile directly on the host machine, not in the docker container
if ($p->getInputOption('without-docker') || ($p->isMacos())) {
$p->setWorkDir(__DIR__);
$p->setBuildDir(__DIR__ . '/thirdparty');
}
$p->setRootDir(__DIR__);
//设置 PHP 源码所在目录 (构建时将进入此目录进行构建)
if ($p->getInputOption('with-php-src')) {
$p->setPhpSrcDir($p->getInputOption('with-php-src'));
} else {
$p->setPhpSrcDir($p->getRootDir() . '/thirdparty/php-src');
}
//设置PHP 安装目录
define("BUILD_PHP_INSTALL_PREFIX", $p->getRootDir() . '/bin/php-' . BUILD_PHP_VERSION);
if ($p->getInputOption('with-override-default-enabled-ext')) {
$p->setExtEnabled([]);
}
if ($p->getInputOption('with-global-prefix')) {
$p->setGlobalPrefix($p->getInputOption('with-global-prefix'));
}
$buildType = $p->getBuildType();
if ($p->getInputOption('with-build-type')) {
$buildType = $p->getInputOption('with-build-type');
$p->setBuildType($buildType);
}
define('PHP_CLI_BUILD_TYPE', $buildType);
define('PHP_CLI_GLOBAL_PREFIX', $p->getGlobalPrefix());
if ($p->getInputOption('with-parallel-jobs')) {
$p->setMaxJob(intval($p->getInputOption('with-parallel-jobs')));
}
if ($p->getInputOption('with-http-proxy')) {
$http_proxy = $p->getInputOption('with-http-proxy');
$proxyConfig = <<<EOF
export HTTP_PROXY={$http_proxy}
export HTTPS_PROXY={$http_proxy}
EOF;
$proxyConfig .= PHP_EOL;
$proxyConfig .= <<<'EOF'
NO_PROXY="127.0.0.0/8,10.0.0.0/8,100.64.0.0/10,172.16.0.0/12,192.168.0.0/16"
NO_PROXY="${NO_PROXY},::1/128,fe80::/10,fd00::/8,ff00::/8"
NO_PROXY="${NO_PROXY},.aliyuncs.com,.aliyun.com,.tencent.com"
NO_PROXY="${NO_PROXY},.tsinghua.edu.cn,.ustc.edu.cn,.npmmirror.com"
NO_PROXY="${NO_PROXY},ftpmirror.gnu.org"
NO_PROXY="${NO_PROXY},gitee.com,gitcode.com"
NO_PROXY="${NO_PROXY},.myqcloud.com,.swoole.com"
NO_PROXY="${NO_PROXY},dl-cdn.alpinelinux.org"
NO_PROXY="${NO_PROXY},deb.debian.org,security.debian.org"
NO_PROXY="${NO_PROXY},archive.ubuntu.com,security.ubuntu.com"
NO_PROXY="${NO_PROXY},pypi.python.org,bootstrap.pypa.io"
export NO_PROXY="${NO_PROXY},localhost"
EOF;
$p->setProxyConfig($proxyConfig, $http_proxy);
}
if ($p->isMacos()) {
$p->setLogicalProcessors('$(sysctl -n hw.ncpu)');
} else {
$p->setLogicalProcessors('$(nproc 2> /dev/null)');
}
if ($p->isMacos()) {
// -lintl -Wl,-framework -Wl,CoreFoundation
//$p->setExtraLdflags('-framework CoreFoundation -framework SystemConfiguration -undefined dynamic_lookup');
$p->setExtraLdflags('-undefined dynamic_lookup');
if (is_file('/usr/local/opt/llvm/bin/ld64.lld')) {
$p->withBinPath('/usr/local/opt/llvm/bin')
->withBinPath('/usr/local/opt/flex/bin')
->withBinPath('/usr/local/opt/bison/bin')
->withBinPath('/usr/local/opt/libtool/bin')
->withBinPath('/usr/local/opt/m4/bin')
->withBinPath('/usr/local/opt/automake/bin/')
->withBinPath('/usr/local/opt/autoconf/bin/')
->setLinker('ld64.lld');
} elseif (is_file('/opt/homebrew/opt/llvm/bin/ld64.lld')) { //兼容 macos arm64
$p->withBinPath('/opt/homebrew/opt/llvm/bin/')
->withBinPath('/opt/homebrew/opt/flex/bin')
->withBinPath('/opt/homebrew/opt/bison/bin')
->withBinPath('/opt/homebrew/opt/libtool/bin')
->withBinPath('/opt/homebrew/opt/m4/bin')
->withBinPath('/opt/homebrew/opt/automake/bin/')
->withBinPath('/opt/homebrew/opt/autoconf/bin/')
->setLinker('ld64.lld');
} else {
$p->setLinker('lld');
}
} else {
$p->setLinker('ld.lld');
}
$c_compiler = $p->getInputOption('with-c-compiler');
if ($c_compiler == 'gcc') {
$p->set_C_COMPILER('gcc');
$p->set_CXX_COMPILER('g++');
$p->setLinker('ld');
}
if ($p->getInputOption('with-build-shared-lib')) {
define('BUILD_SHARED_LIBS', true);
define('BUILD_STATIC_LIBS', false);
} else {
define('BUILD_SHARED_LIBS', false);
define('BUILD_STATIC_LIBS', true);
}
# 设置CPU核数 ; 获取CPU核数,用于 make -j $(nproc)
# $p->setMaxJob(`nproc 2> /dev/null || sysctl -n hw.ncpu`); // nproc on macos ;
# `grep "processor" /proc/cpuinfo | sort -u | wc -l`
if ($p->getOsType() == 'macos') {
$p->withPreInstallCommand(
'macos',
<<<'EOF'
# ls -lh /usr/local/opt
export HOMEBREW_INSTALL_FROM_API=1
export HOMEBREW_NO_ANALYTICS=1
export HOMEBREW_NO_AUTO_UPDATE=1
export PIPENV_PYPI_MIRROR=https://pypi.python.org/simple
EOF
);
} else {
$p->withPreInstallCommand(
'debian',
<<<'EOF'
test -f /etc/apt/apt.conf.d/proxy.conf && rm -rf /etc/apt/apt.conf.d/proxy.conf
export DEBIAN_FRONTEND=noninteractive
EOF
);
}
# GN=generate-ninja
$header = <<<'EOF'
#!/use/bin/env bash
export CPU_NUMS=`nproc 2> /dev/null || sysctl -n hw.ncpu`
# `grep "processor" /proc/cpuinfo | sort -u | wc -l`
export __CURRENT_DIR__=$(cd "$(dirname $0)";pwd)
EOF;
#$p->setExtraCflags('-fno-ident -Os');
$p->setExtraCflags(' -Os');
// Generate make.sh
$p->execute();
function install_libraries(Preprocessor $p): void
{
if ($p->getInputOption('with-c-compiler') == 'x86_64-linux-musl-gcc') {
$p->loadDependentLibrary('musl_cross_make');
}
# $p->loadDependentLibrary('php');
}