-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathbuild
executable file
·207 lines (188 loc) · 4.26 KB
/
build
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
#! /usr/bin/env bash
################################################################################
panic()
{
echo "ERROR: $*"
exit 1
}
get_clang_version()
{
local program="${1:-clang++}"
"$program" --version | awk '
(NR==1){
for (i = 1; i <= NF; ++i) {
if (tolower($i) == "version") {
++i;
print $i;
break;
}
}
}
'
}
################################################################################
self_program="$(realpath "$0")" || \
panic "realpath failed"
self_dir="$(dirname "$self_program")" || \
panic "dirname failed"
top_dir="$self_dir/../.."
setup_file=
verbose=0
matrix_os=
while getopts vs:c: option; do
case "$option" in
c)
setup_file="$OPTARG";;
v)
verbose=$((verbose + 1));;
s)
matrix_os="$OPTARG";;
*)
usage "invalid option $option"
break
;;
esac
done
shift $((OPTIND - 1))
if [ -n "$setup_file" ]; then
cat <<- EOF
============================================================
Sourcing setup file
setup file contents:
============================================================
$(cat "$setup_file")
============================================================
EOF
source "$setup_file" || \
panic "cannot source setup file $setup_file"
fi
build_options=()
build_options+=(--num-jobs 4)
# Determine whether to run demo scripts.
case "$matrix_os" in
#ubuntu-22.04|macos-12)
#ubuntu-22.04)
#ubuntu-*)
*)
build_options+=(--demo)
;;
esac
# Determine whether to use the hacked fmt library.
case "$matrix_os" in
macos-*|ubuntu-*)
build_options+=(--fmt)
;;
esac
# Determine some sanitizer settings.
build_options+=(--no-asan-detect-leaks)
build_options+=(--asan-allow-user-poisoning)
build_options+=(--ubsan-halt-on-error)
case "$matrix_os" in
ubuntu-*)
case "$matrix_os" in
ubuntu-22.04)
;;
ubuntu-20.04)
;;
esac
;;
macos-*)
build_options+=(--no-asan-allow-user-poisoning)
build_options+=(--no-ubsan-halt-on-error)
case "$matrix_os" in
macos-12)
;;
esac
;;
esac
if [ "$verbose" -ge 1 ]; then
cat <<- EOF
============================================================
CC: $CC
============================================================
CXX: $CXX
============================================================
PATH: $PATH
============================================================
LD_LIBRARY_PATH: $LD_LIBRARY_PATH
============================================================
CMAKE_PREFIX_PATH: $CMAKE_PREFIX_PATH
============================================================
CPLUS_INCLUDE_PATH: $CPLUS_INCLUDE_PATH
C_INCLUDE_PATH: $C_INCLUDE_PATH
CPATH: $CPATH
============================================================
clang++ path: $(type -P clang++)
clang++ version: $(get_clang_version clang++)
----------
$(clang++ --version)
----------
clang path: $(type -P clang)
clang version: $(get_clang_version clang)
----------
$(clang --version)
----------
============================================================
g++ path: $(type -P g++)
g++ version:
----------
$(g++ --version)
----------
gcc path: $(type -P gcc)
gcc version:
----------
$(gcc --version)
----------
============================================================
Clang default version of C++ standard:
$(clang++ -dM -E -x c++ /dev/null | grep -F __cplusplus)
============================================================
GCC default version of C++ standard:
$(g++ -dM -E -x c++ /dev/null | grep -F __cplusplus)
============================================================
python path: $(type -P python)
python2 path: $(type -P python2)
python3 path: $(type -P python3)
============================================================
EOF
fi
case "$COMPILER_CXX" in
clang++)
compiler=clang;;
g++)
compiler=gcc;;
*)
panic "unknown compiler";;
esac
environ=()
case "$compiler" in
gcc)
environ+=("CC=$GCC_CC_PATH")
environ+=("CXX=$GCC_CXX_PATH")
;;
clang)
environ+=("CC=$CLANG_CC_PATH")
environ+=("CXX=$CLANG_CXX_PATH")
;;
esac
command=(
env "${environ[@]}"
"$top_dir/build"
--verbose
--clean
--build
--verbose-makefile
--no-fmt
--debug
--asan
--ubsan
"${build_options[@]}"
)
if [ "$verbose" -ge 1 ]; then
cat <<- EOF
============================================================
RUNNING: ${command[*]}
============================================================
EOF
fi
"${command[@]}" || panic "build failed"