jjb: babeltrace: force remap DLL addresses on Cygwin x86
[lttng-ci.git] / scripts / babeltrace / build.sh
CommitLineData
c56b9301 1#!/bin/bash -exu
890bff23 2#
9d56171a
MJ
3# Copyright (C) 2015 Jonathan Rajotte-Julien <jonathan.rajotte-julien@efficios.com>
4# 2016-2019 Michael Jeanson <mjeanson@efficios.com>
890bff23
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
a0b535b2
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
07dafe32
MJ
72# Required variables
73WORKSPACE=${WORKSPACE:-}
74
a57a60d9
MJ
75arch=${arch:-}
76conf=${conf:-}
77build=${build:-}
6476f917 78cc=${cc:-}
a57a60d9 79
c56b9301 80
e6be9fb0
MJ
81SRCDIR="$WORKSPACE/src/babeltrace"
82TMPDIR="$WORKSPACE/tmp"
07dafe32 83PREFIX="/build"
275b59d2 84
07dafe32
MJ
85# Create tmp directory
86rm -rf "$TMPDIR"
87mkdir -p "$TMPDIR"
e6be9fb0 88
0e9967db 89export TMPDIR
72d087d4 90export CFLAGS="-g -O2"
0e9967db 91
6476f917
MJ
92# Set compiler variables
93case "$cc" in
94gcc)
95 export CC=gcc
96 export CXX=g++
97 ;;
98gcc-4.8)
99 export CC=gcc-4.8
100 export CXX=g++-4.8
101 ;;
102gcc-5)
103 export CC=gcc-5
104 export CXX=g++-5
105 ;;
106gcc-6)
107 export CC=gcc-6
108 export CXX=g++-6
109 ;;
110gcc-7)
111 export CC=gcc-7
112 export CXX=g++-7
113 ;;
114gcc-8)
115 export CC=gcc-8
116 export CXX=g++-8
117 ;;
118clang)
119 export CC=clang
120 export CXX=clang++
121 ;;
122clang-3.9)
123 export CC=clang-3.9
124 export CXX=clang++-3.9
125 ;;
126clang-4.0)
127 export CC=clang-4.0
128 export CXX=clang++-4.0
129 ;;
130clang-5.0)
131 export CC=clang-5.0
132 export CXX=clang++-5.0
133 ;;
134clang-6.0)
135 export CC=clang-6.0
136 export CXX=clang++-6.0
137 ;;
138clang-7)
139 export CC=clang-7
140 export CXX=clang++-7
141 ;;
142*)
143 if [ "x$cc" != "x" ]; then
144 export CC="$cc"
145 fi
146 ;;
147esac
148
1183a118 149if [ "x${CC:-}" != "x" ]; then
6476f917
MJ
150 echo "Selected compiler:"
151 "$CC" -v
152fi
153
c56b9301 154# Set platform variables
87e41bca 155case "$arch" in
a0b535b2
MJ
156sol10-i386)
157 export MAKE=gmake
158 export TAR=gtar
159 export NPROC=gnproc
ad11244c 160 export PATH="/opt/csw/bin:/usr/ccs/bin:$PATH"
a0b535b2
MJ
161 export CPPFLAGS="-I/opt/csw/include"
162 export LDFLAGS="-L/opt/csw/lib -R/opt/csw/lib"
163 export PKG_CONFIG_PATH="/opt/csw/lib/pkgconfig"
1f620ba0
MJ
164 export PYTHON="python3"
165 export PYTHON_CONFIG="python3-config"
87e41bca 166 ;;
07dafe32 167
a0b535b2
MJ
168sol11-i386)
169 export MAKE=gmake
170 export TAR=gtar
171 export NPROC=nproc
87e41bca 172 export PATH="$PATH:/usr/perl5/bin"
1d56e325
MJ
173 export CPPFLAGS="-I/opt/csw/include"
174 export LDFLAGS="-L/opt/csw/lib -R/opt/csw/lib"
cd808c9e
MJ
175 export LD_ALTEXEC=/usr/bin/gld
176 export LD=/usr/bin/gld
1f620ba0
MJ
177 export PYTHON="python3"
178 export PYTHON_CONFIG="python3-config"
87e41bca 179 ;;
07dafe32 180
221450b6 181macosx)
a0b535b2
MJ
182 export MAKE=make
183 export TAR=tar
184 export NPROC="getconf _NPROCESSORS_ONLN"
221450b6 185 export PATH="/opt/local/bin:/opt/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"
07dafe32 186 export CPPFLAGS="-I/opt/local/include"
221450b6 187 export LDFLAGS="-L/opt/local/lib"
1f620ba0
MJ
188 export PYTHON="python3"
189 export PYTHON_CONFIG="python3-config"
221450b6 190 ;;
07dafe32 191
897eb548
MJ
192cygwin)
193 export MAKE=make
194 export TAR=tar
195 export NPROC=nproc
196 export PYTHON="python3"
197 export PYTHON_CONFIG="python3-config"
198 rebase_dll=1
199 ;;
200
87e41bca 201*)
a0b535b2
MJ
202 export MAKE=make
203 export TAR=tar
204 export NPROC=nproc
1f620ba0
MJ
205 export PYTHON="python3"
206 export PYTHON_CONFIG="python3-config"
87e41bca
MJ
207 ;;
208esac
209
a0b535b2
MJ
210# Enter the source directory
211cd "$SRCDIR"
212
213# Run bootstrap in the source directory prior to configure
214./bootstrap
215
216# Get source version from configure script
217eval "$(grep '^PACKAGE_VERSION=' ./configure)"
07dafe32 218PACKAGE_VERSION=${PACKAGE_VERSION//\-pre*/}
a0b535b2 219
11ba7264 220# Enable dev mode by default for BT 2.0 builds
9201e00d
MJ
221export BABELTRACE_DEBUG_MODE=1
222export BABELTRACE_DEV_MODE=1
8130d845 223export BABELTRACE_MINIMAL_LOG_LEVEL=TRACE
11ba7264 224
07dafe32
MJ
225# Set configure options and environment variables for each build
226# configuration.
227CONF_OPTS=("--prefix=$PREFIX")
275b59d2
JRJ
228case "$conf" in
229static)
1f620ba0
MJ
230 echo "Static lib only configuration"
231
232 CONF_OPTS+=("--enable-static" "--disable-shared")
233
a0b535b2 234 if vergte "$PACKAGE_VERSION" "2.0"; then
1f620ba0 235 CONF_OPTS+=("--enable-built-in-plugins")
a0b535b2 236 fi
275b59d2 237 ;;
1f620ba0 238
221450b6 239python-bindings)
1f620ba0
MJ
240 echo "Python bindings configuration"
241
242 CONF_OPTS+=("--enable-python-bindings")
a0b535b2
MJ
243
244 if vergte "$PACKAGE_VERSION" "2.0"; then
1f620ba0 245 CONF_OPTS+=("--enable-python-bindings-doc" "--enable-python-plugins")
a0b535b2 246 fi
275b59d2 247 ;;
1f620ba0 248
0d30552d 249prod)
1f620ba0 250 echo "Production configuration"
9201e00d
MJ
251
252 # Unset the developper variables
253 unset BABELTRACE_DEBUG_MODE
254 unset BABELTRACE_DEV_MODE
255 unset BABELTRACE_MINIMAL_LOG_LEVEL
256
257 # Enable the python bindings
1f620ba0 258 CONF_OPTS+=("--enable-python-bindings" "--enable-python-bindings-doc" "--enable-python-plugins")
9201e00d 259 ;;
1f620ba0 260
0d30552d 261min)
1f620ba0 262 echo "Minimal configuration"
0d30552d 263 ;;
1f620ba0 264
275b59d2 265*)
1f620ba0 266 echo "Standard configuration"
0d30552d 267
1f620ba0 268 # Enable the python bindings / plugins by default with babeltrace2,
0d30552d
MJ
269 # the test suite is mostly useless without it.
270 if vergte "$PACKAGE_VERSION" "2.0"; then
1f620ba0 271 CONF_OPTS+=("--enable-python-bindings" "--enable-python-plugins")
0d30552d 272 fi
275b59d2
JRJ
273 ;;
274esac
275
aad6ac90 276# Build type
07dafe32
MJ
277# oot : out-of-tree build
278# dist : build via make dist
279# oot-dist: build via make dist out-of-tree
280# * : normal tree build
aad6ac90 281#
07dafe32 282# Make sure to move to the build directory and run configure
1f620ba0 283# before continuing.
aad6ac90 284case "$build" in
b8475d72
MJ
285oot)
286 echo "Out of tree build"
287
288 # Create and enter a temporary build directory
289 builddir=$(mktemp -d)
290 cd "$builddir"
291
07dafe32 292 "$SRCDIR/configure" "${CONF_OPTS[@]}"
b8475d72 293 ;;
1f620ba0 294
b8475d72
MJ
295dist)
296 echo "Distribution in-tree build"
1f620ba0 297
b8475d72
MJ
298 # Run configure and generate the tar file
299 # in the source directory
300 ./configure
301 $MAKE dist
c56b9301 302
b8475d72
MJ
303 # Create and enter a temporary build directory
304 builddir=$(mktemp -d)
305 cd "$builddir"
306
307 # Extract the distribution tar in the build directory,
308 # ignore the first directory level
309 $TAR xvf "$SRCDIR"/*.tar.* --strip 1
310
07dafe32
MJ
311 # Build in extracted source tree
312 ./configure "${CONF_OPTS[@]}"
b8475d72 313 ;;
c56b9301 314
b8475d72
MJ
315oot-dist)
316 echo "Distribution out of tree build"
c56b9301 317
b8475d72
MJ
318 # Create and enter a temporary build directory
319 builddir=$(mktemp -d)
320 cd "$builddir"
c56b9301 321
b8475d72
MJ
322 # Run configure out of tree and generate the tar file
323 "$SRCDIR/configure"
324 $MAKE dist
c56b9301 325
b8475d72
MJ
326 dist_srcdir="$(mktemp -d)"
327 cd "$dist_srcdir"
c56b9301 328
b8475d72
MJ
329 # Extract the distribution tar in the new source directory,
330 # ignore the first directory level
331 $TAR xvf "$builddir"/*.tar.* --strip 1
332
333 # Create and enter a second temporary build directory
334 builddir="$(mktemp -d)"
335 cd "$builddir"
336
337 # Run configure from the extracted distribution tar,
338 # out of the source tree
07dafe32 339 "$dist_srcdir/configure" "${CONF_OPTS[@]}"
b8475d72
MJ
340 ;;
341
342*)
343 echo "Standard in-tree build"
07dafe32 344 ./configure "${CONF_OPTS[@]}"
b8475d72 345 ;;
aad6ac90
JR
346esac
347
1f620ba0
MJ
348# We are now inside a configured build directory
349
c56b9301 350# BUILD!
a57a60d9 351$MAKE -j "$($NPROC)" V=1
07dafe32 352
897eb548
MJ
353# Force rebase DLL address mapping
354if [ "${rebase_dll:-}" == "1" ]; then
355 find . -name "*.dll" | xargs rebase -O -v
356fi
357
07dafe32
MJ
358# Install in the workspace
359$MAKE install DESTDIR="$WORKSPACE"
c56b9301 360
9d56171a 361# Run tests, don't fail now, we want to run the archiving steps
1d56e325
MJ
362failed_tests=0
363$MAKE --keep-going check || failed_tests=1
c56b9301 364
1f620ba0 365# Copy tap logs for the jenkins tap parser before cleaning the build dir
e6be9fb0
MJ
366rsync -a --exclude 'test-suite.log' --include '*/' --include '*.log' --exclude='*' tests/ "$WORKSPACE/tap"
367
649c39a6
MJ
368# The test suite prior to 1.5 did not produce TAP logs
369if verlt "$PACKAGE_VERSION" "1.5"; then
370 mkdir -p "$WORKSPACE/tap/no-log"
371 echo "1..1" > "$WORKSPACE/tap/no-log/tests.log"
372 echo "ok 1 - Test suite doesn't support logging" >> "$WORKSPACE/tap/no-log/tests.log"
373fi
374
e6be9fb0
MJ
375# Clean the build directory
376$MAKE clean
275b59d2 377
c56b9301 378# Cleanup rpath in executables and shared libraries
07dafe32
MJ
379find "$WORKSPACE/$PREFIX/bin" -type f -perm -0500 -exec chrpath --delete {} \;
380find "$WORKSPACE/$PREFIX/lib" -name "*.so" -exec chrpath --delete {} \;
c56b9301
MJ
381
382# Remove libtool .la files
07dafe32 383find "$WORKSPACE/$PREFIX/lib" -name "*.la" -exec rm -f {} \;
87e41bca 384
1d56e325
MJ
385# Exit with failure if any of the tests failed
386exit $failed_tests
9d56171a 387
87e41bca 388# EOF
This page took 0.045312 seconds and 4 git commands to generate.