jjb: Remove deprecated stable-2.7 jobs, except sles12
[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:-}
76
c56b9301 77
e6be9fb0
MJ
78SRCDIR="$WORKSPACE/src/babeltrace"
79TMPDIR="$WORKSPACE/tmp"
275b59d2
JRJ
80PREFIX="$WORKSPACE/build"
81
e6be9fb0
MJ
82# Create build and tmp directories
83rm -rf "$PREFIX" "$TMPDIR"
84mkdir -p "$PREFIX" "$TMPDIR"
85
0e9967db 86export TMPDIR
72d087d4 87export CFLAGS="-g -O2"
0e9967db 88
c56b9301 89# Set platform variables
87e41bca 90case "$arch" in
a0b535b2
MJ
91sol10-i386)
92 export MAKE=gmake
93 export TAR=gtar
94 export NPROC=gnproc
95 export BISON=bison
96 export YACC="$BISON -y"
ad11244c 97 export PATH="/opt/csw/bin:/usr/ccs/bin:$PATH"
a0b535b2
MJ
98 export CPPFLAGS="-I/opt/csw/include"
99 export LDFLAGS="-L/opt/csw/lib -R/opt/csw/lib"
100 export PKG_CONFIG_PATH="/opt/csw/lib/pkgconfig"
87e41bca 101 ;;
a0b535b2
MJ
102sol11-i386)
103 export MAKE=gmake
104 export TAR=gtar
105 export NPROC=nproc
87e41bca 106 export PATH="$PATH:/usr/perl5/bin"
cd808c9e
MJ
107 export LD_ALTEXEC=/usr/bin/gld
108 export LD=/usr/bin/gld
87e41bca 109 ;;
221450b6 110macosx)
a0b535b2
MJ
111 export MAKE=make
112 export TAR=tar
113 export NPROC="getconf _NPROCESSORS_ONLN"
114 export BISON="bison"
115 export YACC="$BISON -y"
221450b6 116 export PATH="/opt/local/bin:/opt/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"
72d087d4 117 export CFLAGS="$CFLAGS -I/opt/local/include"
221450b6
MJ
118 export LDFLAGS="-L/opt/local/lib"
119 ;;
87e41bca 120*)
a0b535b2
MJ
121 export MAKE=make
122 export TAR=tar
123 export NPROC=nproc
87e41bca
MJ
124 ;;
125esac
126
a0b535b2
MJ
127# Enter the source directory
128cd "$SRCDIR"
129
130# Run bootstrap in the source directory prior to configure
131./bootstrap
132
133# Get source version from configure script
134eval "$(grep '^PACKAGE_VERSION=' ./configure)"
135
c56b9301
MJ
136# Set configure options for each build configuration
137CONF_OPTS=""
275b59d2
JRJ
138case "$conf" in
139static)
140 echo "Static build"
141 CONF_OPTS="--enable-static --disable-shared"
a0b535b2
MJ
142 if vergte "$PACKAGE_VERSION" "2.0"; then
143 CONF_OPTS="${CONF_OPTS} --enable-built-in-plugins"
144 fi
275b59d2 145 ;;
221450b6 146python-bindings)
275b59d2
JRJ
147 echo "Build with python bindings"
148 # We only support bindings built with Python 3
149 export PYTHON="python3"
150 export PYTHON_CONFIG="/usr/bin/python3-config"
151 CONF_OPTS="--enable-python-bindings"
a0b535b2
MJ
152
153 if vergte "$PACKAGE_VERSION" "2.0"; then
1ed70cbb 154 CONF_OPTS="${CONF_OPTS} --enable-python-bindings-doc --enable-python-plugins"
a0b535b2 155 fi
275b59d2
JRJ
156 ;;
157*)
158 echo "Standard build"
159 CONF_OPTS=""
160 ;;
161esac
162
aad6ac90
JR
163# Build type
164# oot : out-of-tree build
165# dist: build via make dist
166# * : normal tree build
167#
168# Make sure to move to the build_path and configure
169# before continuing
e6be9fb0 170BUILD_PATH="$SRCDIR"
aad6ac90 171case "$build" in
c56b9301
MJ
172 oot)
173 echo "Out of tree build"
944a6c86
MJ
174 BUILD_PATH="$WORKSPACE/oot"
175 mkdir -p "$BUILD_PATH"
176 cd "$BUILD_PATH"
a0b535b2 177 "$SRCDIR/configure" --prefix="$PREFIX" $CONF_OPTS
c56b9301
MJ
178 ;;
179
180 dist)
181 echo "Distribution out of tree build"
a57a60d9 182 BUILD_PATH="$(mktemp -d)"
c56b9301
MJ
183
184 # Initial configure and generate tarball
a0b535b2 185 "$SRCDIR/configure"
c56b9301
MJ
186 $MAKE dist
187
944a6c86
MJ
188 mkdir -p "$BUILD_PATH"
189 cp ./*.tar.* "$BUILD_PATH/"
190 cd "$BUILD_PATH"
c56b9301
MJ
191
192 # Ignore level 1 of tar
944a6c86 193 $TAR xvf ./*.tar.* --strip 1
c56b9301 194
a0b535b2 195 "$BUILD_PATH/configure" --prefix="$PREFIX" $CONF_OPTS
c56b9301
MJ
196 ;;
197
0628a9d8
MJ
198 clang)
199 echo "LLVM clang build"
200 export CC=clang
201 clang -v
a0b535b2 202 "$SRCDIR/configure" --prefix="$PREFIX" $CONF_OPTS
0628a9d8
MJ
203 ;;
204 *)
e6be9fb0 205 echo "Standard in-tree build"
a0b535b2 206 "$SRCDIR/configure" --prefix="$PREFIX" $CONF_OPTS
c56b9301 207 ;;
aad6ac90
JR
208esac
209
c56b9301 210# BUILD!
a57a60d9 211$MAKE -j "$($NPROC)" V=1
87e41bca 212$MAKE install
c56b9301
MJ
213
214# Run tests
6827c67a 215$MAKE --keep-going check
c56b9301 216
e6be9fb0
MJ
217# Copy tap logs for the jenkins tap parser
218rsync -a --exclude 'test-suite.log' --include '*/' --include '*.log' --exclude='*' tests/ "$WORKSPACE/tap"
219
220# Clean the build directory
221$MAKE clean
275b59d2 222
c56b9301 223# Cleanup rpath in executables and shared libraries
944a6c86
MJ
224find "$PREFIX/bin" -type f -perm -0500 -exec chrpath --delete {} \;
225find "$PREFIX/lib" -name "*.so" -exec chrpath --delete {} \;
c56b9301
MJ
226
227# Remove libtool .la files
944a6c86 228find "$PREFIX/lib" -name "*.la" -exec rm -f {} \;
aad6ac90 229
c56b9301
MJ
230# Clean temp dir for dist build
231if [ "$build" = "dist" ]; then
944a6c86
MJ
232 cd "$SRCDIR"
233 rm -rf "$BUILD_PATH"
aad6ac90 234fi
87e41bca
MJ
235
236# EOF
This page took 0.063031 seconds and 4 git commands to generate.