jjb: babeltrace: prepare for ubuntu jammy upgrade
[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
776b0d3d 86platform=${platform:-}
a57a60d9
MJ
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 ;;
0f505d21
MJ
111gcc-*)
112 export CC=gcc-${cc#gcc-}
113 export CXX=g++-${cc#gcc-}
6476f917
MJ
114 ;;
115clang)
116 export CC=clang
117 export CXX=clang++
118 ;;
0f505d21
MJ
119clang-*)
120 export CC=clang-${cc#clang-}
121 export CXX=clang++-${cc#clang-}
6476f917
MJ
122 ;;
123*)
124 if [ "x$cc" != "x" ]; then
125 export CC="$cc"
126 fi
127 ;;
128esac
129
1183a118 130if [ "x${CC:-}" != "x" ]; then
6476f917
MJ
131 echo "Selected compiler:"
132 "$CC" -v
133fi
134
c56b9301 135# Set platform variables
776b0d3d 136case "$platform" in
f0d7e5b1 137macos*)
a0b535b2
MJ
138 export MAKE=make
139 export TAR=tar
140 export NPROC="getconf _NPROCESSORS_ONLN"
221450b6 141 export PATH="/opt/local/bin:/opt/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"
07dafe32 142 export CPPFLAGS="-I/opt/local/include"
221450b6 143 export LDFLAGS="-L/opt/local/lib"
0ef2148a
MJ
144 export PYTHON="python3.9"
145 export PYTHON_CONFIG="python3.9-config"
221450b6 146 ;;
07dafe32 147
0f505d21 148freebsd*)
894db5f1
MJ
149 export MAKE=gmake
150 export TAR=tar
151 export NPROC="getconf _NPROCESSORS_ONLN"
152 export CPPFLAGS="-I/usr/local/include"
153 export LDFLAGS="-L/usr/local/lib"
154 export PYTHON="python3"
155 export PYTHON_CONFIG="python3-config"
156
157 # For bt 1.5
158 export YACC="bison -y"
159 ;;
160
87e41bca 161*)
a0b535b2
MJ
162 export MAKE=make
163 export TAR=tar
164 export NPROC=nproc
1f620ba0
MJ
165 export PYTHON="python3"
166 export PYTHON_CONFIG="python3-config"
87e41bca
MJ
167 ;;
168esac
169
51c9c62d
MJ
170# Print build env details
171print_os || true
172print_tooling || true
173
a0b535b2
MJ
174# Enter the source directory
175cd "$SRCDIR"
176
177# Run bootstrap in the source directory prior to configure
178./bootstrap
179
180# Get source version from configure script
181eval "$(grep '^PACKAGE_VERSION=' ./configure)"
07dafe32 182PACKAGE_VERSION=${PACKAGE_VERSION//\-pre*/}
a0b535b2 183
11ba7264 184# Enable dev mode by default for BT 2.0 builds
9201e00d
MJ
185export BABELTRACE_DEBUG_MODE=1
186export BABELTRACE_DEV_MODE=1
8130d845 187export BABELTRACE_MINIMAL_LOG_LEVEL=TRACE
11ba7264 188
07dafe32
MJ
189# Set configure options and environment variables for each build
190# configuration.
191CONF_OPTS=("--prefix=$PREFIX")
f0d7e5b1
MJ
192
193# -Werror is enabled by default in stable-2.0 but won't be in 2.1
194# Explicitly disable it for consistency.
195if vergte "$PACKAGE_VERSION" "2.0"; then
196 CONF_OPTS+=("--disable-Werror")
197fi
198
275b59d2
JRJ
199case "$conf" in
200static)
1f620ba0
MJ
201 echo "Static lib only configuration"
202
203 CONF_OPTS+=("--enable-static" "--disable-shared")
204
a0b535b2 205 if vergte "$PACKAGE_VERSION" "2.0"; then
1f620ba0 206 CONF_OPTS+=("--enable-built-in-plugins")
a0b535b2 207 fi
275b59d2 208 ;;
1f620ba0 209
221450b6 210python-bindings)
1f620ba0
MJ
211 echo "Python bindings configuration"
212
213 CONF_OPTS+=("--enable-python-bindings")
a0b535b2
MJ
214
215 if vergte "$PACKAGE_VERSION" "2.0"; then
1f620ba0 216 CONF_OPTS+=("--enable-python-bindings-doc" "--enable-python-plugins")
a0b535b2 217 fi
275b59d2 218 ;;
1f620ba0 219
0d30552d 220prod)
1f620ba0 221 echo "Production configuration"
9201e00d
MJ
222
223 # Unset the developper variables
224 unset BABELTRACE_DEBUG_MODE
225 unset BABELTRACE_DEV_MODE
226 unset BABELTRACE_MINIMAL_LOG_LEVEL
227
228 # Enable the python bindings
301b8fc9
MJ
229 CONF_OPTS+=("--enable-python-bindings" "--enable-python-plugins")
230 ;;
231
232doc)
233 echo "Documentation configuration"
234
235 CONF_OPTS+=("--enable-python-bindings" "--enable-python-bindings-doc" "--enable-python-plugins" "--enable-api-doc")
9201e00d 236 ;;
1f620ba0 237
0d30552d 238min)
1f620ba0 239 echo "Minimal configuration"
0d30552d 240 ;;
1f620ba0 241
275b59d2 242*)
1f620ba0 243 echo "Standard configuration"
0d30552d 244
1f620ba0 245 # Enable the python bindings / plugins by default with babeltrace2,
0d30552d
MJ
246 # the test suite is mostly useless without it.
247 if vergte "$PACKAGE_VERSION" "2.0"; then
1f620ba0 248 CONF_OPTS+=("--enable-python-bindings" "--enable-python-plugins")
0d30552d 249 fi
275b59d2
JRJ
250 ;;
251esac
252
aad6ac90 253# Build type
07dafe32
MJ
254# oot : out-of-tree build
255# dist : build via make dist
256# oot-dist: build via make dist out-of-tree
257# * : normal tree build
aad6ac90 258#
07dafe32 259# Make sure to move to the build directory and run configure
1f620ba0 260# before continuing.
aad6ac90 261case "$build" in
b8475d72
MJ
262oot)
263 echo "Out of tree build"
264
265 # Create and enter a temporary build directory
266 builddir=$(mktemp -d)
267 cd "$builddir"
268
51c9c62d 269 "$SRCDIR/configure" "${CONF_OPTS[@]}" || failed_configure
b8475d72 270 ;;
1f620ba0 271
b8475d72
MJ
272dist)
273 echo "Distribution in-tree build"
1f620ba0 274
b8475d72
MJ
275 # Run configure and generate the tar file
276 # in the source directory
51c9c62d 277 ./configure || failed_configure
b8475d72 278 $MAKE dist
c56b9301 279
b8475d72
MJ
280 # Create and enter a temporary build directory
281 builddir=$(mktemp -d)
282 cd "$builddir"
283
284 # Extract the distribution tar in the build directory,
285 # ignore the first directory level
286 $TAR xvf "$SRCDIR"/*.tar.* --strip 1
287
07dafe32 288 # Build in extracted source tree
51c9c62d 289 ./configure "${CONF_OPTS[@]}" || failed_configure
b8475d72 290 ;;
c56b9301 291
b8475d72
MJ
292oot-dist)
293 echo "Distribution out of tree build"
c56b9301 294
b8475d72
MJ
295 # Create and enter a temporary build directory
296 builddir=$(mktemp -d)
297 cd "$builddir"
c56b9301 298
b8475d72 299 # Run configure out of tree and generate the tar file
51c9c62d 300 "$SRCDIR/configure" || failed_configure
b8475d72 301 $MAKE dist
c56b9301 302
b8475d72
MJ
303 dist_srcdir="$(mktemp -d)"
304 cd "$dist_srcdir"
c56b9301 305
b8475d72
MJ
306 # Extract the distribution tar in the new source directory,
307 # ignore the first directory level
308 $TAR xvf "$builddir"/*.tar.* --strip 1
309
310 # Create and enter a second temporary build directory
311 builddir="$(mktemp -d)"
312 cd "$builddir"
313
314 # Run configure from the extracted distribution tar,
315 # out of the source tree
51c9c62d 316 "$dist_srcdir/configure" "${CONF_OPTS[@]}" || failed_configure
b8475d72
MJ
317 ;;
318
319*)
320 echo "Standard in-tree build"
51c9c62d 321 ./configure "${CONF_OPTS[@]}" || failed_configure
b8475d72 322 ;;
aad6ac90
JR
323esac
324
1f620ba0
MJ
325# We are now inside a configured build directory
326
c56b9301 327# BUILD!
a57a60d9 328$MAKE -j "$($NPROC)" V=1
07dafe32
MJ
329
330# Install in the workspace
331$MAKE install DESTDIR="$WORKSPACE"
c56b9301 332
9d56171a 333# Run tests, don't fail now, we want to run the archiving steps
1d56e325 334failed_tests=0
e3c32202
JR
335if [ "$BABELTRACE_RUN_TESTS" = "yes" ]; then
336 $MAKE --keep-going check || failed_tests=1
337
338 # Copy tap logs for the jenkins tap parser before cleaning the build dir
339 rsync -a --exclude 'test-suite.log' --include '*/' --include '*.log' --exclude='*' tests/ "$WORKSPACE/tap"
340
341 # The test suite prior to 1.5 did not produce TAP logs
342 if verlt "$PACKAGE_VERSION" "1.5"; then
343 mkdir -p "$WORKSPACE/tap/no-log"
344 echo "1..1" > "$WORKSPACE/tap/no-log/tests.log"
345 echo "ok 1 - Test suite doesn't support logging" >> "$WORKSPACE/tap/no-log/tests.log"
346 fi
649c39a6
MJ
347fi
348
e6be9fb0
MJ
349# Clean the build directory
350$MAKE clean
275b59d2 351
c56b9301 352# Cleanup rpath in executables and shared libraries
07dafe32
MJ
353find "$WORKSPACE/$PREFIX/bin" -type f -perm -0500 -exec chrpath --delete {} \;
354find "$WORKSPACE/$PREFIX/lib" -name "*.so" -exec chrpath --delete {} \;
c56b9301
MJ
355
356# Remove libtool .la files
07dafe32 357find "$WORKSPACE/$PREFIX/lib" -name "*.la" -exec rm -f {} \;
87e41bca 358
1d56e325
MJ
359# Exit with failure if any of the tests failed
360exit $failed_tests
9d56171a 361
87e41bca 362# EOF
This page took 0.068307 seconds and 4 git commands to generate.