jjb: tools: depends-on: support babeltrace
[lttng-ci.git] / scripts / babeltrace / build.sh
1 #!/bin/bash
2 #
3 # Copyright (C) 2015 Jonathan Rajotte-Julien <jonathan.rajotte-julien@efficios.com>
4 # Copyright (C) 2016-2020 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 set -exu
20
21 # Version compare functions
22 vercomp () {
23 set +u
24 if [[ "$1" == "$2" ]]; then
25 return 0
26 fi
27 local IFS=.
28 local i ver1=($1) ver2=($2)
29 # fill empty fields in ver1 with zeros
30 for ((i=${#ver1[@]}; i<${#ver2[@]}; i++)); do
31 ver1[i]=0
32 done
33 for ((i=0; i<${#ver1[@]}; i++)); do
34 if [[ -z ${ver2[i]} ]]; then
35 # fill empty fields in ver2 with zeros
36 ver2[i]=0
37 fi
38 if ((10#${ver1[i]} > 10#${ver2[i]})); then
39 return 1
40 fi
41 if ((10#${ver1[i]} < 10#${ver2[i]})); then
42 return 2
43 fi
44 done
45 set -u
46 return 0
47 }
48
49 verlte() {
50 vercomp "$1" "$2"; local res="$?"
51 [ "$res" -eq "0" ] || [ "$res" -eq "2" ]
52 }
53
54 verlt() {
55 vercomp "$1" "$2"; local res="$?"
56 [ "$res" -eq "2" ]
57 }
58
59 vergte() {
60 vercomp "$1" "$2"; local res="$?"
61 [ "$res" -eq "0" ] || [ "$res" -eq "1" ]
62 }
63
64 vergt() {
65 vercomp "$1" "$2"; local res="$?"
66 [ "$res" -eq "1" ]
67 }
68
69 verne() {
70 vercomp "$1" "$2"; local res="$?"
71 [ "$res" -ne "0" ]
72 }
73
74 failed_configure() {
75 # Assume we are in the configured build directory
76 echo "#################### BEGIN config.log ####################"
77 cat config.log
78 echo "#################### END config.log ####################"
79 exit 1
80 }
81
82
83 # Required variables
84 WORKSPACE=${WORKSPACE:-}
85
86 arch=${arch:-}
87 conf=${conf:-}
88 build=${build:-}
89 cc=${cc:-}
90
91 # Controls if the tests are run
92 BABELTRACE_RUN_TESTS="${BABELTRACE_RUN_TESTS:=yes}"
93
94 SRCDIR="$WORKSPACE/src/babeltrace"
95 TMPDIR="$WORKSPACE/tmp"
96 PREFIX="/build"
97
98 # Create tmp directory
99 rm -rf "$TMPDIR"
100 mkdir -p "$TMPDIR"
101
102 export TMPDIR
103 export CFLAGS="-g -O2"
104
105 # Set compiler variables
106 case "$cc" in
107 gcc)
108 export CC=gcc
109 export CXX=g++
110 ;;
111 gcc-4.8)
112 export CC=gcc-4.8
113 export CXX=g++-4.8
114 ;;
115 gcc-5)
116 export CC=gcc-5
117 export CXX=g++-5
118 ;;
119 gcc-6)
120 export CC=gcc-6
121 export CXX=g++-6
122 ;;
123 gcc-7)
124 export CC=gcc-7
125 export CXX=g++-7
126 ;;
127 gcc-8)
128 export CC=gcc-8
129 export CXX=g++-8
130 ;;
131 clang)
132 export CC=clang
133 export CXX=clang++
134 ;;
135 clang-3.9)
136 export CC=clang-3.9
137 export CXX=clang++-3.9
138 ;;
139 clang-4.0)
140 export CC=clang-4.0
141 export CXX=clang++-4.0
142 ;;
143 clang-5.0)
144 export CC=clang-5.0
145 export CXX=clang++-5.0
146 ;;
147 clang-6.0)
148 export CC=clang-6.0
149 export CXX=clang++-6.0
150 ;;
151 clang-7)
152 export CC=clang-7
153 export CXX=clang++-7
154 ;;
155 *)
156 if [ "x$cc" != "x" ]; then
157 export CC="$cc"
158 fi
159 ;;
160 esac
161
162 if [ "x${CC:-}" != "x" ]; then
163 echo "Selected compiler:"
164 "$CC" -v
165 fi
166
167 # Set platform variables
168 case "$arch" in
169 sol10-i386)
170 export MAKE=gmake
171 export TAR=gtar
172 export NPROC=gnproc
173 export PATH="/opt/csw/bin:/usr/ccs/bin:$PATH"
174 export CPPFLAGS="-I/opt/csw/include"
175 export LDFLAGS="-L/opt/csw/lib -R/opt/csw/lib"
176 export PKG_CONFIG_PATH="/opt/csw/lib/pkgconfig"
177 export PYTHON="python3"
178 export PYTHON_CONFIG="python3-config"
179 ;;
180
181 sol11-i386)
182 export MAKE=gmake
183 export TAR=gtar
184 export NPROC=nproc
185 export PATH="/opt/csw/bin:$PATH:/usr/perl5/bin"
186 export LD_ALTEXEC=/usr/bin/gld
187 export LD=/usr/bin/gld
188 export PYTHON="python3"
189 export PYTHON_CONFIG="python3-config"
190 export PKG_CONFIG_PATH="/usr/lib/pkgconfig"
191 ;;
192
193 macos*)
194 export MAKE=make
195 export TAR=tar
196 export NPROC="getconf _NPROCESSORS_ONLN"
197 export PATH="/opt/local/bin:/opt/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"
198 export CPPFLAGS="-I/opt/local/include"
199 export LDFLAGS="-L/opt/local/lib"
200 export PYTHON="python3.9"
201 export PYTHON_CONFIG="python3.9-config"
202 ;;
203
204 cygwin)
205 export MAKE=make
206 export TAR=tar
207 export NPROC=nproc
208 export PYTHON="python3"
209 export PYTHON_CONFIG="python3-config"
210 rebase_dll=1
211 ;;
212
213 freebsd)
214 export MAKE=gmake
215 export TAR=tar
216 export NPROC="getconf _NPROCESSORS_ONLN"
217 export CPPFLAGS="-I/usr/local/include"
218 export LDFLAGS="-L/usr/local/lib"
219 export PYTHON="python3"
220 export PYTHON_CONFIG="python3-config"
221
222 # For bt 1.5
223 export YACC="bison -y"
224 ;;
225
226 *)
227 export MAKE=make
228 export TAR=tar
229 export NPROC=nproc
230 export PYTHON="python3"
231 export PYTHON_CONFIG="python3-config"
232 ;;
233 esac
234
235 # Print build env details
236 print_os || true
237 print_tooling || true
238
239 # Enter the source directory
240 cd "$SRCDIR"
241
242 # Run bootstrap in the source directory prior to configure
243 ./bootstrap
244
245 # Get source version from configure script
246 eval "$(grep '^PACKAGE_VERSION=' ./configure)"
247 PACKAGE_VERSION=${PACKAGE_VERSION//\-pre*/}
248
249 # Enable dev mode by default for BT 2.0 builds
250 export BABELTRACE_DEBUG_MODE=1
251 export BABELTRACE_DEV_MODE=1
252 export BABELTRACE_MINIMAL_LOG_LEVEL=TRACE
253
254 # Set configure options and environment variables for each build
255 # configuration.
256 CONF_OPTS=("--prefix=$PREFIX")
257
258 # -Werror is enabled by default in stable-2.0 but won't be in 2.1
259 # Explicitly disable it for consistency.
260 if vergte "$PACKAGE_VERSION" "2.0"; then
261 CONF_OPTS+=("--disable-Werror")
262 fi
263
264 case "$conf" in
265 static)
266 echo "Static lib only configuration"
267
268 CONF_OPTS+=("--enable-static" "--disable-shared")
269
270 if vergte "$PACKAGE_VERSION" "2.0"; then
271 CONF_OPTS+=("--enable-built-in-plugins")
272 fi
273 ;;
274
275 python-bindings)
276 echo "Python bindings configuration"
277
278 CONF_OPTS+=("--enable-python-bindings")
279
280 if vergte "$PACKAGE_VERSION" "2.0"; then
281 CONF_OPTS+=("--enable-python-bindings-doc" "--enable-python-plugins")
282 fi
283 ;;
284
285 prod)
286 echo "Production configuration"
287
288 # Unset the developper variables
289 unset BABELTRACE_DEBUG_MODE
290 unset BABELTRACE_DEV_MODE
291 unset BABELTRACE_MINIMAL_LOG_LEVEL
292
293 # Enable the python bindings
294 CONF_OPTS+=("--enable-python-bindings" "--enable-python-bindings-doc" "--enable-python-plugins")
295 ;;
296
297 min)
298 echo "Minimal configuration"
299 ;;
300
301 *)
302 echo "Standard configuration"
303
304 # Enable the python bindings / plugins by default with babeltrace2,
305 # the test suite is mostly useless without it.
306 if vergte "$PACKAGE_VERSION" "2.0"; then
307 CONF_OPTS+=("--enable-python-bindings" "--enable-python-plugins")
308 fi
309 ;;
310 esac
311
312 # Build type
313 # oot : out-of-tree build
314 # dist : build via make dist
315 # oot-dist: build via make dist out-of-tree
316 # * : normal tree build
317 #
318 # Make sure to move to the build directory and run configure
319 # before continuing.
320 case "$build" in
321 oot)
322 echo "Out of tree build"
323
324 # Create and enter a temporary build directory
325 builddir=$(mktemp -d)
326 cd "$builddir"
327
328 "$SRCDIR/configure" "${CONF_OPTS[@]}" || failed_configure
329 ;;
330
331 dist)
332 echo "Distribution in-tree build"
333
334 # Run configure and generate the tar file
335 # in the source directory
336 ./configure || failed_configure
337 $MAKE dist
338
339 # Create and enter a temporary build directory
340 builddir=$(mktemp -d)
341 cd "$builddir"
342
343 # Extract the distribution tar in the build directory,
344 # ignore the first directory level
345 $TAR xvf "$SRCDIR"/*.tar.* --strip 1
346
347 # Build in extracted source tree
348 ./configure "${CONF_OPTS[@]}" || failed_configure
349 ;;
350
351 oot-dist)
352 echo "Distribution out of tree build"
353
354 # Create and enter a temporary build directory
355 builddir=$(mktemp -d)
356 cd "$builddir"
357
358 # Run configure out of tree and generate the tar file
359 "$SRCDIR/configure" || failed_configure
360 $MAKE dist
361
362 dist_srcdir="$(mktemp -d)"
363 cd "$dist_srcdir"
364
365 # Extract the distribution tar in the new source directory,
366 # ignore the first directory level
367 $TAR xvf "$builddir"/*.tar.* --strip 1
368
369 # Create and enter a second temporary build directory
370 builddir="$(mktemp -d)"
371 cd "$builddir"
372
373 # Run configure from the extracted distribution tar,
374 # out of the source tree
375 "$dist_srcdir/configure" "${CONF_OPTS[@]}" || failed_configure
376 ;;
377
378 *)
379 echo "Standard in-tree build"
380 ./configure "${CONF_OPTS[@]}" || failed_configure
381 ;;
382 esac
383
384 # We are now inside a configured build directory
385
386 # BUILD!
387 $MAKE -j "$($NPROC)" V=1
388
389 # Force rebase DLL address mapping
390 if [ "${rebase_dll:-}" == "1" ]; then
391 find . -name "*.dll" -print0 | xargs -0 rebase -O -v
392 fi
393
394 # Install in the workspace
395 $MAKE install DESTDIR="$WORKSPACE"
396
397 # Run tests, don't fail now, we want to run the archiving steps
398 failed_tests=0
399 if [ "$BABELTRACE_RUN_TESTS" = "yes" ]; then
400 $MAKE --keep-going check || failed_tests=1
401
402 # Copy tap logs for the jenkins tap parser before cleaning the build dir
403 rsync -a --exclude 'test-suite.log' --include '*/' --include '*.log' --exclude='*' tests/ "$WORKSPACE/tap"
404
405 # The test suite prior to 1.5 did not produce TAP logs
406 if verlt "$PACKAGE_VERSION" "1.5"; then
407 mkdir -p "$WORKSPACE/tap/no-log"
408 echo "1..1" > "$WORKSPACE/tap/no-log/tests.log"
409 echo "ok 1 - Test suite doesn't support logging" >> "$WORKSPACE/tap/no-log/tests.log"
410 fi
411 fi
412
413 # Clean the build directory
414 $MAKE clean
415
416 # Cleanup rpath in executables and shared libraries
417 find "$WORKSPACE/$PREFIX/bin" -type f -perm -0500 -exec chrpath --delete {} \;
418 find "$WORKSPACE/$PREFIX/lib" -name "*.so" -exec chrpath --delete {} \;
419
420 # Remove libtool .la files
421 find "$WORKSPACE/$PREFIX/lib" -name "*.la" -exec rm -f {} \;
422
423 # Exit with failure if any of the tests failed
424 exit $failed_tests
425
426 # EOF
This page took 0.040199 seconds and 5 git commands to generate.