jjb: Update liburcu jobs
[lttng-ci.git] / scripts / babeltrace / build.sh
CommitLineData
c56b9301 1#!/bin/bash -exu
890bff23 2#
9d56171a
MJ
3# Copyright (C) 2015 Jonathan Rajotte-Julien <jonathan.rajotte-julien@efficios.com>
4# 2016-2019 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
a0b535b2
MJ
19# Version compare functions
20vercomp () {
21 set +u
22 if [[ "$1" == "$2" ]]; then
23 return 0
24 fi
25 local IFS=.
26 local i ver1=($1) ver2=($2)
27 # fill empty fields in ver1 with zeros
28 for ((i=${#ver1[@]}; i<${#ver2[@]}; i++)); do
29 ver1[i]=0
30 done
31 for ((i=0; i<${#ver1[@]}; i++)); do
32 if [[ -z ${ver2[i]} ]]; then
33 # fill empty fields in ver2 with zeros
34 ver2[i]=0
35 fi
36 if ((10#${ver1[i]} > 10#${ver2[i]})); then
37 return 1
38 fi
39 if ((10#${ver1[i]} < 10#${ver2[i]})); then
40 return 2
41 fi
42 done
43 set -u
44 return 0
45}
46
47verlte() {
48 vercomp "$1" "$2"; local res="$?"
49 [ "$res" -eq "0" ] || [ "$res" -eq "2" ]
50}
51
52verlt() {
53 vercomp "$1" "$2"; local res="$?"
54 [ "$res" -eq "2" ]
55}
56
57vergte() {
58 vercomp "$1" "$2"; local res="$?"
59 [ "$res" -eq "0" ] || [ "$res" -eq "1" ]
60}
61
62vergt() {
63 vercomp "$1" "$2"; local res="$?"
64 [ "$res" -eq "1" ]
65}
66
67verne() {
68 vercomp "$1" "$2"; local res="$?"
69 [ "$res" -ne "0" ]
70}
71
a57a60d9
MJ
72# Required parameters
73arch=${arch:-}
74conf=${conf:-}
75build=${build:-}
6476f917 76cc=${cc:-}
a57a60d9 77
c56b9301 78
e6be9fb0
MJ
79SRCDIR="$WORKSPACE/src/babeltrace"
80TMPDIR="$WORKSPACE/tmp"
275b59d2
JRJ
81PREFIX="$WORKSPACE/build"
82
1f620ba0
MJ
83# The build dir defaults to the source dir
84BUILDDIR="$SRCDIR"
85
86# Create install and tmp directories
e6be9fb0
MJ
87rm -rf "$PREFIX" "$TMPDIR"
88mkdir -p "$PREFIX" "$TMPDIR"
89
0e9967db 90export TMPDIR
72d087d4 91export CFLAGS="-g -O2"
0e9967db 92
6476f917
MJ
93# Set compiler variables
94case "$cc" in
95gcc)
96 export CC=gcc
97 export CXX=g++
98 ;;
99gcc-4.8)
100 export CC=gcc-4.8
101 export CXX=g++-4.8
102 ;;
103gcc-5)
104 export CC=gcc-5
105 export CXX=g++-5
106 ;;
107gcc-6)
108 export CC=gcc-6
109 export CXX=g++-6
110 ;;
111gcc-7)
112 export CC=gcc-7
113 export CXX=g++-7
114 ;;
115gcc-8)
116 export CC=gcc-8
117 export CXX=g++-8
118 ;;
119clang)
120 export CC=clang
121 export CXX=clang++
122 ;;
123clang-3.9)
124 export CC=clang-3.9
125 export CXX=clang++-3.9
126 ;;
127clang-4.0)
128 export CC=clang-4.0
129 export CXX=clang++-4.0
130 ;;
131clang-5.0)
132 export CC=clang-5.0
133 export CXX=clang++-5.0
134 ;;
135clang-6.0)
136 export CC=clang-6.0
137 export CXX=clang++-6.0
138 ;;
139clang-7)
140 export CC=clang-7
141 export CXX=clang++-7
142 ;;
143*)
144 if [ "x$cc" != "x" ]; then
145 export CC="$cc"
146 fi
147 ;;
148esac
149
1183a118 150if [ "x${CC:-}" != "x" ]; then
6476f917
MJ
151 echo "Selected compiler:"
152 "$CC" -v
153fi
154
c56b9301 155# Set platform variables
87e41bca 156case "$arch" in
a0b535b2
MJ
157sol10-i386)
158 export MAKE=gmake
159 export TAR=gtar
160 export NPROC=gnproc
161 export BISON=bison
162 export YACC="$BISON -y"
ad11244c 163 export PATH="/opt/csw/bin:/usr/ccs/bin:$PATH"
a0b535b2
MJ
164 export CPPFLAGS="-I/opt/csw/include"
165 export LDFLAGS="-L/opt/csw/lib -R/opt/csw/lib"
166 export PKG_CONFIG_PATH="/opt/csw/lib/pkgconfig"
1f620ba0
MJ
167 export PYTHON="python3"
168 export PYTHON_CONFIG="python3-config"
87e41bca 169 ;;
a0b535b2
MJ
170sol11-i386)
171 export MAKE=gmake
172 export TAR=gtar
173 export NPROC=nproc
87e41bca 174 export PATH="$PATH:/usr/perl5/bin"
cd808c9e
MJ
175 export LD_ALTEXEC=/usr/bin/gld
176 export LD=/usr/bin/gld
1f620ba0
MJ
177 export PYTHON="python3"
178 export PYTHON_CONFIG="python3-config"
87e41bca 179 ;;
221450b6 180macosx)
a0b535b2
MJ
181 export MAKE=make
182 export TAR=tar
183 export NPROC="getconf _NPROCESSORS_ONLN"
184 export BISON="bison"
185 export YACC="$BISON -y"
221450b6 186 export PATH="/opt/local/bin:/opt/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"
72d087d4 187 export CFLAGS="$CFLAGS -I/opt/local/include"
221450b6 188 export LDFLAGS="-L/opt/local/lib"
1f620ba0
MJ
189 export PYTHON="python3"
190 export PYTHON_CONFIG="python3-config"
221450b6 191 ;;
87e41bca 192*)
a0b535b2
MJ
193 export MAKE=make
194 export TAR=tar
195 export NPROC=nproc
1f620ba0
MJ
196 export PYTHON="python3"
197 export PYTHON_CONFIG="python3-config"
87e41bca
MJ
198 ;;
199esac
200
a0b535b2
MJ
201# Enter the source directory
202cd "$SRCDIR"
203
204# Run bootstrap in the source directory prior to configure
205./bootstrap
206
207# Get source version from configure script
208eval "$(grep '^PACKAGE_VERSION=' ./configure)"
209
11ba7264 210# Enable dev mode by default for BT 2.0 builds
9201e00d
MJ
211export BABELTRACE_DEBUG_MODE=1
212export BABELTRACE_DEV_MODE=1
8130d845 213export BABELTRACE_MINIMAL_LOG_LEVEL=TRACE
11ba7264 214
c56b9301 215# Set configure options for each build configuration
1f620ba0 216CONF_OPTS=()
275b59d2
JRJ
217case "$conf" in
218static)
1f620ba0
MJ
219 echo "Static lib only configuration"
220
221 CONF_OPTS+=("--enable-static" "--disable-shared")
222
a0b535b2 223 if vergte "$PACKAGE_VERSION" "2.0"; then
1f620ba0 224 CONF_OPTS+=("--enable-built-in-plugins")
a0b535b2 225 fi
275b59d2 226 ;;
1f620ba0 227
221450b6 228python-bindings)
1f620ba0
MJ
229 echo "Python bindings configuration"
230
231 CONF_OPTS+=("--enable-python-bindings")
a0b535b2
MJ
232
233 if vergte "$PACKAGE_VERSION" "2.0"; then
1f620ba0 234 CONF_OPTS+=("--enable-python-bindings-doc" "--enable-python-plugins")
a0b535b2 235 fi
275b59d2 236 ;;
1f620ba0 237
0d30552d 238prod)
1f620ba0 239 echo "Production configuration"
9201e00d
MJ
240
241 # Unset the developper variables
242 unset BABELTRACE_DEBUG_MODE
243 unset BABELTRACE_DEV_MODE
244 unset BABELTRACE_MINIMAL_LOG_LEVEL
245
246 # Enable the python bindings
1f620ba0 247 CONF_OPTS+=("--enable-python-bindings" "--enable-python-bindings-doc" "--enable-python-plugins")
9201e00d 248 ;;
1f620ba0 249
0d30552d 250min)
1f620ba0 251 echo "Minimal configuration"
0d30552d 252 ;;
1f620ba0 253
275b59d2 254*)
1f620ba0 255 echo "Standard configuration"
0d30552d 256
1f620ba0 257 # Enable the python bindings / plugins by default with babeltrace2,
0d30552d
MJ
258 # the test suite is mostly useless without it.
259 if vergte "$PACKAGE_VERSION" "2.0"; then
1f620ba0 260 CONF_OPTS+=("--enable-python-bindings" "--enable-python-plugins")
0d30552d 261 fi
275b59d2
JRJ
262 ;;
263esac
264
aad6ac90
JR
265# Build type
266# oot : out-of-tree build
267# dist: build via make dist
268# * : normal tree build
269#
1f620ba0
MJ
270# Make sure to move to the build dir and run configure
271# before continuing.
aad6ac90 272case "$build" in
c56b9301
MJ
273 oot)
274 echo "Out of tree build"
1f620ba0
MJ
275
276 BUILDDIR="$WORKSPACE/oot"
277 mkdir -p "$BUILDDIR"
278 cd "$BUILDDIR"
279
280 "$SRCDIR/configure" --prefix="$PREFIX" "${CONF_OPTS[@]}"
c56b9301
MJ
281 ;;
282
283 dist)
284 echo "Distribution out of tree build"
1f620ba0 285 BUILDDIR="$(mktemp -d)"
c56b9301
MJ
286
287 # Initial configure and generate tarball
a0b535b2 288 "$SRCDIR/configure"
c56b9301
MJ
289 $MAKE dist
290
1f620ba0
MJ
291 mkdir -p "$BUILDDIR"
292 cp ./*.tar.* "$BUILDDIR/"
293 cd "$BUILDDIR"
c56b9301
MJ
294
295 # Ignore level 1 of tar
944a6c86 296 $TAR xvf ./*.tar.* --strip 1
c56b9301 297
1f620ba0 298 ./configure --prefix="$PREFIX" "${CONF_OPTS[@]}"
c56b9301
MJ
299 ;;
300
0628a9d8 301 *)
e6be9fb0 302 echo "Standard in-tree build"
1f620ba0 303 ./configure --prefix="$PREFIX" "${CONF_OPTS[@]}"
c56b9301 304 ;;
aad6ac90
JR
305esac
306
1f620ba0
MJ
307# We are now inside a configured build directory
308
c56b9301 309# BUILD!
a57a60d9 310$MAKE -j "$($NPROC)" V=1
87e41bca 311$MAKE install
c56b9301 312
9d56171a
MJ
313# Run tests, don't fail now, we want to run the archiving steps
314set +e
6827c67a 315$MAKE --keep-going check
9d56171a
MJ
316ret=$?
317set -e
c56b9301 318
1f620ba0 319# Copy tap logs for the jenkins tap parser before cleaning the build dir
e6be9fb0
MJ
320rsync -a --exclude 'test-suite.log' --include '*/' --include '*.log' --exclude='*' tests/ "$WORKSPACE/tap"
321
322# Clean the build directory
323$MAKE clean
275b59d2 324
c56b9301 325# Cleanup rpath in executables and shared libraries
944a6c86
MJ
326find "$PREFIX/bin" -type f -perm -0500 -exec chrpath --delete {} \;
327find "$PREFIX/lib" -name "*.so" -exec chrpath --delete {} \;
c56b9301
MJ
328
329# Remove libtool .la files
944a6c86 330find "$PREFIX/lib" -name "*.la" -exec rm -f {} \;
aad6ac90 331
c56b9301
MJ
332# Clean temp dir for dist build
333if [ "$build" = "dist" ]; then
944a6c86 334 cd "$SRCDIR"
1f620ba0 335 rm -rf "$BUILDDIR"
aad6ac90 336fi
87e41bca 337
9d56171a
MJ
338# Exit with the return code of the test suite
339exit $ret
340
87e41bca 341# EOF
This page took 0.041292 seconds and 4 git commands to generate.