jjb: liburcu: prepare for ubuntu jammy upgrade
[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=.
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
51c9c62d
MJ
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
80 # End the build with failure
81 exit 1
82}
83
e04f80ef
MJ
84# Required variables
85WORKSPACE=${WORKSPACE:-}
86
a57a60d9
MJ
87arch=${arch:-}
88conf=${conf:-}
89build=${build:-}
3579dc14
MJ
90cc=${cc:-}
91
aff4e3d1
JR
92# Controls if the tests are run
93LTTNG_UST_RUN_TESTS="${LTTNG_UST_RUN_TESTS:=yes}"
a57a60d9 94
3579dc14
MJ
95DEPS_INC="$WORKSPACE/deps/build/include"
96DEPS_LIB="$WORKSPACE/deps/build/lib"
5bd69da1 97DEPS_PKGCONFIG="$DEPS_LIB/pkgconfig"
1d56e325
MJ
98#DEPS_BIN="$WORKSPACE/deps/build/bin"
99#DEPS_JAVA="$WORKSPACE/deps/build/share/java"
2b68721a 100
3579dc14 101export LD_LIBRARY_PATH="$DEPS_LIB:${LD_LIBRARY_PATH:-}"
5bd69da1 102export PKG_CONFIG_PATH="$DEPS_PKGCONFIG"
3579dc14
MJ
103export CPPFLAGS="-I$DEPS_INC"
104export LDFLAGS="-L$DEPS_LIB"
c3bc676b 105
1f4fba8c
MJ
106SRCDIR="$WORKSPACE/src/lttng-ust"
107TMPDIR="$WORKSPACE/tmp"
3579dc14 108PREFIX="/build"
3b3282a6 109
3579dc14
MJ
110# Create tmp directory
111rm -rf "$TMPDIR"
112mkdir -p "$TMPDIR"
1f4fba8c
MJ
113
114export TMPDIR
72d087d4 115export CFLAGS="-g -O2"
1f4fba8c 116
3579dc14
MJ
117# Set compiler variables
118case "$cc" in
119gcc)
120 export CC=gcc
121 export CXX=g++
122 ;;
2356937a
MJ
123gcc-*)
124 export CC=gcc-${cc#gcc-}
125 export CXX=g++-${cc#gcc-}
3579dc14
MJ
126 ;;
127clang)
128 export CC=clang
129 export CXX=clang++
130 ;;
2356937a
MJ
131clang-*)
132 export CC=clang-${cc#clang-}
133 export CXX=clang++-${cc#clang-}
3579dc14
MJ
134 ;;
135*)
136 if [ "x$cc" != "x" ]; then
137 export CC="$cc"
138 fi
139 ;;
140esac
141
142if [ "x${CC:-}" != "x" ]; then
143 echo "Selected compiler:"
144 "$CC" -v
145fi
146
3b3282a6
MJ
147# Set platform variables
148case "$arch" in
2356937a 149freebsd*)
0f7217a0
MJ
150 export MAKE=gmake
151 export TAR=tar
152 export NPROC="getconf _NPROCESSORS_ONLN"
153 export CPPFLAGS="-I/usr/local/include $CPPFLAGS"
154 export LDFLAGS="-L/usr/local/lib $LDFLAGS"
155 export PYTHON="python3"
156 export PYTHON_CONFIG="python3-config"
157 export CLASSPATH='/usr/local/share/java/classes/*'
df63a3ac 158 export JAVA_HOME='/usr/local/openjdk11'
0f7217a0
MJ
159 ;;
160
3b3282a6 161*)
3579dc14
MJ
162 export MAKE=make
163 export TAR=tar
164 export NPROC=nproc
165 export PYTHON="python3"
166 export PYTHON_CONFIG="python3-config"
d956cb6e 167 export CLASSPATH='/usr/share/java/log4j-api.jar:/usr/share/java/log4j-core.jar:/usr/share/java/log4j-1.2.jar'
3579dc14 168 ;;
3b3282a6
MJ
169esac
170
51c9c62d
MJ
171# Print build env details
172print_os || true
173print_tooling || true
174
3579dc14
MJ
175# Enter the source directory
176cd "$SRCDIR"
c3bc676b 177
3579dc14
MJ
178# Run bootstrap in the source directory prior to configure
179./bootstrap
ab89ec98 180
3579dc14
MJ
181# Get source version from configure script
182eval "$(grep '^PACKAGE_VERSION=' ./configure)"
1d56e325 183PACKAGE_VERSION=${PACKAGE_VERSION//\-pre*/}
c3bc676b 184
0b93ba40
MJ
185# Gerrit will trigger build on FreeBSD regardless of the branch, exit
186# successfuly when the version is < 2.13.
187if [[ $arch == freebsd* ]] && verlt "$PACKAGE_VERSION" "2.13"; then
188 mkdir -p "$WORKSPACE/tap/no-log"
189 echo "1..1" > "$WORKSPACE/tap/no-log/tests.log"
190 echo "ok 1 - FreeBSD build unsupported in < 2.13" >> "$WORKSPACE/tap/no-log/tests.log"
191 exit 0
192fi
193
3579dc14
MJ
194# Set configure options and environment variables for each build
195# configuration.
196CONF_OPTS=("--prefix=$PREFIX")
c3bc676b 197case "$conf" in
3b3282a6 198static)
3579dc14
MJ
199 echo "Static lib only configuration"
200
201 CONF_OPTS+=("--enable-static" "--disable-shared")
1d56e325
MJ
202
203 # Unsupported! liblttng-ust can't pull in it's static (.a) dependencies.
204 exit 1
3b3282a6
MJ
205 ;;
206
67122b96 207agents)
3579dc14 208 echo "Java and Python agents configuration"
3b3282a6 209
3579dc14 210 CONF_OPTS+=("--enable-java-agent-all" "--enable-jni-interface" "--enable-python-agent")
efb13b46
MJ
211
212 # Explicitly add '--enable-java-agent-log4j2', it's not part of '-all' in stable 2.12/2.13
213 if verlt "$PACKAGE_VERSION" "2.14"; then
214 CONF_OPTS+=("--enable-java-agent-log4j2")
215 fi
3b3282a6
MJ
216 ;;
217
a76416f2
JR
218debug-rcu)
219 echo "Enable RCU sanity checks for debugging"
3579dc14 220 export CPPFLAGS="${CPPFLAGS} -DDEBUG_RCU"
a76416f2
JR
221 ;;
222
c3bc676b 223*)
3579dc14 224 echo "Standard configuration"
c3bc676b
JRJ
225 ;;
226esac
227
2b68721a 228# Build type
67122b96
MJ
229# oot : out-of-tree build
230# dist : build via make dist
231# oot-dist: build via make dist out-of-tree
232# * : normal tree build
2b68721a 233#
3579dc14
MJ
234# Make sure to move to the build directory and run configure
235# before continuing.
2b68721a 236case "$build" in
3b3282a6
MJ
237oot)
238 echo "Out of tree build"
67122b96 239
3579dc14
MJ
240 # Create and enter a temporary build directory
241 builddir=$(mktemp -d)
242 cd "$builddir"
67122b96 243
51c9c62d 244 "$SRCDIR/configure" "${CONF_OPTS[@]}" || failed_configure
3b3282a6
MJ
245 ;;
246
247dist)
3579dc14 248 echo "Distribution in-tree build"
3b3282a6 249
3579dc14
MJ
250 # Run configure and generate the tar file
251 # in the source directory
0b93ba40 252 ./configure --enable-jni-interface || failed_configure
3b3282a6
MJ
253 $MAKE dist
254
3579dc14
MJ
255 # Create and enter a temporary build directory
256 builddir=$(mktemp -d)
257 cd "$builddir"
3b3282a6 258
3579dc14
MJ
259 # Extract the distribution tar in the build directory,
260 # ignore the first directory level
261 $TAR xvf "$SRCDIR"/*.tar.* --strip 1
3b3282a6 262
67122b96 263 # Build in extracted source tree
51c9c62d 264 ./configure "${CONF_OPTS[@]}" || failed_configure
3b3282a6
MJ
265 ;;
266
67122b96 267oot-dist)
3579dc14 268 echo "Distribution out of tree build"
67122b96 269
3579dc14
MJ
270 # Create and enter a temporary build directory
271 builddir=$(mktemp -d)
272 cd "$builddir"
273
274 # Run configure out of tree and generate the tar file
0b93ba40 275 "$SRCDIR/configure" --enable-jni-interface || failed_configure
67122b96
MJ
276 $MAKE dist
277
3579dc14
MJ
278 dist_srcdir="$(mktemp -d)"
279 cd "$dist_srcdir"
67122b96 280
3579dc14
MJ
281 # Extract the distribution tar in the new source directory,
282 # ignore the first directory level
283 $TAR xvf "$builddir"/*.tar.* --strip 1
67122b96 284
3579dc14
MJ
285 # Create and enter a second temporary build directory
286 builddir="$(mktemp -d)"
287 cd "$builddir"
67122b96 288
3579dc14
MJ
289 # Run configure from the extracted distribution tar,
290 # out of the source tree
51c9c62d 291 "$dist_srcdir/configure" "${CONF_OPTS[@]}" || failed_configure
67122b96
MJ
292 ;;
293
3b3282a6 294*)
1f4fba8c 295 echo "Standard in-tree build"
51c9c62d 296 ./configure "${CONF_OPTS[@]}" || failed_configure
3b3282a6 297 ;;
2b68721a
MJ
298esac
299
3579dc14
MJ
300# We are now inside a configured build directory
301
3b3282a6 302# BUILD!
a57a60d9 303$MAKE -j "$($NPROC)" V=1
c3bc676b 304
3579dc14
MJ
305# Install in the workspace
306$MAKE install DESTDIR="$WORKSPACE"
307
308# Run tests, don't fail now, we want to run the archiving steps
1d56e325 309failed_tests=0
aff4e3d1
JR
310if [ "$LTTNG_UST_RUN_TESTS" = "yes" ]; then
311 $MAKE --keep-going check || failed_tests=1
c3bc676b 312
aff4e3d1
JR
313 # Copy tap logs for the jenkins tap parser before cleaning the build dir
314 rsync -a --exclude 'test-suite.log' --include '*/' --include '*.log' --exclude='*' tests/ "$WORKSPACE/tap"
c3bc676b 315
aff4e3d1
JR
316 # The test suite prior to 2.8 did not produce TAP logs
317 if verlt "$PACKAGE_VERSION" "2.8"; then
318 mkdir -p "$WORKSPACE/tap/no-log"
319 echo "1..1" > "$WORKSPACE/tap/no-log/tests.log"
320 echo "ok 1 - Test suite doesn't support logging" >> "$WORKSPACE/tap/no-log/tests.log"
321 fi
0fe4a4b4
MJ
322fi
323
1f4fba8c 324# Clean the build directory
3b3282a6 325$MAKE clean
c3bc676b 326
3b3282a6 327# Cleanup rpath in executables and shared libraries
1d56e325 328#find "$WORKSPACE/$PREFIX/bin" -type f -perm -0500 -exec chrpath --delete {} \;
3579dc14 329find "$WORKSPACE/$PREFIX/lib" -name "*.so" -exec chrpath --delete {} \;
3b3282a6
MJ
330
331# Remove libtool .la files
3579dc14 332find "$WORKSPACE/$PREFIX/lib" -name "*.la" -exec rm -f {} \;
2b68721a 333
1d56e325
MJ
334# Exit with failure if any of the tests failed
335exit $failed_tests
3b3282a6
MJ
336
337# EOF
This page took 0.08061 seconds and 4 git commands to generate.