gerrit: bt2: add dev and prod mode
[lttng-ci.git] / scripts / babeltrace / build.sh
CommitLineData
c56b9301 1#!/bin/bash -exu
890bff23
MJ
2#
3# Copyright (C) 2015 - Jonathan Rajotte-Julien <jonathan.rajotte-julien@efficios.com>
0e9967db 4# 2016 - 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
a57a60d9
MJ
72# Required parameters
73arch=${arch:-}
74conf=${conf:-}
75build=${build:-}
6476f917 76cc=${cc:-}
10bbe356 77bt2_mode=${bt2_mode:-}
a57a60d9 78
c56b9301 79
e6be9fb0
MJ
80SRCDIR="$WORKSPACE/src/babeltrace"
81TMPDIR="$WORKSPACE/tmp"
275b59d2
JRJ
82PREFIX="$WORKSPACE/build"
83
e6be9fb0
MJ
84# Create build and tmp directories
85rm -rf "$PREFIX" "$TMPDIR"
86mkdir -p "$PREFIX" "$TMPDIR"
87
0e9967db 88export TMPDIR
72d087d4 89export CFLAGS="-g -O2"
0e9967db 90
6476f917
MJ
91# Set compiler variables
92case "$cc" in
93gcc)
94 export CC=gcc
95 export CXX=g++
96 ;;
97gcc-4.8)
98 export CC=gcc-4.8
99 export CXX=g++-4.8
100 ;;
101gcc-5)
102 export CC=gcc-5
103 export CXX=g++-5
104 ;;
105gcc-6)
106 export CC=gcc-6
107 export CXX=g++-6
108 ;;
109gcc-7)
110 export CC=gcc-7
111 export CXX=g++-7
112 ;;
113gcc-8)
114 export CC=gcc-8
115 export CXX=g++-8
116 ;;
117clang)
118 export CC=clang
119 export CXX=clang++
120 ;;
121clang-3.9)
122 export CC=clang-3.9
123 export CXX=clang++-3.9
124 ;;
125clang-4.0)
126 export CC=clang-4.0
127 export CXX=clang++-4.0
128 ;;
129clang-5.0)
130 export CC=clang-5.0
131 export CXX=clang++-5.0
132 ;;
133clang-6.0)
134 export CC=clang-6.0
135 export CXX=clang++-6.0
136 ;;
137clang-7)
138 export CC=clang-7
139 export CXX=clang++-7
140 ;;
141*)
142 if [ "x$cc" != "x" ]; then
143 export CC="$cc"
144 fi
145 ;;
146esac
147
1183a118 148if [ "x${CC:-}" != "x" ]; then
6476f917
MJ
149 echo "Selected compiler:"
150 "$CC" -v
151fi
152
c56b9301 153# Set platform variables
87e41bca 154case "$arch" in
a0b535b2
MJ
155sol10-i386)
156 export MAKE=gmake
157 export TAR=gtar
158 export NPROC=gnproc
159 export BISON=bison
160 export YACC="$BISON -y"
ad11244c 161 export PATH="/opt/csw/bin:/usr/ccs/bin:$PATH"
a0b535b2
MJ
162 export CPPFLAGS="-I/opt/csw/include"
163 export LDFLAGS="-L/opt/csw/lib -R/opt/csw/lib"
164 export PKG_CONFIG_PATH="/opt/csw/lib/pkgconfig"
87e41bca 165 ;;
a0b535b2
MJ
166sol11-i386)
167 export MAKE=gmake
168 export TAR=gtar
169 export NPROC=nproc
87e41bca 170 export PATH="$PATH:/usr/perl5/bin"
cd808c9e
MJ
171 export LD_ALTEXEC=/usr/bin/gld
172 export LD=/usr/bin/gld
87e41bca 173 ;;
221450b6 174macosx)
a0b535b2
MJ
175 export MAKE=make
176 export TAR=tar
177 export NPROC="getconf _NPROCESSORS_ONLN"
178 export BISON="bison"
179 export YACC="$BISON -y"
221450b6 180 export PATH="/opt/local/bin:/opt/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"
72d087d4 181 export CFLAGS="$CFLAGS -I/opt/local/include"
221450b6
MJ
182 export LDFLAGS="-L/opt/local/lib"
183 ;;
87e41bca 184*)
a0b535b2
MJ
185 export MAKE=make
186 export TAR=tar
187 export NPROC=nproc
87e41bca
MJ
188 ;;
189esac
190
a0b535b2
MJ
191# Enter the source directory
192cd "$SRCDIR"
193
194# Run bootstrap in the source directory prior to configure
195./bootstrap
196
197# Get source version from configure script
198eval "$(grep '^PACKAGE_VERSION=' ./configure)"
199
11ba7264 200# Enable dev mode by default for BT 2.0 builds
10bbe356
JR
201case "$bt2_mode" in
202dev)
203 echo "Developer mode"
204 export BABELTRACE_DEBUG_MODE=1
205 export BABELTRACE_DEV_MODE=1
206 export BABELTRACE_MINIMAL_LOG_LEVEL=VERBOSE
207 ;;
208*)
209 echo "Production mode (Default)"
210 export BABELTRACE_MINIMAL_LOG_LEVEL=INFO
211 ;;
212esac
11ba7264 213
c56b9301
MJ
214# Set configure options for each build configuration
215CONF_OPTS=""
275b59d2
JRJ
216case "$conf" in
217static)
218 echo "Static build"
219 CONF_OPTS="--enable-static --disable-shared"
a0b535b2
MJ
220 if vergte "$PACKAGE_VERSION" "2.0"; then
221 CONF_OPTS="${CONF_OPTS} --enable-built-in-plugins"
222 fi
275b59d2 223 ;;
221450b6 224python-bindings)
275b59d2
JRJ
225 echo "Build with python bindings"
226 # We only support bindings built with Python 3
227 export PYTHON="python3"
228 export PYTHON_CONFIG="/usr/bin/python3-config"
229 CONF_OPTS="--enable-python-bindings"
a0b535b2
MJ
230
231 if vergte "$PACKAGE_VERSION" "2.0"; then
1ed70cbb 232 CONF_OPTS="${CONF_OPTS} --enable-python-bindings-doc --enable-python-plugins"
a0b535b2 233 fi
275b59d2
JRJ
234 ;;
235*)
236 echo "Standard build"
237 CONF_OPTS=""
238 ;;
239esac
240
aad6ac90
JR
241# Build type
242# oot : out-of-tree build
243# dist: build via make dist
244# * : normal tree build
245#
246# Make sure to move to the build_path and configure
247# before continuing
e6be9fb0 248BUILD_PATH="$SRCDIR"
aad6ac90 249case "$build" in
c56b9301
MJ
250 oot)
251 echo "Out of tree build"
944a6c86
MJ
252 BUILD_PATH="$WORKSPACE/oot"
253 mkdir -p "$BUILD_PATH"
254 cd "$BUILD_PATH"
a0b535b2 255 "$SRCDIR/configure" --prefix="$PREFIX" $CONF_OPTS
c56b9301
MJ
256 ;;
257
258 dist)
259 echo "Distribution out of tree build"
a57a60d9 260 BUILD_PATH="$(mktemp -d)"
c56b9301
MJ
261
262 # Initial configure and generate tarball
a0b535b2 263 "$SRCDIR/configure"
c56b9301
MJ
264 $MAKE dist
265
944a6c86
MJ
266 mkdir -p "$BUILD_PATH"
267 cp ./*.tar.* "$BUILD_PATH/"
268 cd "$BUILD_PATH"
c56b9301
MJ
269
270 # Ignore level 1 of tar
944a6c86 271 $TAR xvf ./*.tar.* --strip 1
c56b9301 272
a0b535b2 273 "$BUILD_PATH/configure" --prefix="$PREFIX" $CONF_OPTS
c56b9301
MJ
274 ;;
275
0628a9d8 276 *)
e6be9fb0 277 echo "Standard in-tree build"
a0b535b2 278 "$SRCDIR/configure" --prefix="$PREFIX" $CONF_OPTS
c56b9301 279 ;;
aad6ac90
JR
280esac
281
c56b9301 282# BUILD!
a57a60d9 283$MAKE -j "$($NPROC)" V=1
87e41bca 284$MAKE install
c56b9301
MJ
285
286# Run tests
6827c67a 287$MAKE --keep-going check
c56b9301 288
e6be9fb0
MJ
289# Copy tap logs for the jenkins tap parser
290rsync -a --exclude 'test-suite.log' --include '*/' --include '*.log' --exclude='*' tests/ "$WORKSPACE/tap"
291
292# Clean the build directory
293$MAKE clean
275b59d2 294
c56b9301 295# Cleanup rpath in executables and shared libraries
944a6c86
MJ
296find "$PREFIX/bin" -type f -perm -0500 -exec chrpath --delete {} \;
297find "$PREFIX/lib" -name "*.so" -exec chrpath --delete {} \;
c56b9301
MJ
298
299# Remove libtool .la files
944a6c86 300find "$PREFIX/lib" -name "*.la" -exec rm -f {} \;
aad6ac90 301
c56b9301
MJ
302# Clean temp dir for dist build
303if [ "$build" = "dist" ]; then
944a6c86
MJ
304 cd "$SRCDIR"
305 rm -rf "$BUILD_PATH"
aad6ac90 306fi
87e41bca
MJ
307
308# EOF
This page took 0.049957 seconds and 4 git commands to generate.