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