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