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