-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathaaa_example.php
271 lines (195 loc) · 7.45 KB
/
aaa_example.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
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
<?php
use SwooleCli\Library;
use SwooleCli\Preprocessor;
return function (Preprocessor $p) {
$example_prefix = EXAMPLE_PREFIX;
$openssl_prefix = OPENSSL_PREFIX;
//文件名称 和 库名称一致
$lib = new Library('aaa_example');
$lib->withHomePage('https://opencv.org/')
->withLicense('http://www.gnu.org/licenses/lgpl-2.1.html', Library::LICENSE_LGPL)
->withManual('https://github.com/opencv/opencv.git')
/*
*
//设置现在文件 hash 值验证,hash 值不匹配,下载文件的自动被丢弃
->withFileHash('sha1', '32ead1982fed95c52060cd92187a411de3376ac9')
->withFileHash('md5','538378de497a830092cd497e2f963b5d')
->withFileHash('sha256','5dc841d2dc9f492d57d4550c114f15a03d5ee0275975571ebd82a1fca8604176')
//设置别名
->withAliasName('example')
//明确申明 使用源地址下载
->withDownloadWithOriginURL("https://ftpmirror.gnu.org/gnu/bison/bison-3.8.tar.gz")
//明确申明 不使用代理
->withHttpProxy(false)
//明确申明 每次都执行下载,不使用已下载的缓存文件
->withAutoUpdateFile()
//构建过程中添加代理 (特殊库才需要,比如构建 rav1e 库,构建过程中会自动到代码仓库下载)
->withBuildLibraryHttpProxy()
*/
# 下载扩展源代码 二种方式 (任选一种即可)
/* 下载依赖库源代码方式一 start */
->withUrl('https://github.com/opencv/opencv/archive/refs/tags/4.7.0.tar.gz')
->withFile('opencv-4.7.0.tar.gz')
/* 下载依赖库源代码方式一 end */
/* 下载依赖库源代码方式二 start */
->withFile('opencv-latest.tar.gz')
->withDownloadScript(
'opencv',
<<<EOF
git clone -b main --depth=1 https://github.com/opencv/opencv.git
EOF
)
/* 下载依赖库源代码方式二 end */
# 补全构建环境缺失软件包
// bash make-install-deps.sh
->withPreInstallCommand(
'alpine',
<<<EOF
apk add ninja python3 py3-pip nasm yasm
apk add meson
EOF
)
->withPrefix($example_prefix)
/*
//明确申明 不使用构建缓存 例子: thirdparty/openssl (每次都解压全新源代码到此目录)
->withBuildCached(false)
//明确申明 不使用库缓存 例子: /usr/local/swoole-cli/zlib (每次构建都需要安装到此目录)
->withInstallCached(false)
*/
# 构建源码可以使用cmake 、 autoconfig 、 meson 构建等
/* 使用 cmake 构建 start */
->withBuildScript(
<<<EOF
mkdir -p build
cd build
cmake .. \
-DCMAKE_INSTALL_PREFIX={$example_prefix} \
-DCMAKE_POLICY_DEFAULT_CMP0074=NEW \
-DCMAKE_BUILD_TYPE=Release \
-DBUILD_SHARED_LIBS=OFF \
-DBUILD_STATIC_LIBS=ON
# cmake 查看选项
# cmake -LH ..
# 更多配置选项,请查看 CMakeLists.txt 文件
# 配置选项例子 ;
# -DCMAKE_INSTALL_LIBDIR={$example_prefix}/lib \
# -DCMAKE_INSTALL_INCLUDEDIR={$example_prefix}/include \
# -DCMAKE_CXX_STANDARD=14
# -DCMAKE_C_STANDARD=11
# -DCMAKE_C_COMPILER=clang \
# -DCMAKE_CXX_COMPILER=clang++ \
# -DCMAKE_DISABLE_FIND_PACKAGE_libsharpyuv=ON \
# -DCMAKE_C_FLAGS="-D_POSIX_C_SOURCE=200809L" \
# -DOpenSSL_ROOT={$openssl_prefix} \
# 查找PKGCONFIG配置目录多个使用分号隔开
# -DCMAKE_PREFIX_PATH="{$openssl_prefix};{$openssl_prefix}" \
# 显示构建详情
# -DCMAKE_VERBOSE_MAKEFILE=ON
# CMakeLists.txt 设置 set(CMAKE_VERBOSE_MAKEFILEON ON)
cmake --build . --config Release --target install
EOF
)
/* 使用 cmake 构建 end */
/* 使用 meson、ninja 构建 start */
->withBuildScript(
<<<EOF
meson -h
meson setup -h
# meson configure -h
meson setup build \
-Dprefix={$example_prefix} \
-Dbackend=ninja \
-Dbuildtype=release \
-Ddefault_library=static \
-Db_staticpic=true \
-Db_pie=true \
-Dprefer_static=true
# 更多构建选项,请查看 meson_options.txt 文件
# -Dexamples=disabled
# -Dc_args=-fmax-errors=10 \
# -Dcpp_args=-DMAGIC=123
# meson compile -C build
# meson install -C build
ninja -C build
ninja -C build install
EOF
)
/* 使用 meson、ninja 构建 end */
/* 使用 autoconfig automake 构建 start */
->withConfigure(
<<<EOF
# sh autogen.sh
# libtoolize -ci
# autoreconf -fi
./configure --help
# LDFLAGS="\$LDFLAGS -static"
PACKAGES='openssl '
PACKAGES="\$PACKAGES zlib"
OPENSSL_CFLAGS=$(pkg-config --cflags --static openssl)
OPENSSL_LIBS=$(pkg-config --libs --static openssl)
CPPFLAGS="$(pkg-config --cflags-only-I --static \$PACKAGES)" \
LDFLAGS="$(pkg-config --libs-only-L --static \$PACKAGES) " \
LIBS="$(pkg-config --libs-only-l --static \$PACKAGES)" \
./configure \
--prefix={$example_prefix} \
--enable-shared=no \
--enable-static=yes
# 显示构建详情
# make VERBOSE=1
# 指定安装目录
# make DESTDIR=/usr/local/swoole-cli/example
#
EOF
)
/* 使用 autoconfig automake 构建 end */
/* 默认不需要此配置
->withScriptAfterInstall(
<<<EOF
rm -rf {$example_prefix}/lib/*.so.*
rm -rf {$example_prefix}/lib/*.so
rm -rf {$example_prefix}/lib/*.dylib
EOF
)
//没有pkgconfig 配置的库,手动生成 pkgconfig 配置
->withScriptAfterInstall(
<<<EOF
mkdir -p {$example_prefix}/lib/pkgconfig
cat << '__example_PKGCONFIG_EOF__' > {$example_prefix}/lib/pkgconfig/libexample.pc
prefix={$example_prefix}/
exec_prefix=\${prefix}/
libdir=\${prefix}/lib
includedir=\${prefix}/include/
Name: example
Description: example
Version: 1.0.0
Requires: zlib
Libs: -L\${libdir} -lexample
Libs.private: -lz -lm
Cflags: -I\${includedir}
__example_PKGCONFIG_EOF__
EOF
)
*/
->withPkgName('libexample')
->withBinPath($example_prefix . '/bin/')
//依赖其它静态链接库
->withDependentLibraries('zlib', 'openssl')
/*
//默认不需要此配置,特殊目录才需要配置
->withLdflags('-L' . $example_prefix . '/lib64')
//默认不需要此配置,特殊目录才需要配置
->withPkgConfig($example_prefix . '/lib/ib64/pkgconfig')
*/
;
$p->addLibrary($lib);
/*
//只有当没有 pkgconfig 配置文件才需要编写这里配置; 例子: src/builder/library/bzip2.php
$p->withVariable('CPPFLAGS', '$CPPFLAGS -I' . $example_prefix . '/include');
$p->withVariable('LDFLAGS', '$LDFLAGS -L' . $example_prefix . '/lib');
$p->withVariable('LIBS', '$LIBS -lexample ');
*/
/* 导入需要的变量
$p->withExportVariable('LIBPQ_CFLAGS', '$(pkg-config --cflags --static libpq)');
$p->withExportVariable('LIBPQ_LIBS', '$(pkg-config --libs --static libpq)');
*/
};