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