jjb: lttng-ust master requires liburcu master
[lttng-ci.git] / scripts / lttng-tools / build.sh
CommitLineData
3c85b52d 1#!/bin/bash -exu
b4005bbf 2#
3c85b52d 3# Copyright (C) 2016 - Jonathan Rajotte-Julien <jonathan.rajotte-julien@efficios.com>
b4005bbf
MJ
4# 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
0cdaa21c 19# Version compare functions
b6e62a6a
MJ
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
0cdaa21c 47verlte() {
b6e62a6a
MJ
48 vercomp "$1" "$2"; local res="$?"
49 [ "$res" -eq "0" ] || [ "$res" -eq "2" ]
0cdaa21c
MJ
50}
51
52verlt() {
b6e62a6a
MJ
53 vercomp "$1" "$2"; local res="$?"
54 [ "$res" -eq "2" ]
0cdaa21c
MJ
55}
56
57vergte() {
b6e62a6a
MJ
58 vercomp "$1" "$2"; local res="$?"
59 [ "$res" -eq "0" ] || [ "$res" -eq "1" ]
0cdaa21c
MJ
60}
61
62vergt() {
b6e62a6a
MJ
63 vercomp "$1" "$2"; local res="$?"
64 [ "$res" -eq "1" ]
65}
66
67verne() {
68 vercomp "$1" "$2"; local res="$?"
69 [ "$res" -ne "0" ]
0cdaa21c
MJ
70}
71
212d2afd
MJ
72# Required parameters
73arch=${arch:-}
74conf=${conf:-}
75build=${build:-}
b4005bbf 76
212d2afd 77SRCDIR="$WORKSPACE/src/lttng-tools"
67122b96 78#TMPDIR="$WORKSPACE/tmp"
212d2afd
MJ
79PREFIX="$WORKSPACE/build"
80TAPDIR="$WORKSPACE/tap"
81
82
83# Create build and tmp directories
67122b96
MJ
84rm -rf "$PREFIX" "$TAPDIR"
85mkdir -p "$PREFIX" "$TAPDIR"
212d2afd 86
67122b96 87#export TMPDIR
72d087d4 88CFLAGS="-g -O2"
b4005bbf
MJ
89
90# liburcu
91URCU_INCS="$WORKSPACE/deps/liburcu/build/include/"
92URCU_LIBS="$WORKSPACE/deps/liburcu/build/lib/"
93
94# lttng-ust
95UST_INCS="$WORKSPACE/deps/lttng-ust/build/include/"
96UST_LIBS="$WORKSPACE/deps/lttng-ust/build/lib/"
95654431 97UST_JAVA="$WORKSPACE/deps/lttng-ust/build/share/java/"
b4005bbf
MJ
98
99# babeltrace
212d2afd 100#BABEL_INCS="$WORKSPACE/deps/babeltrace/build/include/"
b4005bbf
MJ
101BABEL_LIBS="$WORKSPACE/deps/babeltrace/build/lib/"
102BABEL_BINS="$WORKSPACE/deps/babeltrace/build/bin/"
103
b4005bbf 104
0cdaa21c
MJ
105# Set platform variables
106case "$arch" in
995ac8f2 107sol10-i386)
0cdaa21c
MJ
108 MAKE=gmake
109 TAR=gtar
110 NPROC=gnproc
111 BISON="bison"
112 YACC="$BISON -y"
72d087d4 113 CFLAGS="$CFLAGS -D_XOPEN_SOURCE=500"
0cdaa21c 114 RUN_TESTS="no"
ad11244c
MJ
115
116 export PATH="/opt/csw/bin:/usr/ccs/bin:$PATH"
0cdaa21c
MJ
117 ;;
118
995ac8f2 119sol11-i386)
0cdaa21c
MJ
120 MAKE=gmake
121 TAR=gtar
122 NPROC=nproc
123 BISON="/opt/csw/bin/bison"
124 YACC="$BISON -y"
72d087d4 125 CFLAGS="$CFLAGS -D_XOPEN_SOURCE=500"
0cdaa21c
MJ
126 RUN_TESTS="no"
127
128 export PATH="$PATH:/usr/perl5/bin"
129 ;;
130
b6e62a6a
MJ
131macosx)
132 MAKE=make
133 TAR=tar
134 NPROC="getconf _NPROCESSORS_ONLN"
135 BISON="bison"
136 YACC="$BISON -y"
137 RUN_TESTS="no"
138
139 export PATH="/opt/local/bin:/opt/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"
72d087d4 140 CFLAGS="$CFLAGS -I/opt/local/include"
e6a2206f 141 LDFLAGS="-L/opt/local/lib"
b6e62a6a
MJ
142 ;;
143
61afb3c3
MJ
144cygwin|cygwin64|msys32|msys64)
145 MAKE=make
146 TAR=tar
147 NPROC=nproc
148 BISON="bison"
149 YACC="$BISON -y"
72d087d4 150 #CFLAGS=""
61afb3c3
MJ
151 RUN_TESTS="no"
152 ;;
153
0cdaa21c
MJ
154*)
155 MAKE=make
156 TAR=tar
157 NPROC=nproc
158 BISON="bison"
159 YACC="$BISON -y"
72d087d4 160 #CFLAGS=""
0cdaa21c
MJ
161 RUN_TESTS="yes"
162
163 PYTHON2=python2
164 PYTHON3=python3
165
166 P2_VERSION=$($PYTHON2 -c "import sys;print(sys.version[:3])")
167 P3_VERSION=$($PYTHON3 -c "import sys;print(sys.version[:3])")
168
169 UST_PYTHON2="$WORKSPACE/deps/lttng-ust/build/lib/python$P2_VERSION/site-packages"
170 UST_PYTHON3="$WORKSPACE/deps/lttng-ust/build/lib/python$P3_VERSION/site-packages"
171 ;;
172esac
173
174
212d2afd
MJ
175# Enter the source directory
176cd "$SRCDIR"
177
178# Run bootstrap in the source directory prior to configure
0cdaa21c
MJ
179./bootstrap
180
181# Get source version from configure script
212d2afd
MJ
182eval "$(grep '^PACKAGE_VERSION=' ./configure)"
183PACKAGE_VERSION=$(echo "$PACKAGE_VERSION"| sed 's/\-pre$//')
0cdaa21c
MJ
184
185
186# Export build flags
187case "$conf" in
188no-ust)
e6a2206f
JR
189 CPPFLAGS="${CPPFLAGS:-} -I$URCU_INCS"
190 LDFLAGS="${LDFLAGS:-} -L$URCU_LIBS"
b4005bbf 191 export LD_LIBRARY_PATH="$URCU_LIBS:$BABEL_LIBS:${LD_LIBRARY_PATH:-}"
0cdaa21c
MJ
192 ;;
193
194*)
e6a2206f
JR
195 CPPFLAGS="${CPPFLAGS:-} -I$URCU_INCS -I$UST_INCS"
196 LDFLAGS="${LDFLAGS:-} -L$URCU_LIBS -L$UST_LIBS"
b4005bbf 197 export LD_LIBRARY_PATH="$URCU_LIBS:$UST_LIBS:$BABEL_LIBS:${LD_LIBRARY_PATH:-}"
0cdaa21c
MJ
198 ;;
199esac
b4005bbf 200
0cdaa21c
MJ
201# The switch to build without UST changed in 2.8
202if vergte "$PACKAGE_VERSION" "2.8"; then
203 NO_UST="--without-lttng-ust"
204else
205 NO_UST="--disable-lttng-ust"
206fi
b4005bbf 207
0cdaa21c 208# Set configure options for each build configuration
b4005bbf
MJ
209CONF_OPTS=""
210case "$conf" in
0cdaa21c
MJ
211static)
212 echo "Static build"
213 CONF_OPTS="--enable-static --disable-shared"
214 ;;
215
0cdaa21c
MJ
216no-ust)
217 echo "Build without UST support"
218 CONF_OPTS="$NO_UST"
219 ;;
220
67122b96
MJ
221agents)
222 echo "Enable Java Agents"
0cdaa21c
MJ
223 export JAVA_HOME="/usr/lib/jvm/default-java"
224 export CLASSPATH="$UST_JAVA/*:/usr/share/java/*"
67122b96 225 CONF_OPTS+=" --enable-test-java-agent-all"
0cdaa21c 226
67122b96 227 echo "Enable Python agents"
0cdaa21c 228 export PYTHONPATH="$UST_PYTHON2:$UST_PYTHON3"
67122b96
MJ
229 CONF_OPTS+=" --enable-test-python-agent-all"
230
231 echo "Enable Python bindings"
232 # We only support bindings built with Python 3
233 export PYTHON="python3"
234 export PYTHON_CONFIG="/usr/bin/python3-config"
235 CONF_OPTS+=" --enable-python-bindings"
0cdaa21c
MJ
236 ;;
237
238relayd-only)
239 echo "Build relayd only"
b6e62a6a 240 CONF_OPTS="--disable-bin-lttng --disable-bin-lttng-consumerd --disable-bin-lttng-crash --disable-bin-lttng-sessiond --disable-extras --disable-man-pages $NO_UST"
0cdaa21c
MJ
241 ;;
242
22780fe6
JR
243debug-rcu)
244 echo "Enable RCU sanity checks for debugging"
245 CPPFLAGS="${CPPFLAGS:-} -DDEBUG_RCU"
246 ;;
247
0cdaa21c
MJ
248*)
249 echo "Standard build"
250 CONF_OPTS=""
251 ;;
b4005bbf
MJ
252esac
253
0cdaa21c 254
b4005bbf 255# Build type
67122b96
MJ
256# oot : out-of-tree build
257# dist : build via make dist
258# oot-dist: build via make dist out-of-tree
259# * : normal tree build
b4005bbf 260#
0cdaa21c 261# Make sure to move to the build_path and run configure
b4005bbf 262# before continuing
212d2afd 263BUILD_PATH=$SRCDIR
b4005bbf 264case "$build" in
95654431
MJ
265 oot)
266 echo "Out of tree build"
267 BUILD_PATH=$WORKSPACE/oot
b6e62a6a
MJ
268 mkdir -p "$BUILD_PATH"
269 cd "$BUILD_PATH"
e6a2206f 270 MAKE=$MAKE BISON="$BISON" YACC="$YACC" CFLAGS="$CFLAGS" LDFLAGS="$LDFLAGS" CPPFLAGS="$CPPFLAGS" "$SRCDIR/configure" --prefix="$PREFIX" $CONF_OPTS
95654431
MJ
271 ;;
272
273 dist)
67122b96 274 echo "Distribution tarball in-tree build"
95654431
MJ
275
276 # Initial configure and generate tarball
e6a2206f 277 MAKE=$MAKE BISON="$BISON" YACC="$YACC" CFLAGS="$CFLAGS" LDFLAGS="$LDFLAGS" CPPFLAGS="$CPPFLAGS" "$SRCDIR/configure" $CONF_OPTS --enable-build-man-pages
0cdaa21c 278 $MAKE dist
95654431 279
67122b96 280 BUILD_PATH="$(mktemp -d)"
b6e62a6a
MJ
281 cp ./*.tar.* "$BUILD_PATH/"
282 cd "$BUILD_PATH"
95654431
MJ
283
284 # Ignore level 1 of tar
b6e62a6a 285 $TAR xvf ./*.tar.* --strip 1
95654431 286
67122b96 287 # Build in extracted source tree
e6a2206f 288 MAKE=$MAKE BISON="$BISON" YACC="$YACC" CFLAGS="$CFLAGS" LDFLAGS="$LDFLAGS" CPPFLAGS="$CPPFLAGS" "$BUILD_PATH/configure" --prefix="$PREFIX" $CONF_OPTS
95654431
MJ
289 ;;
290
67122b96
MJ
291 oot-dist)
292 echo "Distribution tarball out of tree build"
293 BUILD_PATH="$(mktemp -d)"
294 cd "$BUILD_PATH"
295
296 # Initial configure and generate tarball
e6a2206f 297 MAKE=$MAKE BISON="$BISON" YACC="$YACC" CFLAGS="$CFLAGS" LDFLAGS="$LDFLAGS" CPPFLAGS="$CPPFLAGS" "$SRCDIR/configure" $CONF_OPTS --enable-build-man-pages
67122b96
MJ
298 $MAKE dist
299
300 NEWSRC_PATH="$(mktemp -d)"
301 cp ./*.tar.* "$NEWSRC_PATH/"
302 cd "$NEWSRC_PATH"
303
304 # Ignore level 1 of tar
305 $TAR xvf ./*.tar.* --strip 1
306
307 BUILD_PATH="$(mktemp -d)"
308 cd "$BUILD_PATH"
309
310 # Build oot from extracted sources
e6a2206f 311 MAKE=$MAKE BISON="$BISON" YACC="$YACC" CFLAGS="$CFLAGS" LDFLAGS="$LDFLAGS" CPPFLAGS="$CPPFLAGS" "$NEWSRC_PATH/configure" --prefix="$PREFIX" $CONF_OPTS
67122b96
MJ
312 ;;
313
95654431 314 *)
95654431 315 echo "Standard tree build"
e6a2206f 316 MAKE=$MAKE BISON="$BISON" YACC="$YACC" CFLAGS="$CFLAGS" LDFLAGS="$LDFLAGS" CPPFLAGS="$CPPFLAGS" "$BUILD_PATH/configure" --prefix="$PREFIX" $CONF_OPTS
95654431 317 ;;
b4005bbf
MJ
318esac
319
0cdaa21c 320# BUILD!
212d2afd 321$MAKE -j "$($NPROC)" V=1
0cdaa21c 322$MAKE install
b4005bbf
MJ
323
324# Run tests
0cdaa21c 325if [ "$RUN_TESTS" = "yes" ]; then
212d2afd 326 cd tests || exit 1
7671741c 327
0cdaa21c
MJ
328 # Allow core dumps
329 ulimit -c unlimited
330
331 # Add 'babeltrace' binary to PATH
7671741c 332 chmod +x "$BABEL_BINS/babeltrace"
0cdaa21c
MJ
333 export PATH="$PATH:$BABEL_BINS"
334
335 # Prepare tap output dirs
212d2afd
MJ
336 rm -rf "$TAPDIR"
337 mkdir -p "$TAPDIR"
338 mkdir -p "$TAPDIR/unit"
339 mkdir -p "$TAPDIR/fast_regression"
340 mkdir -p "$TAPDIR/with_bindings_regression"
0cdaa21c 341
a4e98cc0
JR
342 # Force the lttng-sessiond path to /bin/true to prevent the spawing of a
343 # lttng-sessiond --daemonize on "lttng create"
344 export LTTNG_SESSIOND_PATH="/bin/true"
345
0cdaa21c
MJ
346 # Run 'unit_tests' and 'fast_regression' test suites for all configs except 'no-ust'
347 if [ "$conf" != "no-ust" ]; then
3c85b52d
MJ
348 # Run 'unit_tests', 2.8 and up has a new test suite
349 if vergte "$PACKAGE_VERSION" "2.8"; then
6827c67a 350 make --keep-going check
212d2afd 351 rsync -a --exclude 'test-suite.log' --include '*/' --include '*.log' --exclude='*'" $BUILD_PATH/tests/" "$TAPDIR"
3c85b52d 352 else
212d2afd
MJ
353 prove --merge -v --exec '' - < "$BUILD_PATH/tests/unit_tests" --archive "$TAPDIR/unit/" || true
354 prove --merge -v --exec '' - < "$BUILD_PATH/tests/fast_regression" --archive "$TAPDIR/fast_regression/" || true
3c85b52d 355 fi
0cdaa21c
MJ
356 else
357 # Regression is disabled for now, we need to adjust the testsuite for no ust builds.
3c85b52d 358 echo "Tests disabled for 'no-ust'."
0cdaa21c
MJ
359 fi
360
361 # Run 'with_bindings_regression' test suite for 'python-bindings' config
362 if [ "$conf" = "python-bindings" ]; then
212d2afd 363 prove --merge -v --exec '' - < "$BUILD_PATH/tests/with_bindings_regression" --archive "$TAPDIR/with_bindings_regression/" || true
0cdaa21c
MJ
364 fi
365
366 # TAP plugin is having a hard time with .yml files.
212d2afd 367 find "$TAPDIR" -name "meta.yml" -exec rm -f {} \;
0cdaa21c
MJ
368
369 # And also with files without extension, so rename all result to *.tap
212d2afd 370 find "$TAPDIR/" -type f -exec mv {} {}.tap \;
7671741c
MJ
371
372 cd -
b4005bbf
MJ
373fi
374
b4005bbf 375# Cleanup
0cdaa21c 376$MAKE clean
b4005bbf 377
0cdaa21c 378# Cleanup rpath in executables and shared libraries
212d2afd
MJ
379find "$PREFIX/bin" -type f -perm -0500 -exec chrpath --delete {} \;
380find "$PREFIX/lib" -name "*.so" -exec chrpath --delete {} \;
0cdaa21c
MJ
381
382# Remove libtool .la files
212d2afd 383find "$PREFIX/lib" -name "*.la" -exec rm -f {} \;
b4005bbf
MJ
384
385# Clean temp dir for dist build
0cdaa21c 386if [ "$build" = "dist" ]; then
212d2afd 387 cd "$SRCDIR"
7671741c 388 rm -rf "$BUILD_PATH"
b4005bbf 389fi
95654431
MJ
390
391# EOF
This page took 0.040759 seconds and 4 git commands to generate.