jjb: babeltrace: prepare for ubuntu jammy upgrade
[lttng-ci.git] / scripts / babeltrace / build.sh
... / ...
CommitLineData
1#!/bin/bash
2#
3# Copyright (C) 2015 Jonathan Rajotte-Julien <jonathan.rajotte-julien@efficios.com>
4# Copyright (C) 2016-2020 Michael Jeanson <mjeanson@efficios.com>
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
19set -exu
20
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
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
83# Required variables
84WORKSPACE=${WORKSPACE:-}
85
86platform=${platform:-}
87conf=${conf:-}
88build=${build:-}
89cc=${cc:-}
90
91# Controls if the tests are run
92BABELTRACE_RUN_TESTS="${BABELTRACE_RUN_TESTS:=yes}"
93
94SRCDIR="$WORKSPACE/src/babeltrace"
95TMPDIR="$WORKSPACE/tmp"
96PREFIX="/build"
97
98# Create tmp directory
99rm -rf "$TMPDIR"
100mkdir -p "$TMPDIR"
101
102export TMPDIR
103export CFLAGS="-g -O2"
104
105# Set compiler variables
106case "$cc" in
107gcc)
108 export CC=gcc
109 export CXX=g++
110 ;;
111gcc-*)
112 export CC=gcc-${cc#gcc-}
113 export CXX=g++-${cc#gcc-}
114 ;;
115clang)
116 export CC=clang
117 export CXX=clang++
118 ;;
119clang-*)
120 export CC=clang-${cc#clang-}
121 export CXX=clang++-${cc#clang-}
122 ;;
123*)
124 if [ "x$cc" != "x" ]; then
125 export CC="$cc"
126 fi
127 ;;
128esac
129
130if [ "x${CC:-}" != "x" ]; then
131 echo "Selected compiler:"
132 "$CC" -v
133fi
134
135# Set platform variables
136case "$platform" in
137macos*)
138 export MAKE=make
139 export TAR=tar
140 export NPROC="getconf _NPROCESSORS_ONLN"
141 export PATH="/opt/local/bin:/opt/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"
142 export CPPFLAGS="-I/opt/local/include"
143 export LDFLAGS="-L/opt/local/lib"
144 export PYTHON="python3.9"
145 export PYTHON_CONFIG="python3.9-config"
146 ;;
147
148freebsd*)
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
161*)
162 export MAKE=make
163 export TAR=tar
164 export NPROC=nproc
165 export PYTHON="python3"
166 export PYTHON_CONFIG="python3-config"
167 ;;
168esac
169
170# Print build env details
171print_os || true
172print_tooling || true
173
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)"
182PACKAGE_VERSION=${PACKAGE_VERSION//\-pre*/}
183
184# Enable dev mode by default for BT 2.0 builds
185export BABELTRACE_DEBUG_MODE=1
186export BABELTRACE_DEV_MODE=1
187export BABELTRACE_MINIMAL_LOG_LEVEL=TRACE
188
189# Set configure options and environment variables for each build
190# configuration.
191CONF_OPTS=("--prefix=$PREFIX")
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
199case "$conf" in
200static)
201 echo "Static lib only configuration"
202
203 CONF_OPTS+=("--enable-static" "--disable-shared")
204
205 if vergte "$PACKAGE_VERSION" "2.0"; then
206 CONF_OPTS+=("--enable-built-in-plugins")
207 fi
208 ;;
209
210python-bindings)
211 echo "Python bindings configuration"
212
213 CONF_OPTS+=("--enable-python-bindings")
214
215 if vergte "$PACKAGE_VERSION" "2.0"; then
216 CONF_OPTS+=("--enable-python-bindings-doc" "--enable-python-plugins")
217 fi
218 ;;
219
220prod)
221 echo "Production configuration"
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
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")
236 ;;
237
238min)
239 echo "Minimal configuration"
240 ;;
241
242*)
243 echo "Standard configuration"
244
245 # Enable the python bindings / plugins by default with babeltrace2,
246 # the test suite is mostly useless without it.
247 if vergte "$PACKAGE_VERSION" "2.0"; then
248 CONF_OPTS+=("--enable-python-bindings" "--enable-python-plugins")
249 fi
250 ;;
251esac
252
253# Build type
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
258#
259# Make sure to move to the build directory and run configure
260# before continuing.
261case "$build" in
262oot)
263 echo "Out of tree build"
264
265 # Create and enter a temporary build directory
266 builddir=$(mktemp -d)
267 cd "$builddir"
268
269 "$SRCDIR/configure" "${CONF_OPTS[@]}" || failed_configure
270 ;;
271
272dist)
273 echo "Distribution in-tree build"
274
275 # Run configure and generate the tar file
276 # in the source directory
277 ./configure || failed_configure
278 $MAKE dist
279
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
288 # Build in extracted source tree
289 ./configure "${CONF_OPTS[@]}" || failed_configure
290 ;;
291
292oot-dist)
293 echo "Distribution out of tree build"
294
295 # Create and enter a temporary build directory
296 builddir=$(mktemp -d)
297 cd "$builddir"
298
299 # Run configure out of tree and generate the tar file
300 "$SRCDIR/configure" || failed_configure
301 $MAKE dist
302
303 dist_srcdir="$(mktemp -d)"
304 cd "$dist_srcdir"
305
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
316 "$dist_srcdir/configure" "${CONF_OPTS[@]}" || failed_configure
317 ;;
318
319*)
320 echo "Standard in-tree build"
321 ./configure "${CONF_OPTS[@]}" || failed_configure
322 ;;
323esac
324
325# We are now inside a configured build directory
326
327# BUILD!
328$MAKE -j "$($NPROC)" V=1
329
330# Install in the workspace
331$MAKE install DESTDIR="$WORKSPACE"
332
333# Run tests, don't fail now, we want to run the archiving steps
334failed_tests=0
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
347fi
348
349# Clean the build directory
350$MAKE clean
351
352# Cleanup rpath in executables and shared libraries
353find "$WORKSPACE/$PREFIX/bin" -type f -perm -0500 -exec chrpath --delete {} \;
354find "$WORKSPACE/$PREFIX/lib" -name "*.so" -exec chrpath --delete {} \;
355
356# Remove libtool .la files
357find "$WORKSPACE/$PREFIX/lib" -name "*.la" -exec rm -f {} \;
358
359# Exit with failure if any of the tests failed
360exit $failed_tests
361
362# EOF
This page took 0.02313 seconds and 4 git commands to generate.