Skip to content

Latest commit

 

History

History
executable file
·
267 lines (237 loc) · 7.76 KB

build.sh

File metadata and controls

executable file
·
267 lines (237 loc) · 7.76 KB
 
Dec 3, 2016
Dec 3, 2016
1
#!/usr/bin/env bash
Jan 24, 2017
Jan 24, 2017
2
3
4
5
6
7
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
################################################################################
#
Oct 17, 2016
Oct 17, 2016
8
9
10
11
# This script builds NSS with gyp and ninja.
#
# This build system is still under development. It does not yet support all
# the features or platforms that NSS supports.
Oct 17, 2016
Oct 17, 2016
13
14
set -e
Jan 10, 2017
Jan 10, 2017
15
cwd=$(cd $(dirname $0); pwd -P)
Jul 10, 2019
Jul 10, 2019
16
17
18
19
dist_dir="$cwd/../dist"
argsfile="$dist_dir/build_args"
source "$cwd/coreconf/nspr.sh"
source "$cwd/coreconf/sanitizers.sh"
May 31, 2017
May 31, 2017
20
GYP=${GYP:-gyp}
Nov 7, 2016
Nov 7, 2016
21
Oct 26, 2016
Oct 26, 2016
22
# Usage info
Jan 10, 2017
Jan 10, 2017
23
24
show_help()
{
Jul 10, 2019
Jul 10, 2019
25
cat "$cwd/help.txt"
Oct 26, 2016
Oct 26, 2016
26
27
}
Jan 10, 2017
Jan 10, 2017
28
29
30
31
32
33
34
35
36
37
38
39
run_verbose()
{
if [ "$verbose" = 1 ]; then
echo "$@"
exec 3>&1
else
exec 3>/dev/null
fi
"$@" 1>&3 2>&3
exec 3>&-
}
Jul 10, 2019
Jul 10, 2019
40
41
42
43
44
45
46
47
# The prehistoric bash on Mac doesn't support @Q quoting.
# The consequences aren't that serious, unless there are odd arrangements of spaces.
if /usr/bin/env bash -c 'x=1;echo "${x@Q}"' >/dev/null 2>&1; then
Q() { echo "${@@Q}"; }
else
Q() { echo "$@"; }
fi
Oct 22, 2016
Oct 22, 2016
48
if [ -n "$CCC" ] && [ -z "$CXX" ]; then
Oct 22, 2016
Oct 22, 2016
49
50
51
export CXX="$CCC"
fi
Oct 26, 2016
Oct 26, 2016
52
53
opt_build=0
build_64=0
Oct 28, 2016
Oct 28, 2016
54
55
clean=0
rebuild_gyp=0
Jan 5, 2017
Jan 5, 2017
56
rebuild_nspr=0
Sep 12, 2019
Sep 12, 2019
57
58
59
build_nspr_tests=0
run_nspr_tests=0
exit_after_nspr=0
Oct 28, 2016
Oct 28, 2016
60
target=Debug
Nov 15, 2016
Nov 15, 2016
61
verbose=0
Nov 18, 2016
Nov 18, 2016
62
fuzz=0
Jan 20, 2017
Jan 20, 2017
63
64
fuzz_tls=0
fuzz_oss=0
Mar 7, 2017
Mar 7, 2017
65
no_local_nspr=0
Jan 24, 2019
Jan 24, 2019
66
sslkeylogfile=1
Jan 5, 2017
Jan 5, 2017
67
68
69
gyp_params=(--depth="$cwd" --generator-output=".")
ninja_params=()
Nov 9, 2016
Nov 9, 2016
70
Oct 12, 2018
Oct 12, 2018
71
# Assume that the target architecture is the same as the host by default.
Jul 10, 2019
Jul 10, 2019
72
host_arch=$(python "$cwd/coreconf/detect_host_arch.py")
Oct 12, 2018
Oct 12, 2018
73
74
75
76
77
78
target_arch=$host_arch
# Assume that MSVC is wanted if this is running on windows.
platform=$(uname -s)
if [ "${platform%-*}" = "MINGW32_NT" -o "${platform%-*}" = "MINGW64_NT" ]; then
msvc=1
Oct 26, 2016
Oct 26, 2016
79
80
fi
Oct 12, 2018
Oct 12, 2018
81
# Parse command line arguments.
Jul 10, 2019
Jul 10, 2019
82
all_args=("$@")
Oct 21, 2016
Oct 21, 2016
83
while [ $# -gt 0 ]; do
Oct 12, 2018
Oct 12, 2018
84
case "$1" in
Jul 10, 2019
Jul 10, 2019
85
86
87
88
89
90
91
92
--rebuild)
if [[ ! -e "$argsfile" ]]; then
echo "Unable to rebuild" 1>&2
exit 2
fi
IFS=$'\r\n' GLOBIGNORE='*' command eval 'previous_args=($(<"$argsfile"))'
exec /usr/bin/env bash -c "$(Q "$0")"' "$@"' "$0" "${previous_args[@]}"
;;
Oct 26, 2016
Oct 26, 2016
93
-c) clean=1 ;;
Nov 8, 2017
Nov 8, 2017
94
-cc) clean_only=1 ;;
Sep 23, 2018
Sep 23, 2018
95
-v) ninja_params+=(-v); verbose=1 ;;
Oct 12, 2018
Oct 12, 2018
96
97
98
99
100
101
102
103
104
-j) ninja_params+=(-j "$2"); shift ;;
--gyp|-g) rebuild_gyp=1 ;;
--opt|-o) opt_build=1 ;;
-m32|--m32) target_arch=ia32; echo 'Warning: use -t instead of -m32' 1>&2 ;;
-t|--target) target_arch="$2"; shift ;;
--target=*) target_arch="${1#*=}" ;;
--clang) export CC=clang; export CCC=clang++; export CXX=clang++; msvc=0 ;;
--gcc) export CC=gcc; export CCC=g++; export CXX=g++; msvc=0 ;;
--msvc) msvc=1 ;;
Jan 10, 2017
Jan 10, 2017
105
106
--scan-build) enable_scanbuild ;;
--scan-build=?*) enable_scanbuild "${1#*=}" ;;
Oct 12, 2018
Oct 12, 2018
107
108
--disable-tests) gyp_params+=(-Ddisable_tests=1) ;;
--pprof) gyp_params+=(-Duse_pprof=1) ;;
Jan 10, 2017
Jan 10, 2017
109
110
111
112
--asan) enable_sanitizer asan ;;
--msan) enable_sanitizer msan ;;
--ubsan) enable_ubsan ;;
--ubsan=?*) enable_ubsan "${1#*=}" ;;
Oct 12, 2018
Oct 12, 2018
113
114
115
--fuzz) fuzz=1 ;;
--fuzz=oss) fuzz=1; fuzz_oss=1 ;;
--fuzz=tls) fuzz=1; fuzz_tls=1 ;;
Dec 4, 2019
Dec 4, 2019
116
117
--sancov) enable_sancov; gyp_params+=(-Dcoverage=1) ;;
--sancov=?*) enable_sancov "${1#*=}"; gyp_params+=(-Dcoverage=1) ;;
Jan 16, 2018
Jan 16, 2018
118
--emit-llvm) gyp_params+=(-Demit_llvm=1 -Dsign_libs=0) ;;
Jan 20, 2017
Jan 20, 2017
119
--no-zdefs) gyp_params+=(-Dno_zdefs=1) ;;
Apr 29, 2019
Apr 29, 2019
120
--static) gyp_params+=(-Dstatic_libs=1) ;;
Oct 12, 2018
Oct 12, 2018
121
122
--ct-verif) gyp_params+=(-Dct_verif=1) ;;
--nspr) nspr_clean; rebuild_nspr=1 ;;
Sep 12, 2019
Sep 12, 2019
123
124
125
--nspr-test-build) build_nspr_tests=1 ;;
--nspr-test-run) run_nspr_tests=1 ;;
--nspr-only) exit_after_nspr=1 ;;
Mar 7, 2017
Mar 7, 2017
126
127
--with-nspr=?*) set_nspr_path "${1#*=}"; no_local_nspr=1 ;;
--system-nspr) set_nspr_path "/usr/include/nspr/:"; no_local_nspr=1 ;;
Oct 12, 2018
Oct 12, 2018
128
--system-sqlite) gyp_params+=(-Duse_system_sqlite=1) ;;
Sep 23, 2018
Sep 23, 2018
129
--enable-fips) gyp_params+=(-Ddisable_fips=0) ;;
Oct 12, 2018
Oct 12, 2018
130
--enable-libpkix) gyp_params+=(-Ddisable_libpkix=0) ;;
Aug 3, 2018
Aug 3, 2018
131
--mozpkix-only) gyp_params+=(-Dmozpkix_only=1 -Ddisable_tests=1 -Dsign_libs=0) ;;
Jan 24, 2019
Jan 24, 2019
132
--disable-keylog) sslkeylogfile=0 ;;
Dec 4, 2019
Dec 4, 2019
133
--enable-legacy-db) gyp_params+=(-Ddisable_dbm=0) ;;
Jul 10, 2019
Jul 10, 2019
134
-D*) gyp_params+=("$1") ;;
Jan 10, 2017
Jan 10, 2017
135
*) show_help; exit 2 ;;
Oct 21, 2016
Oct 21, 2016
136
137
138
139
esac
shift
done
Oct 12, 2018
Oct 12, 2018
140
141
# Set the target architecture and build type.
gyp_params+=(-Dtarget_arch="$target_arch")
Jan 5, 2017
Jan 5, 2017
142
if [ "$opt_build" = 1 ]; then
Oct 26, 2016
Oct 26, 2016
143
target=Release
Oct 17, 2016
Oct 17, 2016
144
else
Oct 26, 2016
Oct 26, 2016
145
target=Debug
Oct 17, 2016
Oct 17, 2016
146
fi
Oct 12, 2018
Oct 12, 2018
147
Jan 24, 2019
Jan 24, 2019
148
149
gyp_params+=(-Denable_sslkeylogfile="$sslkeylogfile")
Oct 12, 2018
Oct 12, 2018
150
# Do special setup.
Jan 5, 2017
Jan 5, 2017
151
if [ "$fuzz" = 1 ]; then
Jul 10, 2019
Jul 10, 2019
152
source "$cwd/coreconf/fuzz.sh"
Nov 18, 2016
Nov 18, 2016
153
fi
Oct 12, 2018
Oct 12, 2018
154
155
156
157
nspr_set_flags $sanitizer_flags
if [ ! -z "$sanitizer_flags" ]; then
gyp_params+=(-Dsanitizer_flags="$sanitizer_flags")
fi
Nov 18, 2016
Nov 18, 2016
158
Oct 12, 2018
Oct 12, 2018
159
if [ "$msvc" = 1 ]; then
Jul 10, 2019
Jul 10, 2019
160
source "$cwd/coreconf/msvc.sh"
Oct 12, 2018
Oct 12, 2018
161
162
fi
Jan 10, 2017
Jan 10, 2017
163
# -c = clean first
Nov 8, 2017
Nov 8, 2017
164
if [ "$clean" = 1 -o "$clean_only" = 1 ]; then
Jan 10, 2017
Jan 10, 2017
165
nspr_clean
Jul 10, 2019
Jul 10, 2019
166
rm -rf "$cwd/out"
Jan 10, 2017
Jan 10, 2017
167
rm -rf "$dist_dir"
Nov 8, 2017
Nov 8, 2017
168
169
170
171
172
# -cc = only clean, don't build
if [ "$clean_only" = 1 ]; then
echo "Cleaned"
exit 0
fi
Jan 5, 2017
Jan 5, 2017
173
174
fi
Jul 10, 2019
Jul 10, 2019
175
176
177
178
179
180
# Setup build paths.
target_dir="$cwd/out/$target"
mkdir -p "$target_dir"
dist_dir=$(mkdir -p "$dist_dir"; cd "$dist_dir"; pwd -P)
gyp_params+=(-Dnss_dist_dir="$dist_dir")
Jan 5, 2017
Jan 5, 2017
181
182
# This saves a canonical representation of arguments that we are passing to gyp
# or the NSPR build so that we can work out if a rebuild is needed.
Jan 10, 2017
Jan 10, 2017
183
184
185
# Caveat: This can fail for arguments that are position-dependent.
# e.g., "-e 2 -f 1" and "-e 1 -f 2" canonicalize the same.
check_config()
Jan 5, 2017
Jan 5, 2017
186
{
Jan 10, 2017
Jan 10, 2017
187
local newconf="$1".new oldconf="$1"
Jan 5, 2017
Jan 5, 2017
188
shift
Jan 10, 2017
Jan 10, 2017
189
mkdir -p $(dirname "$newconf")
Jul 10, 2019
Jul 10, 2019
190
191
192
193
194
echo CC="$(Q "$CC")" >"$newconf"
echo CCC="$(Q "$CCC")" >>"$newconf"
echo CXX="$(Q "$CXX")" >>"$newconf"
echo target_arch="$(Q "$target_arch")" >>"$newconf"
for i in "$@"; do echo "$i"; done | sort >>"$newconf"
Jan 10, 2017
Jan 10, 2017
195
196
197
198
# Note: The following diff fails if $oldconf isn't there as well, which
# happens if we don't have a previous successful build.
! diff -q "$newconf" "$oldconf" >/dev/null 2>&1
Jan 5, 2017
Jan 5, 2017
199
200
}
Jul 10, 2019
Jul 10, 2019
201
202
gyp_config="$cwd/out/gyp_config"
nspr_config="$cwd/out/$target/nspr_config"
Jan 10, 2017
Jan 10, 2017
203
Oct 12, 2018
Oct 12, 2018
204
# Now check what needs to be rebuilt.
Jan 5, 2017
Jan 5, 2017
205
206
207
208
# If we don't have a build directory make sure that we rebuild.
if [ ! -d "$target_dir" ]; then
rebuild_nspr=1
rebuild_gyp=1
Jul 10, 2019
Jul 10, 2019
209
elif [ ! -d "$dist_dir/$target" ]; then
Jan 10, 2017
Jan 10, 2017
210
rebuild_nspr=1
Jan 5, 2017
Jan 5, 2017
211
212
fi
Oct 12, 2018
Oct 12, 2018
213
if check_config "$nspr_config" \
Jul 10, 2019
Jul 10, 2019
214
215
216
nspr_cflags="$(Q "$nspr_cflags")" \
nspr_cxxflags="$(Q "$nspr_cxxflags")" \
nspr_ldflags="$(Q "$nspr_ldflags")"; then
Jan 10, 2017
Jan 10, 2017
217
218
219
rebuild_nspr=1
fi
Jul 10, 2019
Jul 10, 2019
220
if check_config "$gyp_config" "$(Q "${gyp_params[@]}")"; then
Jan 5, 2017
Jan 5, 2017
221
222
223
rebuild_gyp=1
fi
Oct 12, 2018
Oct 12, 2018
224
# Save the chosen target.
Jul 10, 2019
Jul 10, 2019
225
226
echo "$target" > "$dist_dir/latest"
for i in "${all_args[@]}"; do echo "$i"; done > "$argsfile"
Jan 5, 2017
Jan 5, 2017
227
Oct 12, 2018
Oct 12, 2018
228
229
# Build.
# NSPR.
Mar 7, 2017
Mar 7, 2017
230
if [[ "$rebuild_nspr" = 1 && "$no_local_nspr" = 0 ]]; then
Jul 10, 2019
Jul 10, 2019
231
nspr_clean
Oct 12, 2018
Oct 12, 2018
232
nspr_build
Jul 10, 2019
Jul 10, 2019
233
mv -f "$nspr_config.new" "$nspr_config"
Jan 5, 2017
Jan 5, 2017
234
fi
Sep 12, 2019
Sep 12, 2019
235
236
237
238
239
if [ "$exit_after_nspr" = 1 ]; then
exit 0
fi
Oct 12, 2018
Oct 12, 2018
240
# gyp.
Jan 5, 2017
Jan 5, 2017
241
if [ "$rebuild_gyp" = 1 ]; then
Jul 10, 2019
Jul 10, 2019
242
243
244
if ! hash "$GYP" 2> /dev/null; then
echo "Building NSS requires an installation of gyp: https://gyp.gsrc.io/" 1>&2
exit 3
May 8, 2017
May 8, 2017
245
fi
Jan 5, 2017
Jan 5, 2017
246
# These extra arguments aren't used in determining whether to rebuild.
Jul 10, 2019
Jul 10, 2019
247
248
obj_dir="$dist_dir/$target"
gyp_params+=(-Dnss_dist_obj_dir="$obj_dir")
Mar 7, 2017
Mar 7, 2017
249
250
251
if [ "$no_local_nspr" = 0 ]; then
set_nspr_path "$obj_dir/include/nspr:$obj_dir/lib"
fi
Oct 17, 2016
Oct 17, 2016
252
Jul 10, 2019
Jul 10, 2019
253
run_verbose run_scanbuild ${GYP} -f ninja "${gyp_params[@]}" "$cwd/nss.gyp"
Nov 7, 2016
Nov 7, 2016
254
Jul 10, 2019
Jul 10, 2019
255
mv -f "$gyp_config.new" "$gyp_config"
Oct 17, 2016
Oct 17, 2016
257
Oct 12, 2018
Oct 12, 2018
258
259
# ninja.
if hash ninja-build 2>/dev/null; then
Sep 23, 2018
Sep 23, 2018
260
ninja=ninja-build
Oct 12, 2018
Oct 12, 2018
261
262
elif hash ninja 2>/dev/null; then
ninja=ninja
Oct 17, 2016
Oct 17, 2016
263
else
Jul 10, 2019
Jul 10, 2019
264
265
echo "Building NSS requires an installation of ninja: https://ninja-build.org/" 1>&2
exit 3
Jul 10, 2019
Jul 10, 2019
267
run_scanbuild "$ninja" -C "$target_dir" "${ninja_params[@]}"