-
Notifications
You must be signed in to change notification settings - Fork 77
/
Copy pathbuild.sh
executable file
·348 lines (287 loc) · 9.96 KB
/
build.sh
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
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
#!/bin/bash
set -e
GCC_LIBSTDCXX_VERSION=14.2.0
ZLIB_VERSION=1.3.1
OPENSSL_VERSION=3.3.0
CURL_VERSION=8.7.1
SQLITE_VERSION=3450300
SQLITE_YEAR=2024
# shellcheck source=image/functions.sh
source /hbb_build/functions.sh
# shellcheck source=image/activate_func.sh
source /hbb_build/activate_func.sh
SKIP_INITIALIZE=${SKIP_INITIALIZE:-false}
SKIP_USERS_GROUPS=${SKIP_USERS_GROUPS:-false}
SKIP_LIBS=${SKIP_LIBS:-false}
SKIP_FINALIZE=${SKIP_FINALIZE:-false}
SKIP_LIBSTDCXX=${SKIP_LIBSTDCXX:-$SKIP_LIBS}
SKIP_ZLIB=${SKIP_ZLIB:-$SKIP_LIBS}
SKIP_OPENSSL=${SKIP_OPENSSL:-$SKIP_LIBS}
SKIP_CURL=${SKIP_CURL:-$SKIP_LIBS}
SKIP_SQLITE=${SKIP_SQLITE:-$SKIP_LIBS}
MAKE_CONCURRENCY=2
VARIANTS='exe exe_gc_hardened shlib'
export PATH=/hbb/bin:$PATH
#########################
if ! eval_bool "$SKIP_INITIALIZE"; then
header "Initializing"
run mkdir -p /hbb /hbb/bin
run cp /hbb_build/libcheck /hbb/bin/
run cp /hbb_build/hardening-check /hbb/bin/
run cp /hbb_build/setuser /hbb/bin/
run cp /hbb_build/activate_func.sh /hbb/activate_func.sh
run cp /hbb_build/hbb-activate /hbb/activate
run cp /hbb_build/activate-exec /hbb/activate-exec
if ! eval_bool "$SKIP_USERS_GROUPS"; then
run groupadd -g 9327 builder
run adduser --uid 9327 --gid 9327 builder
fi
for VARIANT in $VARIANTS; do
run mkdir -p "/hbb_$VARIANT"
run cp /hbb_build/activate-exec "/hbb_$VARIANT/"
run cp "/hbb_build/variants/$VARIANT.sh" "/hbb_$VARIANT/activate"
done
header "Updating system, installing compiler toolchain"
run touch /var/lib/rpm/*
run yum update -y
run yum install -y autoconf automake bzip2 cmake curl curl-devel epel-release \
file gettext git libtool m4 openssl-devel patch perl-IPC-Cmd \
pkgconfig python2-devel python2-pip python2-setuptools \
tar zlib-devel "gcc-toolset-$DEVTOOLSET_VERSION" "gcc-toolset-$DEVTOOLSET_VERSION-runtime"
run yum install -y --enablerepo=epel ccache
echo "*link_gomp: %{static|static-libgcc|static-libstdc++|static-libgfortran: libgomp.a%s; : -lgomp } %{static: -ldl }" > /opt/rh/gcc-toolset-${DEVTOOLSET_VERSION}/root/usr/lib/gcc/*-redhat-linux/${DEVTOOLSET_VERSION}/libgomp.spec
fi
## libstdc++
function install_libstdcxx()
{
local VARIANT="$1"
local PREFIX="/hbb_$VARIANT"
header "Installing libstdc++ static libraries: $VARIANT"
download_and_extract gcc-$GCC_LIBSTDCXX_VERSION.tar.gz \
gcc-$GCC_LIBSTDCXX_VERSION \
https://ftpmirror.gnu.org/gcc/gcc-$GCC_LIBSTDCXX_VERSION/gcc-$GCC_LIBSTDCXX_VERSION.tar.gz
(
# shellcheck source=/dev/null
source "$PREFIX/activate"
run rm -rf ../gcc-build
run mkdir ../gcc-build
echo "+ Entering /gcc-build"
cd ../gcc-build
# shellcheck disable=SC2030
CFLAGS=$(adjust_optimization_level "$STATICLIB_CFLAGS")
export CFLAGS
# The libstdc++ build system has a bug. In order for it to enable C++11 thread
# support, it checks for gthreads (part of libgcc) support. This is done by checking
# whether gthr.h can be found and compiled. gthr.h in turn includes gthr-default.h,
# which is autogenerated at the end of the configure script and placed in include/bits.
#
# Therefore we need to run configure twice. The first time to generate include/bits/gthr-default.h,
# which allows the second configure run to detect gthreads support.
#
# https://github.com/FooBarWidget/holy-build-box/issues/19
# shellcheck disable=SC2030
CXXFLAGS=$(adjust_optimization_level "$STATICLIB_CXXFLAGS -Iinclude/bits")
export CXXFLAGS
../gcc-$GCC_LIBSTDCXX_VERSION/libstdc++-v3/configure \
--prefix="$PREFIX" --disable-multilib \
--disable-libstdcxx-visibility --disable-shared
../gcc-$GCC_LIBSTDCXX_VERSION/libstdc++-v3/configure \
--prefix="$PREFIX" --disable-multilib \
--disable-libstdcxx-visibility --disable-shared
# Assert that C++11 thread support is enabled.
run grep -q '^#define _GLIBCXX_HAS_GTHREADS 1$' config.h
run make -j$MAKE_CONCURRENCY
run mkdir -p "$PREFIX/lib"
run cp src/.libs/libstdc++.a "$PREFIX/lib/"
run cp libsupc++/.libs/libsupc++.a "$PREFIX/lib/"
)
# shellcheck disable=SC2181
if [[ "$?" != 0 ]]; then false; fi
echo "Leaving source directory"
popd >/dev/null
run rm -rf gcc-$GCC_LIBSTDCXX_VERSION
run rm -rf gcc-build
}
if ! eval_bool "$SKIP_LIBSTDCXX"; then
for VARIANT in $VARIANTS; do
install_libstdcxx "$VARIANT"
done
fi
### zlib
function install_zlib()
{
local VARIANT="$1"
local PREFIX="/hbb_$VARIANT"
header "Installing zlib $ZLIB_VERSION static libraries: $VARIANT"
download_and_extract zlib-$ZLIB_VERSION.tar.gz \
zlib-$ZLIB_VERSION \
https://zlib.net/fossils/zlib-$ZLIB_VERSION.tar.gz
(
# shellcheck source=/dev/null
source "$PREFIX/activate"
# shellcheck disable=SC2030,SC2031
CFLAGS=$(adjust_optimization_level "$STATICLIB_CFLAGS")
export CFLAGS
run ./configure --prefix="$PREFIX" --static
run make -j$MAKE_CONCURRENCY
run make install
)
# shellcheck disable=SC2181
if [[ "$?" != 0 ]]; then false; fi
echo "Leaving source directory"
popd >/dev/null
run rm -rf zlib-$ZLIB_VERSION
}
if ! eval_bool "$SKIP_ZLIB"; then
for VARIANT in $VARIANTS; do
install_zlib "$VARIANT"
done
fi
### OpenSSL
function install_openssl()
{
local VARIANT="$1"
local PREFIX="/hbb_$VARIANT"
header "Installing OpenSSL $OPENSSL_VERSION static libraries: $PREFIX"
download_and_extract openssl-$OPENSSL_VERSION.tar.gz \
openssl-$OPENSSL_VERSION \
https://www.openssl.org/source/openssl-$OPENSSL_VERSION.tar.gz
(
set -o pipefail
# shellcheck source=/dev/null
source "$PREFIX/activate"
# shellcheck disable=SC2030,SC2001
CFLAGS=$(adjust_optimization_level "$STATICLIB_CFLAGS")
export CFLAGS
# shellcheck disable=SC2153
export LIB_CFLAGS="$SHLIB_CFLAGS"
# shellcheck disable=SC2153
export LIB_LDFLAGS="-Wl,-znodelete -shared -Wl,-Bsymbolic $SHLIB_LDFLAGS"
export DSO_CFLAGS="$SHLIB_CFLAGS"
export DSO_LDFLAGS="-Wl,-z,defs -Wl,-znodelete -shared -Wl,-Bsymbolic $SHLIB_LDFLAGS"
# shellcheck disable=SC2086
run ./Configure "linux-$(uname -m)" \
--prefix="$PREFIX" --openssldir="$PREFIX/openssl" \
threads zlib no-shared no-sse2 no-legacy no-tests
# Force Make to use the environment variables instead
run sed -i "/^LIB_CFLAGS=/d" Makefile
run sed -i "/^LIB_LDFLAGS=/d" Makefile
run sed -i "/^DSO_CFLAGS=/d" Makefile
run sed -i "/^DSO_LDFLAGS=/d" Makefile
run make "-j$MAKE_CONCURRENCY"
run make install_sw
run strip --strip-all "$PREFIX/bin/openssl"
if [[ "$VARIANT" = exe_gc_hardened ]]; then
run hardening-check -b "$PREFIX/bin/openssl"
fi
# shellcheck disable=SC2016
run sed -i 's/^Libs:.*/Libs: -L${libdir} -lcrypto -lz -ldl -lpthread/' "$PREFIX"/lib*/pkgconfig/libcrypto.pc
run sed -i '/^Libs.private:/d' "$PREFIX"/lib*/pkgconfig/libcrypto.pc
)
# shellcheck disable=SC2181
if [[ "$?" != 0 ]]; then false; fi
echo "Leaving source directory"
popd >/dev/null
run rm -rf openssl-$OPENSSL_VERSION
}
if ! eval_bool "$SKIP_OPENSSL"; then
for VARIANT in $VARIANTS; do
install_openssl "$VARIANT"
done
run mv /hbb_exe_gc_hardened/bin/openssl /hbb/bin/
for VARIANT in $VARIANTS; do
run rm -f "/hbb_$VARIANT/bin/openssl"
done
fi
### libcurl
function install_curl()
{
local VARIANT="$1"
local PREFIX="/hbb_$VARIANT"
header "Installing Curl $CURL_VERSION static libraries: $PREFIX"
download_and_extract curl-$CURL_VERSION.tar.bz2 \
curl-$CURL_VERSION \
https://curl.se/download/curl-$CURL_VERSION.tar.bz2
(
# shellcheck source=/dev/null
source "$PREFIX/activate"
# shellcheck disable=SC2030,SC2031
CFLAGS=$(adjust_optimization_level "$STATICLIB_CFLAGS")
export CFLAGS
./configure --prefix="$PREFIX" --disable-shared --disable-debug --enable-optimize --disable-werror \
--disable-curldebug --enable-symbol-hiding --disable-ares --disable-manual --disable-ldap --disable-ldaps \
--disable-rtsp --disable-dict --disable-ftp --disable-ftps --disable-gopher --disable-imap \
--disable-imaps --disable-pop3 --disable-pop3s --without-librtmp --disable-smtp --disable-smtps \
--disable-telnet --disable-tftp --disable-smb --disable-versioned-symbols \
--without-libidn --without-libssh2 --without-nghttp2 \
--with-ssl
run make -j$MAKE_CONCURRENCY
run make install
if [[ "$VARIANT" = exe_gc_hardened ]]; then
run hardening-check -b "$PREFIX/bin/curl"
fi
run rm -f "$PREFIX/bin/curl"
)
# shellcheck disable=SC2181
if [[ "$?" != 0 ]]; then false; fi
echo "Leaving source directory"
popd >/dev/null
run rm -rf curl-$CURL_VERSION
}
if ! eval_bool "$SKIP_CURL"; then
for VARIANT in $VARIANTS; do
install_curl "$VARIANT"
done
fi
### SQLite
function install_sqlite()
{
local VARIANT="$1"
local PREFIX="/hbb_$VARIANT"
header "Installing SQLite $SQLITE_VERSION static libraries: $PREFIX"
download_and_extract sqlite-autoconf-$SQLITE_VERSION.tar.gz \
sqlite-autoconf-$SQLITE_VERSION \
https://www.sqlite.org/$SQLITE_YEAR/sqlite-autoconf-$SQLITE_VERSION.tar.gz
(
# shellcheck source=/dev/null
source "$PREFIX/activate"
# shellcheck disable=SC2031
CFLAGS=$(adjust_optimization_level "$STATICLIB_CFLAGS")
# shellcheck disable=SC2031
CXXFLAGS=$(adjust_optimization_level "$STATICLIB_CXXFLAGS")
export CFLAGS
export CXXFLAGS
run ./configure --prefix="$PREFIX" --enable-static \
--disable-shared --disable-dynamic-extensions
run make -j$MAKE_CONCURRENCY
run make install
if [[ "$VARIANT" = exe_gc_hardened ]]; then
run hardening-check -b "$PREFIX/bin/sqlite3"
fi
run strip --strip-all "$PREFIX/bin/sqlite3"
)
# shellcheck disable=SC2181
if [[ "$?" != 0 ]]; then false; fi
echo "Leaving source directory"
popd >/dev/null
run rm -rf sqlite-autoconf-$SQLITE_VERSION
}
if ! eval_bool "$SKIP_SQLITE"; then
for VARIANT in $VARIANTS; do
install_sqlite "$VARIANT"
done
run mv /hbb_exe_gc_hardened/bin/sqlite3 /hbb/bin/
for VARIANT in $VARIANTS; do
run rm -f "/hbb_$VARIANT/bin/sqlite3"
done
fi
### Finalizing
if ! eval_bool "$SKIP_FINALIZE"; then
header "Finalizing"
run yum clean -y all
run rm -rf /hbb/share/doc /hbb/share/man
run rm -rf /hbb_build /tmp/*
for VARIANT in $VARIANTS; do
run rm -rf "/hbb_$VARIANT/share/doc" "/hbb_$VARIANT/share/man"
done
fi