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