jjb: Add sles15sp4 to sles builds
[lttng-ci.git] / scripts / lttng-ust / build.sh
CommitLineData
51c9c62d 1#!/bin/bash
2b68721a 2#
3579dc14
MJ
3# Copyright (C) 2015 Jonathan Rajotte-Julien <jonathan.rajotte-julien@efficios.com>
4# 2016-2019 Michael Jeanson <mjeanson@efficios.com>
2b68721a
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
3579dc14
MJ
21# Version compare functions
22vercomp () {
23 set +u
24 if [[ "$1" == "$2" ]]; then
25 return 0
26 fi
27 local IFS=.
4afa623f
MJ
28 # Ignore the shellcheck warning, we want splitting to happen based on IFS.
29 # shellcheck disable=SC2206
3579dc14
MJ
30 local i ver1=($1) ver2=($2)
31 # fill empty fields in ver1 with zeros
32 for ((i=${#ver1[@]}; i<${#ver2[@]}; i++)); do
33 ver1[i]=0
34 done
35 for ((i=0; i<${#ver1[@]}; i++)); do
36 if [[ -z ${ver2[i]} ]]; then
37 # fill empty fields in ver2 with zeros
38 ver2[i]=0
39 fi
40 if ((10#${ver1[i]} > 10#${ver2[i]})); then
41 return 1
42 fi
43 if ((10#${ver1[i]} < 10#${ver2[i]})); then
44 return 2
45 fi
46 done
47 set -u
48 return 0
49}
50
51verlte() {
52 vercomp "$1" "$2"; local res="$?"
53 [ "$res" -eq "0" ] || [ "$res" -eq "2" ]
54}
55
56verlt() {
57 vercomp "$1" "$2"; local res="$?"
58 [ "$res" -eq "2" ]
59}
60
61vergte() {
62 vercomp "$1" "$2"; local res="$?"
63 [ "$res" -eq "0" ] || [ "$res" -eq "1" ]
64}
65
66vergt() {
67 vercomp "$1" "$2"; local res="$?"
68 [ "$res" -eq "1" ]
69}
70
71verne() {
72 vercomp "$1" "$2"; local res="$?"
73 [ "$res" -ne "0" ]
74}
75
51c9c62d
MJ
76failed_configure() {
77 # Assume we are in the configured build directory
78 echo "#################### BEGIN config.log ####################"
79 cat config.log
80 echo "#################### END config.log ####################"
81
82 # End the build with failure
83 exit 1
84}
85
e04f80ef
MJ
86# Required variables
87WORKSPACE=${WORKSPACE:-}
88
94a6d1fb 89platform=${platform:-}
a57a60d9
MJ
90conf=${conf:-}
91build=${build:-}
3579dc14
MJ
92cc=${cc:-}
93
aff4e3d1
JR
94# Controls if the tests are run
95LTTNG_UST_RUN_TESTS="${LTTNG_UST_RUN_TESTS:=yes}"
a57a60d9 96
4afa623f
MJ
97SRCDIR="$WORKSPACE/src/lttng-ust"
98TMPDIR="$WORKSPACE/tmp"
99PREFIX="/build"
100LIBDIR="lib"
32dde2a3 101LIBDIR_ARCH="$LIBDIR"
4afa623f
MJ
102
103# RHEL and SLES both use lib64 but don't bother shipping a default autoconf
104# site config that matches this.
85322e5d
MJ
105if [[ ( -f /etc/redhat-release || -f /etc/SuSE-release || -f /etc/yocto-release ) ]]; then
106 # Detect the userspace bitness in a distro agnostic way
107 if file -L /bin/bash | grep '64-bit' >/dev/null 2>&1; then
108 LIBDIR_ARCH="${LIBDIR}64"
85322e5d 109 fi
4afa623f
MJ
110fi
111
3579dc14 112DEPS_INC="$WORKSPACE/deps/build/include"
4afa623f 113DEPS_LIB="$WORKSPACE/deps/build/$LIBDIR_ARCH"
5bd69da1 114DEPS_PKGCONFIG="$DEPS_LIB/pkgconfig"
1d56e325
MJ
115#DEPS_BIN="$WORKSPACE/deps/build/bin"
116#DEPS_JAVA="$WORKSPACE/deps/build/share/java"
2b68721a 117
3579dc14 118export LD_LIBRARY_PATH="$DEPS_LIB:${LD_LIBRARY_PATH:-}"
5bd69da1 119export PKG_CONFIG_PATH="$DEPS_PKGCONFIG"
3579dc14
MJ
120export CPPFLAGS="-I$DEPS_INC"
121export LDFLAGS="-L$DEPS_LIB"
c3bc676b 122
3579dc14
MJ
123# Create tmp directory
124rm -rf "$TMPDIR"
125mkdir -p "$TMPDIR"
1f4fba8c
MJ
126
127export TMPDIR
72d087d4 128export CFLAGS="-g -O2"
1f4fba8c 129
3579dc14
MJ
130# Set compiler variables
131case "$cc" in
132gcc)
133 export CC=gcc
134 export CXX=g++
135 ;;
2356937a
MJ
136gcc-*)
137 export CC=gcc-${cc#gcc-}
138 export CXX=g++-${cc#gcc-}
3579dc14
MJ
139 ;;
140clang)
141 export CC=clang
142 export CXX=clang++
143 ;;
2356937a
MJ
144clang-*)
145 export CC=clang-${cc#clang-}
146 export CXX=clang++-${cc#clang-}
3579dc14
MJ
147 ;;
148*)
149 if [ "x$cc" != "x" ]; then
150 export CC="$cc"
151 fi
152 ;;
153esac
154
155if [ "x${CC:-}" != "x" ]; then
156 echo "Selected compiler:"
157 "$CC" -v
158fi
159
3b3282a6 160# Set platform variables
94a6d1fb 161case "$platform" in
2356937a 162freebsd*)
0f7217a0
MJ
163 export MAKE=gmake
164 export TAR=tar
165 export NPROC="getconf _NPROCESSORS_ONLN"
166 export CPPFLAGS="-I/usr/local/include $CPPFLAGS"
167 export LDFLAGS="-L/usr/local/lib $LDFLAGS"
168 export PYTHON="python3"
169 export PYTHON_CONFIG="python3-config"
170 export CLASSPATH='/usr/local/share/java/classes/*'
df63a3ac 171 export JAVA_HOME='/usr/local/openjdk11'
0f7217a0
MJ
172 ;;
173
3b3282a6 174*)
3579dc14
MJ
175 export MAKE=make
176 export TAR=tar
177 export NPROC=nproc
178 export PYTHON="python3"
179 export PYTHON_CONFIG="python3-config"
d956cb6e 180 export CLASSPATH='/usr/share/java/log4j-api.jar:/usr/share/java/log4j-core.jar:/usr/share/java/log4j-1.2.jar'
3579dc14 181 ;;
3b3282a6
MJ
182esac
183
51c9c62d
MJ
184# Print build env details
185print_os || true
186print_tooling || true
187
3579dc14
MJ
188# Enter the source directory
189cd "$SRCDIR"
c3bc676b 190
3579dc14
MJ
191# Run bootstrap in the source directory prior to configure
192./bootstrap
ab89ec98 193
3579dc14
MJ
194# Get source version from configure script
195eval "$(grep '^PACKAGE_VERSION=' ./configure)"
1d56e325 196PACKAGE_VERSION=${PACKAGE_VERSION//\-pre*/}
c3bc676b 197
0b93ba40
MJ
198# Gerrit will trigger build on FreeBSD regardless of the branch, exit
199# successfuly when the version is < 2.13.
94a6d1fb 200if [[ $platform == freebsd* ]] && verlt "$PACKAGE_VERSION" "2.13"; then
0b93ba40
MJ
201 mkdir -p "$WORKSPACE/tap/no-log"
202 echo "1..1" > "$WORKSPACE/tap/no-log/tests.log"
203 echo "ok 1 - FreeBSD build unsupported in < 2.13" >> "$WORKSPACE/tap/no-log/tests.log"
204 exit 0
205fi
206
3579dc14
MJ
207# Set configure options and environment variables for each build
208# configuration.
4afa623f 209CONF_OPTS=("--prefix=$PREFIX" "--libdir=$PREFIX/$LIBDIR_ARCH")
c3bc676b 210case "$conf" in
3b3282a6 211static)
3579dc14
MJ
212 echo "Static lib only configuration"
213
214 CONF_OPTS+=("--enable-static" "--disable-shared")
1d56e325
MJ
215
216 # Unsupported! liblttng-ust can't pull in it's static (.a) dependencies.
217 exit 1
3b3282a6
MJ
218 ;;
219
67122b96 220agents)
3579dc14 221 echo "Java and Python agents configuration"
3b3282a6 222
3579dc14 223 CONF_OPTS+=("--enable-java-agent-all" "--enable-jni-interface" "--enable-python-agent")
efb13b46
MJ
224
225 # Explicitly add '--enable-java-agent-log4j2', it's not part of '-all' in stable 2.12/2.13
226 if verlt "$PACKAGE_VERSION" "2.14"; then
227 CONF_OPTS+=("--enable-java-agent-log4j2")
228 fi
3b3282a6
MJ
229 ;;
230
a76416f2
JR
231debug-rcu)
232 echo "Enable RCU sanity checks for debugging"
3579dc14 233 export CPPFLAGS="${CPPFLAGS} -DDEBUG_RCU"
a76416f2
JR
234 ;;
235
c3bc676b 236*)
3579dc14 237 echo "Standard configuration"
6871000c
MJ
238
239 # Something is broken in docbook-xml on yocto
240 if [[ "$platform" = yocto* ]]; then
241 CONF_OPTS+=("--disable-man-pages")
242 fi
c3bc676b
JRJ
243 ;;
244esac
245
2b68721a 246# Build type
67122b96
MJ
247# oot : out-of-tree build
248# dist : build via make dist
249# oot-dist: build via make dist out-of-tree
250# * : normal tree build
2b68721a 251#
3579dc14
MJ
252# Make sure to move to the build directory and run configure
253# before continuing.
2b68721a 254case "$build" in
3b3282a6
MJ
255oot)
256 echo "Out of tree build"
67122b96 257
3579dc14
MJ
258 # Create and enter a temporary build directory
259 builddir=$(mktemp -d)
260 cd "$builddir"
67122b96 261
51c9c62d 262 "$SRCDIR/configure" "${CONF_OPTS[@]}" || failed_configure
3b3282a6
MJ
263 ;;
264
265dist)
3579dc14 266 echo "Distribution in-tree build"
3b3282a6 267
3579dc14
MJ
268 # Run configure and generate the tar file
269 # in the source directory
0b93ba40 270 ./configure --enable-jni-interface || failed_configure
3b3282a6
MJ
271 $MAKE dist
272
3579dc14
MJ
273 # Create and enter a temporary build directory
274 builddir=$(mktemp -d)
275 cd "$builddir"
3b3282a6 276
3579dc14
MJ
277 # Extract the distribution tar in the build directory,
278 # ignore the first directory level
279 $TAR xvf "$SRCDIR"/*.tar.* --strip 1
3b3282a6 280
67122b96 281 # Build in extracted source tree
51c9c62d 282 ./configure "${CONF_OPTS[@]}" || failed_configure
3b3282a6
MJ
283 ;;
284
67122b96 285oot-dist)
3579dc14 286 echo "Distribution out of tree build"
67122b96 287
3579dc14
MJ
288 # Create and enter a temporary build directory
289 builddir=$(mktemp -d)
290 cd "$builddir"
291
292 # Run configure out of tree and generate the tar file
0b93ba40 293 "$SRCDIR/configure" --enable-jni-interface || failed_configure
67122b96
MJ
294 $MAKE dist
295
3579dc14
MJ
296 dist_srcdir="$(mktemp -d)"
297 cd "$dist_srcdir"
67122b96 298
3579dc14
MJ
299 # Extract the distribution tar in the new source directory,
300 # ignore the first directory level
301 $TAR xvf "$builddir"/*.tar.* --strip 1
67122b96 302
3579dc14
MJ
303 # Create and enter a second temporary build directory
304 builddir="$(mktemp -d)"
305 cd "$builddir"
67122b96 306
3579dc14
MJ
307 # Run configure from the extracted distribution tar,
308 # out of the source tree
51c9c62d 309 "$dist_srcdir/configure" "${CONF_OPTS[@]}" || failed_configure
67122b96
MJ
310 ;;
311
3b3282a6 312*)
1f4fba8c 313 echo "Standard in-tree build"
51c9c62d 314 ./configure "${CONF_OPTS[@]}" || failed_configure
3b3282a6 315 ;;
2b68721a
MJ
316esac
317
3579dc14
MJ
318# We are now inside a configured build directory
319
3b3282a6 320# BUILD!
a57a60d9 321$MAKE -j "$($NPROC)" V=1
c3bc676b 322
3579dc14
MJ
323# Install in the workspace
324$MAKE install DESTDIR="$WORKSPACE"
325
326# Run tests, don't fail now, we want to run the archiving steps
1d56e325 327failed_tests=0
aff4e3d1
JR
328if [ "$LTTNG_UST_RUN_TESTS" = "yes" ]; then
329 $MAKE --keep-going check || failed_tests=1
c3bc676b 330
aff4e3d1
JR
331 # Copy tap logs for the jenkins tap parser before cleaning the build dir
332 rsync -a --exclude 'test-suite.log' --include '*/' --include '*.log' --exclude='*' tests/ "$WORKSPACE/tap"
c3bc676b 333
4174b905
MJ
334 # Copy the test suites top-level log which includes all tests failures
335 rsync -a --include 'test-suite.log' --include '*/' --exclude='*' tests/ "$WORKSPACE/log"
336
aff4e3d1
JR
337 # The test suite prior to 2.8 did not produce TAP logs
338 if verlt "$PACKAGE_VERSION" "2.8"; then
339 mkdir -p "$WORKSPACE/tap/no-log"
340 echo "1..1" > "$WORKSPACE/tap/no-log/tests.log"
341 echo "ok 1 - Test suite doesn't support logging" >> "$WORKSPACE/tap/no-log/tests.log"
342 fi
0fe4a4b4
MJ
343fi
344
1f4fba8c 345# Clean the build directory
3b3282a6 346$MAKE clean
c3bc676b 347
3b3282a6 348# Cleanup rpath in executables and shared libraries
1d56e325 349#find "$WORKSPACE/$PREFIX/bin" -type f -perm -0500 -exec chrpath --delete {} \;
4afa623f 350find "$WORKSPACE/$PREFIX/$LIBDIR_ARCH" -name "*.so" -exec chrpath --delete {} \;
3b3282a6
MJ
351
352# Remove libtool .la files
4afa623f 353find "$WORKSPACE/$PREFIX/$LIBDIR_ARCH" -name "*.la" -exec rm -f {} \;
2b68721a 354
1d56e325
MJ
355# Exit with failure if any of the tests failed
356exit $failed_tests
3b3282a6
MJ
357
358# EOF
This page took 0.049109 seconds and 4 git commands to generate.