jjb: Use the https protocol for checkouts on Github, it's faster
[lttng-ci.git] / scripts / lttng-ust / build.sh
... / ...
CommitLineData
1#!/bin/bash -exu
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
19# Version compare functions
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
47verlte() {
48 vercomp "$1" "$2"; local res="$?"
49 [ "$res" -eq "0" ] || [ "$res" -eq "2" ]
50}
51
52verlt() {
53 vercomp "$1" "$2"; local res="$?"
54 [ "$res" -eq "2" ]
55}
56
57vergte() {
58 vercomp "$1" "$2"; local res="$?"
59 [ "$res" -eq "0" ] || [ "$res" -eq "1" ]
60}
61
62vergt() {
63 vercomp "$1" "$2"; local res="$?"
64 [ "$res" -eq "1" ]
65}
66
67verne() {
68 vercomp "$1" "$2"; local res="$?"
69 [ "$res" -ne "0" ]
70}
71
72# Required variables
73WORKSPACE=${WORKSPACE:-}
74
75arch=${arch:-}
76conf=${conf:-}
77build=${build:-}
78cc=${cc:-}
79
80
81DEPS_INC="$WORKSPACE/deps/build/include"
82DEPS_LIB="$WORKSPACE/deps/build/lib"
83DEPS_PKGCONFIG="$DEPS_LIB/pkgconfig"
84#DEPS_BIN="$WORKSPACE/deps/build/bin"
85#DEPS_JAVA="$WORKSPACE/deps/build/share/java"
86
87export LD_LIBRARY_PATH="$DEPS_LIB:${LD_LIBRARY_PATH:-}"
88export PKG_CONFIG_PATH="$DEPS_PKGCONFIG"
89export CPPFLAGS="-I$DEPS_INC"
90export LDFLAGS="-L$DEPS_LIB"
91
92SRCDIR="$WORKSPACE/src/lttng-ust"
93TMPDIR="$WORKSPACE/tmp"
94PREFIX="/build"
95
96# Create tmp directory
97rm -rf "$TMPDIR"
98mkdir -p "$TMPDIR"
99
100export TMPDIR
101export CFLAGS="-g -O2"
102
103# Set compiler variables
104case "$cc" in
105gcc)
106 export CC=gcc
107 export CXX=g++
108 ;;
109gcc-4.8)
110 export CC=gcc-4.8
111 export CXX=g++-4.8
112 ;;
113gcc-5)
114 export CC=gcc-5
115 export CXX=g++-5
116 ;;
117gcc-6)
118 export CC=gcc-6
119 export CXX=g++-6
120 ;;
121gcc-7)
122 export CC=gcc-7
123 export CXX=g++-7
124 ;;
125gcc-8)
126 export CC=gcc-8
127 export CXX=g++-8
128 ;;
129clang)
130 export CC=clang
131 export CXX=clang++
132 ;;
133clang-3.9)
134 export CC=clang-3.9
135 export CXX=clang++-3.9
136 ;;
137clang-4.0)
138 export CC=clang-4.0
139 export CXX=clang++-4.0
140 ;;
141clang-5.0)
142 export CC=clang-5.0
143 export CXX=clang++-5.0
144 ;;
145clang-6.0)
146 export CC=clang-6.0
147 export CXX=clang++-6.0
148 ;;
149clang-7)
150 export CC=clang-7
151 export CXX=clang++-7
152 ;;
153*)
154 if [ "x$cc" != "x" ]; then
155 export CC="$cc"
156 fi
157 ;;
158esac
159
160if [ "x${CC:-}" != "x" ]; then
161 echo "Selected compiler:"
162 "$CC" -v
163fi
164
165# Set platform variables
166case "$arch" in
167*)
168 export MAKE=make
169 export TAR=tar
170 export NPROC=nproc
171 export PYTHON="python3"
172 export PYTHON_CONFIG="python3-config"
173 ;;
174esac
175
176# Enter the source directory
177cd "$SRCDIR"
178
179# Run bootstrap in the source directory prior to configure
180./bootstrap
181
182# Get source version from configure script
183eval "$(grep '^PACKAGE_VERSION=' ./configure)"
184PACKAGE_VERSION=${PACKAGE_VERSION//\-pre*/}
185
186# Set configure options and environment variables for each build
187# configuration.
188CONF_OPTS=("--prefix=$PREFIX")
189case "$conf" in
190static)
191 echo "Static lib only configuration"
192
193 CONF_OPTS+=("--enable-static" "--disable-shared")
194
195 # Unsupported! liblttng-ust can't pull in it's static (.a) dependencies.
196 exit 1
197 ;;
198
199agents)
200 echo "Java and Python agents configuration"
201
202 export CLASSPATH='/usr/share/java/*'
203 CONF_OPTS+=("--enable-java-agent-all" "--enable-jni-interface" "--enable-python-agent")
204 ;;
205
206debug-rcu)
207 echo "Enable RCU sanity checks for debugging"
208 export CPPFLAGS="${CPPFLAGS} -DDEBUG_RCU"
209 ;;
210
211*)
212 echo "Standard configuration"
213 ;;
214esac
215
216# Build type
217# oot : out-of-tree build
218# dist : build via make dist
219# oot-dist: build via make dist out-of-tree
220# * : normal tree build
221#
222# Make sure to move to the build directory and run configure
223# before continuing.
224case "$build" in
225oot)
226 echo "Out of tree build"
227
228 # Create and enter a temporary build directory
229 builddir=$(mktemp -d)
230 cd "$builddir"
231
232 "$SRCDIR/configure" "${CONF_OPTS[@]}"
233 ;;
234
235dist)
236 echo "Distribution in-tree build"
237
238 # Run configure and generate the tar file
239 # in the source directory
240 ./configure
241 $MAKE dist
242
243 # Create and enter a temporary build directory
244 builddir=$(mktemp -d)
245 cd "$builddir"
246
247 # Extract the distribution tar in the build directory,
248 # ignore the first directory level
249 $TAR xvf "$SRCDIR"/*.tar.* --strip 1
250
251 # Build in extracted source tree
252 ./configure "${CONF_OPTS[@]}"
253 ;;
254
255oot-dist)
256 echo "Distribution out of tree build"
257
258 # Create and enter a temporary build directory
259 builddir=$(mktemp -d)
260 cd "$builddir"
261
262 # Run configure out of tree and generate the tar file
263 "$SRCDIR/configure"
264 $MAKE dist
265
266 dist_srcdir="$(mktemp -d)"
267 cd "$dist_srcdir"
268
269 # Extract the distribution tar in the new source directory,
270 # ignore the first directory level
271 $TAR xvf "$builddir"/*.tar.* --strip 1
272
273 # Create and enter a second temporary build directory
274 builddir="$(mktemp -d)"
275 cd "$builddir"
276
277 # Run configure from the extracted distribution tar,
278 # out of the source tree
279 "$dist_srcdir/configure" "${CONF_OPTS[@]}"
280 ;;
281
282*)
283 echo "Standard in-tree build"
284 ./configure "${CONF_OPTS[@]}"
285 ;;
286esac
287
288# We are now inside a configured build directory
289
290# BUILD!
291$MAKE -j "$($NPROC)" V=1
292
293# Install in the workspace
294$MAKE install DESTDIR="$WORKSPACE"
295
296# Run tests, don't fail now, we want to run the archiving steps
297failed_tests=0
298$MAKE --keep-going check || failed_tests=1
299
300# Copy tap logs for the jenkins tap parser before cleaning the build dir
301rsync -a --exclude 'test-suite.log' --include '*/' --include '*.log' --exclude='*' tests/ "$WORKSPACE/tap"
302
303# The test suite prior to 2.8 did not produce TAP logs
304if verlt "$PACKAGE_VERSION" "2.8"; then
305 mkdir -p "$WORKSPACE/tap/no-log"
306 echo "1..1" > "$WORKSPACE/tap/no-log/tests.log"
307 echo "ok 1 - Test suite doesn't support logging" >> "$WORKSPACE/tap/no-log/tests.log"
308fi
309
310# Clean the build directory
311$MAKE clean
312
313# Cleanup rpath in executables and shared libraries
314#find "$WORKSPACE/$PREFIX/bin" -type f -perm -0500 -exec chrpath --delete {} \;
315find "$WORKSPACE/$PREFIX/lib" -name "*.so" -exec chrpath --delete {} \;
316
317# Remove libtool .la files
318find "$WORKSPACE/$PREFIX/lib" -name "*.la" -exec rm -f {} \;
319
320# Exit with failure if any of the tests failed
321exit $failed_tests
322
323# EOF
This page took 0.022332 seconds and 4 git commands to generate.