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