Commit | Line | Data |
---|---|---|
51c9c62d | 1 | #!/bin/bash |
890bff23 | 2 | # |
9d56171a | 3 | # Copyright (C) 2015 Jonathan Rajotte-Julien <jonathan.rajotte-julien@efficios.com> |
51c9c62d | 4 | # Copyright (C) 2016-2020 Michael Jeanson <mjeanson@efficios.com> |
890bff23 MJ |
5 | # |
6 | # This program is free software: you can redistribute it and/or modify | |
7 | # it under the terms of the GNU General Public License as published by | |
8 | # the Free Software Foundation, either version 3 of the License, or | |
9 | # (at your option) any later version. | |
10 | # | |
11 | # This program is distributed in the hope that it will be useful, | |
12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | # GNU General Public License for more details. | |
15 | # | |
16 | # You should have received a copy of the GNU General Public License | |
17 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
18 | ||
51c9c62d MJ |
19 | set -exu |
20 | ||
a0b535b2 MJ |
21 | # Version compare functions |
22 | vercomp () { | |
23 | set +u | |
24 | if [[ "$1" == "$2" ]]; then | |
25 | return 0 | |
26 | fi | |
27 | local IFS=. | |
6946ebc0 SM |
28 | # Ignore the shellcheck warning, we want splitting to happen based on IFS. |
29 | # shellcheck disable=SC2206 | |
a0b535b2 MJ |
30 | local i ver1=($1) ver2=($2) |
31 | # fill empty fields in ver1 with zeros | |
32 | for ((i=${#ver1[@]}; i<${#ver2[@]}; i++)); do | |
33 | ver1[i]=0 | |
34 | done | |
35 | for ((i=0; i<${#ver1[@]}; i++)); do | |
36 | if [[ -z ${ver2[i]} ]]; then | |
37 | # fill empty fields in ver2 with zeros | |
38 | ver2[i]=0 | |
39 | fi | |
40 | if ((10#${ver1[i]} > 10#${ver2[i]})); then | |
41 | return 1 | |
42 | fi | |
43 | if ((10#${ver1[i]} < 10#${ver2[i]})); then | |
44 | return 2 | |
45 | fi | |
46 | done | |
47 | set -u | |
48 | return 0 | |
49 | } | |
50 | ||
6946ebc0 SM |
51 | # Shellcheck flags the following functions that are unused as "unreachable", |
52 | # ignore that. | |
53 | ||
54 | # shellcheck disable=SC2317 | |
a0b535b2 | 55 | verlte() { |
6946ebc0 SM |
56 | vercomp "$1" "$2" |
57 | local res="$?" | |
a0b535b2 MJ |
58 | [ "$res" -eq "0" ] || [ "$res" -eq "2" ] |
59 | } | |
60 | ||
6946ebc0 | 61 | # shellcheck disable=SC2317 |
a0b535b2 MJ |
62 | verlt() { |
63 | vercomp "$1" "$2"; local res="$?" | |
64 | [ "$res" -eq "2" ] | |
65 | } | |
66 | ||
6946ebc0 | 67 | # shellcheck disable=SC2317 |
a0b535b2 MJ |
68 | vergte() { |
69 | vercomp "$1" "$2"; local res="$?" | |
70 | [ "$res" -eq "0" ] || [ "$res" -eq "1" ] | |
71 | } | |
72 | ||
6946ebc0 | 73 | # shellcheck disable=SC2317 |
a0b535b2 MJ |
74 | vergt() { |
75 | vercomp "$1" "$2"; local res="$?" | |
76 | [ "$res" -eq "1" ] | |
77 | } | |
78 | ||
6946ebc0 | 79 | # shellcheck disable=SC2317 |
a0b535b2 MJ |
80 | verne() { |
81 | vercomp "$1" "$2"; local res="$?" | |
82 | [ "$res" -ne "0" ] | |
83 | } | |
84 | ||
51c9c62d MJ |
85 | failed_configure() { |
86 | # Assume we are in the configured build directory | |
87 | echo "#################### BEGIN config.log ####################" | |
88 | cat config.log | |
89 | echo "#################### END config.log ####################" | |
90 | exit 1 | |
91 | } | |
92 | ||
93 | ||
07dafe32 MJ |
94 | # Required variables |
95 | WORKSPACE=${WORKSPACE:-} | |
96 | ||
776b0d3d | 97 | platform=${platform:-} |
a57a60d9 MJ |
98 | conf=${conf:-} |
99 | build=${build:-} | |
6476f917 | 100 | cc=${cc:-} |
a57a60d9 | 101 | |
e3c32202 JR |
102 | # Controls if the tests are run |
103 | BABELTRACE_RUN_TESTS="${BABELTRACE_RUN_TESTS:=yes}" | |
c56b9301 | 104 | |
e6be9fb0 MJ |
105 | SRCDIR="$WORKSPACE/src/babeltrace" |
106 | TMPDIR="$WORKSPACE/tmp" | |
07dafe32 | 107 | PREFIX="/build" |
4afa623f MJ |
108 | LIBDIR="lib" |
109 | ||
110 | # RHEL and SLES both use lib64 but don't bother shipping a default autoconf | |
111 | # site config that matches this. | |
112 | if [[ ( -f /etc/redhat-release || -f /etc/SuSE-release ) && ( "$(uname -m)" == "x86_64" ) ]]; then | |
113 | LIBDIR_ARCH="${LIBDIR}64" | |
114 | else | |
115 | LIBDIR_ARCH="$LIBDIR" | |
116 | fi | |
275b59d2 | 117 | |
07dafe32 MJ |
118 | # Create tmp directory |
119 | rm -rf "$TMPDIR" | |
120 | mkdir -p "$TMPDIR" | |
e6be9fb0 | 121 | |
0e9967db | 122 | export TMPDIR |
72d087d4 | 123 | export CFLAGS="-g -O2" |
0e9967db | 124 | |
6476f917 MJ |
125 | # Set compiler variables |
126 | case "$cc" in | |
127 | gcc) | |
128 | export CC=gcc | |
129 | export CXX=g++ | |
130 | ;; | |
0f505d21 MJ |
131 | gcc-*) |
132 | export CC=gcc-${cc#gcc-} | |
133 | export CXX=g++-${cc#gcc-} | |
6476f917 MJ |
134 | ;; |
135 | clang) | |
136 | export CC=clang | |
137 | export CXX=clang++ | |
138 | ;; | |
0f505d21 MJ |
139 | clang-*) |
140 | export CC=clang-${cc#clang-} | |
141 | export CXX=clang++-${cc#clang-} | |
6476f917 MJ |
142 | ;; |
143 | *) | |
144 | if [ "x$cc" != "x" ]; then | |
145 | export CC="$cc" | |
146 | fi | |
147 | ;; | |
148 | esac | |
149 | ||
1183a118 | 150 | if [ "x${CC:-}" != "x" ]; then |
6476f917 MJ |
151 | echo "Selected compiler:" |
152 | "$CC" -v | |
153 | fi | |
154 | ||
c56b9301 | 155 | # Set platform variables |
776b0d3d | 156 | case "$platform" in |
f0d7e5b1 | 157 | macos*) |
a0b535b2 MJ |
158 | export MAKE=make |
159 | export TAR=tar | |
160 | export NPROC="getconf _NPROCESSORS_ONLN" | |
221450b6 | 161 | export PATH="/opt/local/bin:/opt/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin" |
07dafe32 | 162 | export CPPFLAGS="-I/opt/local/include" |
221450b6 | 163 | export LDFLAGS="-L/opt/local/lib" |
00f7bb3f MJ |
164 | export PYTHON="python3" |
165 | export PYTHON_CONFIG="python3-config" | |
221450b6 | 166 | ;; |
07dafe32 | 167 | |
0f505d21 | 168 | freebsd*) |
894db5f1 MJ |
169 | export MAKE=gmake |
170 | export TAR=tar | |
171 | export NPROC="getconf _NPROCESSORS_ONLN" | |
172 | export CPPFLAGS="-I/usr/local/include" | |
173 | export LDFLAGS="-L/usr/local/lib" | |
174 | export PYTHON="python3" | |
175 | export PYTHON_CONFIG="python3-config" | |
176 | ||
177 | # For bt 1.5 | |
178 | export YACC="bison -y" | |
179 | ;; | |
180 | ||
87e41bca | 181 | *) |
a0b535b2 MJ |
182 | export MAKE=make |
183 | export TAR=tar | |
184 | export NPROC=nproc | |
1f620ba0 MJ |
185 | export PYTHON="python3" |
186 | export PYTHON_CONFIG="python3-config" | |
87e41bca MJ |
187 | ;; |
188 | esac | |
189 | ||
51c9c62d MJ |
190 | # Print build env details |
191 | print_os || true | |
192 | print_tooling || true | |
193 | ||
a0b535b2 MJ |
194 | # Enter the source directory |
195 | cd "$SRCDIR" | |
196 | ||
197 | # Run bootstrap in the source directory prior to configure | |
198 | ./bootstrap | |
199 | ||
200 | # Get source version from configure script | |
201 | eval "$(grep '^PACKAGE_VERSION=' ./configure)" | |
07dafe32 | 202 | PACKAGE_VERSION=${PACKAGE_VERSION//\-pre*/} |
a0b535b2 | 203 | |
11ba7264 | 204 | # Enable dev mode by default for BT 2.0 builds |
9201e00d MJ |
205 | export BABELTRACE_DEBUG_MODE=1 |
206 | export BABELTRACE_DEV_MODE=1 | |
8130d845 | 207 | export BABELTRACE_MINIMAL_LOG_LEVEL=TRACE |
11ba7264 | 208 | |
07dafe32 MJ |
209 | # Set configure options and environment variables for each build |
210 | # configuration. | |
4afa623f | 211 | CONF_OPTS=("--prefix=$PREFIX" "--libdir=$PREFIX/$LIBDIR_ARCH") |
f0d7e5b1 MJ |
212 | |
213 | # -Werror is enabled by default in stable-2.0 but won't be in 2.1 | |
214 | # Explicitly disable it for consistency. | |
215 | if vergte "$PACKAGE_VERSION" "2.0"; then | |
216 | CONF_OPTS+=("--disable-Werror") | |
217 | fi | |
218 | ||
275b59d2 JRJ |
219 | case "$conf" in |
220 | static) | |
1f620ba0 MJ |
221 | echo "Static lib only configuration" |
222 | ||
223 | CONF_OPTS+=("--enable-static" "--disable-shared") | |
224 | ||
a0b535b2 | 225 | if vergte "$PACKAGE_VERSION" "2.0"; then |
1f620ba0 | 226 | CONF_OPTS+=("--enable-built-in-plugins") |
a0b535b2 | 227 | fi |
275b59d2 | 228 | ;; |
1f620ba0 | 229 | |
221450b6 | 230 | python-bindings) |
1f620ba0 MJ |
231 | echo "Python bindings configuration" |
232 | ||
233 | CONF_OPTS+=("--enable-python-bindings") | |
a0b535b2 MJ |
234 | |
235 | if vergte "$PACKAGE_VERSION" "2.0"; then | |
1f620ba0 | 236 | CONF_OPTS+=("--enable-python-bindings-doc" "--enable-python-plugins") |
a0b535b2 | 237 | fi |
275b59d2 | 238 | ;; |
1f620ba0 | 239 | |
0d30552d | 240 | prod) |
1f620ba0 | 241 | echo "Production configuration" |
9201e00d MJ |
242 | |
243 | # Unset the developper variables | |
244 | unset BABELTRACE_DEBUG_MODE | |
245 | unset BABELTRACE_DEV_MODE | |
246 | unset BABELTRACE_MINIMAL_LOG_LEVEL | |
247 | ||
248 | # Enable the python bindings | |
301b8fc9 MJ |
249 | CONF_OPTS+=("--enable-python-bindings" "--enable-python-plugins") |
250 | ;; | |
251 | ||
252 | doc) | |
253 | echo "Documentation configuration" | |
254 | ||
255 | CONF_OPTS+=("--enable-python-bindings" "--enable-python-bindings-doc" "--enable-python-plugins" "--enable-api-doc") | |
9201e00d | 256 | ;; |
1f620ba0 | 257 | |
1b232bc6 SM |
258 | asan) |
259 | echo "Address Sanitizer configuration" | |
260 | ||
261 | # --enable-asan was introduced after 2.0 but don't check the version, we | |
262 | # want this configuration to fail if ASAN is unavailable. | |
263 | CONF_OPTS+=("--enable-asan" "--enable-python-bindings" "--enable-python-plugins") | |
264 | ;; | |
265 | ||
0d30552d | 266 | min) |
1f620ba0 | 267 | echo "Minimal configuration" |
0d30552d | 268 | ;; |
1f620ba0 | 269 | |
275b59d2 | 270 | *) |
1f620ba0 | 271 | echo "Standard configuration" |
0d30552d | 272 | |
1f620ba0 | 273 | # Enable the python bindings / plugins by default with babeltrace2, |
0d30552d MJ |
274 | # the test suite is mostly useless without it. |
275 | if vergte "$PACKAGE_VERSION" "2.0"; then | |
1f620ba0 | 276 | CONF_OPTS+=("--enable-python-bindings" "--enable-python-plugins") |
0d30552d | 277 | fi |
275b59d2 JRJ |
278 | ;; |
279 | esac | |
280 | ||
aad6ac90 | 281 | # Build type |
07dafe32 MJ |
282 | # oot : out-of-tree build |
283 | # dist : build via make dist | |
284 | # oot-dist: build via make dist out-of-tree | |
285 | # * : normal tree build | |
aad6ac90 | 286 | # |
07dafe32 | 287 | # Make sure to move to the build directory and run configure |
1f620ba0 | 288 | # before continuing. |
aad6ac90 | 289 | case "$build" in |
b8475d72 MJ |
290 | oot) |
291 | echo "Out of tree build" | |
292 | ||
293 | # Create and enter a temporary build directory | |
294 | builddir=$(mktemp -d) | |
295 | cd "$builddir" | |
296 | ||
51c9c62d | 297 | "$SRCDIR/configure" "${CONF_OPTS[@]}" || failed_configure |
b8475d72 | 298 | ;; |
1f620ba0 | 299 | |
b8475d72 MJ |
300 | dist) |
301 | echo "Distribution in-tree build" | |
1f620ba0 | 302 | |
b8475d72 MJ |
303 | # Run configure and generate the tar file |
304 | # in the source directory | |
51c9c62d | 305 | ./configure || failed_configure |
b8475d72 | 306 | $MAKE dist |
c56b9301 | 307 | |
b8475d72 MJ |
308 | # Create and enter a temporary build directory |
309 | builddir=$(mktemp -d) | |
310 | cd "$builddir" | |
311 | ||
312 | # Extract the distribution tar in the build directory, | |
313 | # ignore the first directory level | |
314 | $TAR xvf "$SRCDIR"/*.tar.* --strip 1 | |
315 | ||
07dafe32 | 316 | # Build in extracted source tree |
51c9c62d | 317 | ./configure "${CONF_OPTS[@]}" || failed_configure |
b8475d72 | 318 | ;; |
c56b9301 | 319 | |
b8475d72 MJ |
320 | oot-dist) |
321 | echo "Distribution out of tree build" | |
c56b9301 | 322 | |
b8475d72 MJ |
323 | # Create and enter a temporary build directory |
324 | builddir=$(mktemp -d) | |
325 | cd "$builddir" | |
c56b9301 | 326 | |
b8475d72 | 327 | # Run configure out of tree and generate the tar file |
51c9c62d | 328 | "$SRCDIR/configure" || failed_configure |
b8475d72 | 329 | $MAKE dist |
c56b9301 | 330 | |
b8475d72 MJ |
331 | dist_srcdir="$(mktemp -d)" |
332 | cd "$dist_srcdir" | |
c56b9301 | 333 | |
b8475d72 MJ |
334 | # Extract the distribution tar in the new source directory, |
335 | # ignore the first directory level | |
336 | $TAR xvf "$builddir"/*.tar.* --strip 1 | |
337 | ||
338 | # Create and enter a second temporary build directory | |
339 | builddir="$(mktemp -d)" | |
340 | cd "$builddir" | |
341 | ||
342 | # Run configure from the extracted distribution tar, | |
343 | # out of the source tree | |
51c9c62d | 344 | "$dist_srcdir/configure" "${CONF_OPTS[@]}" || failed_configure |
b8475d72 MJ |
345 | ;; |
346 | ||
347 | *) | |
348 | echo "Standard in-tree build" | |
51c9c62d | 349 | ./configure "${CONF_OPTS[@]}" || failed_configure |
b8475d72 | 350 | ;; |
aad6ac90 JR |
351 | esac |
352 | ||
1f620ba0 MJ |
353 | # We are now inside a configured build directory |
354 | ||
c56b9301 | 355 | # BUILD! |
a57a60d9 | 356 | $MAKE -j "$($NPROC)" V=1 |
07dafe32 MJ |
357 | |
358 | # Install in the workspace | |
359 | $MAKE install DESTDIR="$WORKSPACE" | |
c56b9301 | 360 | |
9d56171a | 361 | # Run tests, don't fail now, we want to run the archiving steps |
1d56e325 | 362 | failed_tests=0 |
e3c32202 JR |
363 | if [ "$BABELTRACE_RUN_TESTS" = "yes" ]; then |
364 | $MAKE --keep-going check || failed_tests=1 | |
365 | ||
366 | # Copy tap logs for the jenkins tap parser before cleaning the build dir | |
367 | rsync -a --exclude 'test-suite.log' --include '*/' --include '*.log' --exclude='*' tests/ "$WORKSPACE/tap" | |
368 | ||
369 | # The test suite prior to 1.5 did not produce TAP logs | |
370 | if verlt "$PACKAGE_VERSION" "1.5"; then | |
371 | mkdir -p "$WORKSPACE/tap/no-log" | |
372 | echo "1..1" > "$WORKSPACE/tap/no-log/tests.log" | |
373 | echo "ok 1 - Test suite doesn't support logging" >> "$WORKSPACE/tap/no-log/tests.log" | |
374 | fi | |
649c39a6 MJ |
375 | fi |
376 | ||
e6be9fb0 MJ |
377 | # Clean the build directory |
378 | $MAKE clean | |
275b59d2 | 379 | |
c56b9301 | 380 | # Cleanup rpath in executables and shared libraries |
07dafe32 | 381 | find "$WORKSPACE/$PREFIX/bin" -type f -perm -0500 -exec chrpath --delete {} \; |
4afa623f | 382 | find "$WORKSPACE/$PREFIX/$LIBDIR_ARCH" -name "*.so" -exec chrpath --delete {} \; |
c56b9301 MJ |
383 | |
384 | # Remove libtool .la files | |
4afa623f | 385 | find "$WORKSPACE/$PREFIX/$LIBDIR_ARCH" -name "*.la" -exec rm -f {} \; |
87e41bca | 386 | |
1d56e325 MJ |
387 | # Exit with failure if any of the tests failed |
388 | exit $failed_tests | |
9d56171a | 389 | |
87e41bca | 390 | # EOF |