jjb: librseq: update for ubuntu 22.04 builders
[lttng-ci.git] / scripts / babeltrace / build.sh
CommitLineData
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
19set -exu
20
a0b535b2
MJ
21# Version compare functions
22vercomp () {
23 set +u
24 if [[ "$1" == "$2" ]]; then
25 return 0
26 fi
27 local IFS=.
28 local i ver1=($1) ver2=($2)
29 # fill empty fields in ver1 with zeros
30 for ((i=${#ver1[@]}; i<${#ver2[@]}; i++)); do
31 ver1[i]=0
32 done
33 for ((i=0; i<${#ver1[@]}; i++)); do
34 if [[ -z ${ver2[i]} ]]; then
35 # fill empty fields in ver2 with zeros
36 ver2[i]=0
37 fi
38 if ((10#${ver1[i]} > 10#${ver2[i]})); then
39 return 1
40 fi
41 if ((10#${ver1[i]} < 10#${ver2[i]})); then
42 return 2
43 fi
44 done
45 set -u
46 return 0
47}
48
49verlte() {
50 vercomp "$1" "$2"; local res="$?"
51 [ "$res" -eq "0" ] || [ "$res" -eq "2" ]
52}
53
54verlt() {
55 vercomp "$1" "$2"; local res="$?"
56 [ "$res" -eq "2" ]
57}
58
59vergte() {
60 vercomp "$1" "$2"; local res="$?"
61 [ "$res" -eq "0" ] || [ "$res" -eq "1" ]
62}
63
64vergt() {
65 vercomp "$1" "$2"; local res="$?"
66 [ "$res" -eq "1" ]
67}
68
69verne() {
70 vercomp "$1" "$2"; local res="$?"
71 [ "$res" -ne "0" ]
72}
73
51c9c62d
MJ
74failed_configure() {
75 # Assume we are in the configured build directory
76 echo "#################### BEGIN config.log ####################"
77 cat config.log
78 echo "#################### END config.log ####################"
79 exit 1
80}
81
82
07dafe32
MJ
83# Required variables
84WORKSPACE=${WORKSPACE:-}
85
a57a60d9
MJ
86arch=${arch:-}
87conf=${conf:-}
88build=${build:-}
6476f917 89cc=${cc:-}
a57a60d9 90
e3c32202
JR
91# Controls if the tests are run
92BABELTRACE_RUN_TESTS="${BABELTRACE_RUN_TESTS:=yes}"
c56b9301 93
e6be9fb0
MJ
94SRCDIR="$WORKSPACE/src/babeltrace"
95TMPDIR="$WORKSPACE/tmp"
07dafe32 96PREFIX="/build"
275b59d2 97
07dafe32
MJ
98# Create tmp directory
99rm -rf "$TMPDIR"
100mkdir -p "$TMPDIR"
e6be9fb0 101
0e9967db 102export TMPDIR
72d087d4 103export CFLAGS="-g -O2"
0e9967db 104
6476f917
MJ
105# Set compiler variables
106case "$cc" in
107gcc)
108 export CC=gcc
109 export CXX=g++
110 ;;
111gcc-4.8)
112 export CC=gcc-4.8
113 export CXX=g++-4.8
114 ;;
115gcc-5)
116 export CC=gcc-5
117 export CXX=g++-5
118 ;;
119gcc-6)
120 export CC=gcc-6
121 export CXX=g++-6
122 ;;
123gcc-7)
124 export CC=gcc-7
125 export CXX=g++-7
126 ;;
127gcc-8)
128 export CC=gcc-8
129 export CXX=g++-8
130 ;;
131clang)
132 export CC=clang
133 export CXX=clang++
134 ;;
135clang-3.9)
136 export CC=clang-3.9
137 export CXX=clang++-3.9
138 ;;
139clang-4.0)
140 export CC=clang-4.0
141 export CXX=clang++-4.0
142 ;;
143clang-5.0)
144 export CC=clang-5.0
145 export CXX=clang++-5.0
146 ;;
147clang-6.0)
148 export CC=clang-6.0
149 export CXX=clang++-6.0
150 ;;
151clang-7)
152 export CC=clang-7
153 export CXX=clang++-7
154 ;;
155*)
156 if [ "x$cc" != "x" ]; then
157 export CC="$cc"
158 fi
159 ;;
160esac
161
1183a118 162if [ "x${CC:-}" != "x" ]; then
6476f917
MJ
163 echo "Selected compiler:"
164 "$CC" -v
165fi
166
c56b9301 167# Set platform variables
87e41bca 168case "$arch" in
a0b535b2
MJ
169sol10-i386)
170 export MAKE=gmake
171 export TAR=gtar
172 export NPROC=gnproc
ad11244c 173 export PATH="/opt/csw/bin:/usr/ccs/bin:$PATH"
a0b535b2
MJ
174 export CPPFLAGS="-I/opt/csw/include"
175 export LDFLAGS="-L/opt/csw/lib -R/opt/csw/lib"
176 export PKG_CONFIG_PATH="/opt/csw/lib/pkgconfig"
1f620ba0
MJ
177 export PYTHON="python3"
178 export PYTHON_CONFIG="python3-config"
87e41bca 179 ;;
07dafe32 180
a0b535b2
MJ
181sol11-i386)
182 export MAKE=gmake
183 export TAR=gtar
184 export NPROC=nproc
f2cd0939 185 export PATH="/opt/csw/bin:$PATH:/usr/perl5/bin"
cd808c9e
MJ
186 export LD_ALTEXEC=/usr/bin/gld
187 export LD=/usr/bin/gld
1f620ba0
MJ
188 export PYTHON="python3"
189 export PYTHON_CONFIG="python3-config"
f2cd0939 190 export PKG_CONFIG_PATH="/usr/lib/pkgconfig"
87e41bca 191 ;;
07dafe32 192
f0d7e5b1 193macos*)
a0b535b2
MJ
194 export MAKE=make
195 export TAR=tar
196 export NPROC="getconf _NPROCESSORS_ONLN"
221450b6 197 export PATH="/opt/local/bin:/opt/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"
07dafe32 198 export CPPFLAGS="-I/opt/local/include"
221450b6 199 export LDFLAGS="-L/opt/local/lib"
0ef2148a
MJ
200 export PYTHON="python3.9"
201 export PYTHON_CONFIG="python3.9-config"
221450b6 202 ;;
07dafe32 203
897eb548
MJ
204cygwin)
205 export MAKE=make
206 export TAR=tar
207 export NPROC=nproc
208 export PYTHON="python3"
209 export PYTHON_CONFIG="python3-config"
210 rebase_dll=1
211 ;;
212
894db5f1
MJ
213freebsd)
214 export MAKE=gmake
215 export TAR=tar
216 export NPROC="getconf _NPROCESSORS_ONLN"
217 export CPPFLAGS="-I/usr/local/include"
218 export LDFLAGS="-L/usr/local/lib"
219 export PYTHON="python3"
220 export PYTHON_CONFIG="python3-config"
221
222 # For bt 1.5
223 export YACC="bison -y"
224 ;;
225
87e41bca 226*)
a0b535b2
MJ
227 export MAKE=make
228 export TAR=tar
229 export NPROC=nproc
1f620ba0
MJ
230 export PYTHON="python3"
231 export PYTHON_CONFIG="python3-config"
87e41bca
MJ
232 ;;
233esac
234
51c9c62d
MJ
235# Print build env details
236print_os || true
237print_tooling || true
238
a0b535b2
MJ
239# Enter the source directory
240cd "$SRCDIR"
241
242# Run bootstrap in the source directory prior to configure
243./bootstrap
244
245# Get source version from configure script
246eval "$(grep '^PACKAGE_VERSION=' ./configure)"
07dafe32 247PACKAGE_VERSION=${PACKAGE_VERSION//\-pre*/}
a0b535b2 248
11ba7264 249# Enable dev mode by default for BT 2.0 builds
9201e00d
MJ
250export BABELTRACE_DEBUG_MODE=1
251export BABELTRACE_DEV_MODE=1
8130d845 252export BABELTRACE_MINIMAL_LOG_LEVEL=TRACE
11ba7264 253
07dafe32
MJ
254# Set configure options and environment variables for each build
255# configuration.
256CONF_OPTS=("--prefix=$PREFIX")
f0d7e5b1
MJ
257
258# -Werror is enabled by default in stable-2.0 but won't be in 2.1
259# Explicitly disable it for consistency.
260if vergte "$PACKAGE_VERSION" "2.0"; then
261 CONF_OPTS+=("--disable-Werror")
262fi
263
275b59d2
JRJ
264case "$conf" in
265static)
1f620ba0
MJ
266 echo "Static lib only configuration"
267
268 CONF_OPTS+=("--enable-static" "--disable-shared")
269
a0b535b2 270 if vergte "$PACKAGE_VERSION" "2.0"; then
1f620ba0 271 CONF_OPTS+=("--enable-built-in-plugins")
a0b535b2 272 fi
275b59d2 273 ;;
1f620ba0 274
221450b6 275python-bindings)
1f620ba0
MJ
276 echo "Python bindings configuration"
277
278 CONF_OPTS+=("--enable-python-bindings")
a0b535b2
MJ
279
280 if vergte "$PACKAGE_VERSION" "2.0"; then
1f620ba0 281 CONF_OPTS+=("--enable-python-bindings-doc" "--enable-python-plugins")
a0b535b2 282 fi
275b59d2 283 ;;
1f620ba0 284
0d30552d 285prod)
1f620ba0 286 echo "Production configuration"
9201e00d
MJ
287
288 # Unset the developper variables
289 unset BABELTRACE_DEBUG_MODE
290 unset BABELTRACE_DEV_MODE
291 unset BABELTRACE_MINIMAL_LOG_LEVEL
292
293 # Enable the python bindings
1f620ba0 294 CONF_OPTS+=("--enable-python-bindings" "--enable-python-bindings-doc" "--enable-python-plugins")
9201e00d 295 ;;
1f620ba0 296
0d30552d 297min)
1f620ba0 298 echo "Minimal configuration"
0d30552d 299 ;;
1f620ba0 300
275b59d2 301*)
1f620ba0 302 echo "Standard configuration"
0d30552d 303
1f620ba0 304 # Enable the python bindings / plugins by default with babeltrace2,
0d30552d
MJ
305 # the test suite is mostly useless without it.
306 if vergte "$PACKAGE_VERSION" "2.0"; then
1f620ba0 307 CONF_OPTS+=("--enable-python-bindings" "--enable-python-plugins")
0d30552d 308 fi
275b59d2
JRJ
309 ;;
310esac
311
aad6ac90 312# Build type
07dafe32
MJ
313# oot : out-of-tree build
314# dist : build via make dist
315# oot-dist: build via make dist out-of-tree
316# * : normal tree build
aad6ac90 317#
07dafe32 318# Make sure to move to the build directory and run configure
1f620ba0 319# before continuing.
aad6ac90 320case "$build" in
b8475d72
MJ
321oot)
322 echo "Out of tree build"
323
324 # Create and enter a temporary build directory
325 builddir=$(mktemp -d)
326 cd "$builddir"
327
51c9c62d 328 "$SRCDIR/configure" "${CONF_OPTS[@]}" || failed_configure
b8475d72 329 ;;
1f620ba0 330
b8475d72
MJ
331dist)
332 echo "Distribution in-tree build"
1f620ba0 333
b8475d72
MJ
334 # Run configure and generate the tar file
335 # in the source directory
51c9c62d 336 ./configure || failed_configure
b8475d72 337 $MAKE dist
c56b9301 338
b8475d72
MJ
339 # Create and enter a temporary build directory
340 builddir=$(mktemp -d)
341 cd "$builddir"
342
343 # Extract the distribution tar in the build directory,
344 # ignore the first directory level
345 $TAR xvf "$SRCDIR"/*.tar.* --strip 1
346
07dafe32 347 # Build in extracted source tree
51c9c62d 348 ./configure "${CONF_OPTS[@]}" || failed_configure
b8475d72 349 ;;
c56b9301 350
b8475d72
MJ
351oot-dist)
352 echo "Distribution out of tree build"
c56b9301 353
b8475d72
MJ
354 # Create and enter a temporary build directory
355 builddir=$(mktemp -d)
356 cd "$builddir"
c56b9301 357
b8475d72 358 # Run configure out of tree and generate the tar file
51c9c62d 359 "$SRCDIR/configure" || failed_configure
b8475d72 360 $MAKE dist
c56b9301 361
b8475d72
MJ
362 dist_srcdir="$(mktemp -d)"
363 cd "$dist_srcdir"
c56b9301 364
b8475d72
MJ
365 # Extract the distribution tar in the new source directory,
366 # ignore the first directory level
367 $TAR xvf "$builddir"/*.tar.* --strip 1
368
369 # Create and enter a second temporary build directory
370 builddir="$(mktemp -d)"
371 cd "$builddir"
372
373 # Run configure from the extracted distribution tar,
374 # out of the source tree
51c9c62d 375 "$dist_srcdir/configure" "${CONF_OPTS[@]}" || failed_configure
b8475d72
MJ
376 ;;
377
378*)
379 echo "Standard in-tree build"
51c9c62d 380 ./configure "${CONF_OPTS[@]}" || failed_configure
b8475d72 381 ;;
aad6ac90
JR
382esac
383
1f620ba0
MJ
384# We are now inside a configured build directory
385
c56b9301 386# BUILD!
a57a60d9 387$MAKE -j "$($NPROC)" V=1
07dafe32 388
897eb548
MJ
389# Force rebase DLL address mapping
390if [ "${rebase_dll:-}" == "1" ]; then
f2cd0939 391 find . -name "*.dll" -print0 | xargs -0 rebase -O -v
897eb548
MJ
392fi
393
07dafe32
MJ
394# Install in the workspace
395$MAKE install DESTDIR="$WORKSPACE"
c56b9301 396
9d56171a 397# Run tests, don't fail now, we want to run the archiving steps
1d56e325 398failed_tests=0
e3c32202
JR
399if [ "$BABELTRACE_RUN_TESTS" = "yes" ]; then
400 $MAKE --keep-going check || failed_tests=1
401
402 # Copy tap logs for the jenkins tap parser before cleaning the build dir
403 rsync -a --exclude 'test-suite.log' --include '*/' --include '*.log' --exclude='*' tests/ "$WORKSPACE/tap"
404
405 # The test suite prior to 1.5 did not produce TAP logs
406 if verlt "$PACKAGE_VERSION" "1.5"; then
407 mkdir -p "$WORKSPACE/tap/no-log"
408 echo "1..1" > "$WORKSPACE/tap/no-log/tests.log"
409 echo "ok 1 - Test suite doesn't support logging" >> "$WORKSPACE/tap/no-log/tests.log"
410 fi
649c39a6
MJ
411fi
412
e6be9fb0
MJ
413# Clean the build directory
414$MAKE clean
275b59d2 415
c56b9301 416# Cleanup rpath in executables and shared libraries
07dafe32
MJ
417find "$WORKSPACE/$PREFIX/bin" -type f -perm -0500 -exec chrpath --delete {} \;
418find "$WORKSPACE/$PREFIX/lib" -name "*.so" -exec chrpath --delete {} \;
c56b9301
MJ
419
420# Remove libtool .la files
07dafe32 421find "$WORKSPACE/$PREFIX/lib" -name "*.la" -exec rm -f {} \;
87e41bca 422
1d56e325
MJ
423# Exit with failure if any of the tests failed
424exit $failed_tests
9d56171a 425
87e41bca 426# EOF
This page took 0.048098 seconds and 4 git commands to generate.