jjb: babeltrace: prepare for ubuntu jammy upgrade
[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 platform=${platform:-}
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-*)
112 export CC=gcc-${cc#gcc-}
113 export CXX=g++-${cc#gcc-}
114 ;;
115 clang)
116 export CC=clang
117 export CXX=clang++
118 ;;
119 clang-*)
120 export CC=clang-${cc#clang-}
121 export CXX=clang++-${cc#clang-}
122 ;;
123 *)
124 if [ "x$cc" != "x" ]; then
125 export CC="$cc"
126 fi
127 ;;
128 esac
129
130 if [ "x${CC:-}" != "x" ]; then
131 echo "Selected compiler:"
132 "$CC" -v
133 fi
134
135 # Set platform variables
136 case "$platform" in
137 macos*)
138 export MAKE=make
139 export TAR=tar
140 export NPROC="getconf _NPROCESSORS_ONLN"
141 export PATH="/opt/local/bin:/opt/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"
142 export CPPFLAGS="-I/opt/local/include"
143 export LDFLAGS="-L/opt/local/lib"
144 export PYTHON="python3.9"
145 export PYTHON_CONFIG="python3.9-config"
146 ;;
147
148 freebsd*)
149 export MAKE=gmake
150 export TAR=tar
151 export NPROC="getconf _NPROCESSORS_ONLN"
152 export CPPFLAGS="-I/usr/local/include"
153 export LDFLAGS="-L/usr/local/lib"
154 export PYTHON="python3"
155 export PYTHON_CONFIG="python3-config"
156
157 # For bt 1.5
158 export YACC="bison -y"
159 ;;
160
161 *)
162 export MAKE=make
163 export TAR=tar
164 export NPROC=nproc
165 export PYTHON="python3"
166 export PYTHON_CONFIG="python3-config"
167 ;;
168 esac
169
170 # Print build env details
171 print_os || true
172 print_tooling || true
173
174 # Enter the source directory
175 cd "$SRCDIR"
176
177 # Run bootstrap in the source directory prior to configure
178 ./bootstrap
179
180 # Get source version from configure script
181 eval "$(grep '^PACKAGE_VERSION=' ./configure)"
182 PACKAGE_VERSION=${PACKAGE_VERSION//\-pre*/}
183
184 # Enable dev mode by default for BT 2.0 builds
185 export BABELTRACE_DEBUG_MODE=1
186 export BABELTRACE_DEV_MODE=1
187 export BABELTRACE_MINIMAL_LOG_LEVEL=TRACE
188
189 # Set configure options and environment variables for each build
190 # configuration.
191 CONF_OPTS=("--prefix=$PREFIX")
192
193 # -Werror is enabled by default in stable-2.0 but won't be in 2.1
194 # Explicitly disable it for consistency.
195 if vergte "$PACKAGE_VERSION" "2.0"; then
196 CONF_OPTS+=("--disable-Werror")
197 fi
198
199 case "$conf" in
200 static)
201 echo "Static lib only configuration"
202
203 CONF_OPTS+=("--enable-static" "--disable-shared")
204
205 if vergte "$PACKAGE_VERSION" "2.0"; then
206 CONF_OPTS+=("--enable-built-in-plugins")
207 fi
208 ;;
209
210 python-bindings)
211 echo "Python bindings configuration"
212
213 CONF_OPTS+=("--enable-python-bindings")
214
215 if vergte "$PACKAGE_VERSION" "2.0"; then
216 CONF_OPTS+=("--enable-python-bindings-doc" "--enable-python-plugins")
217 fi
218 ;;
219
220 prod)
221 echo "Production configuration"
222
223 # Unset the developper variables
224 unset BABELTRACE_DEBUG_MODE
225 unset BABELTRACE_DEV_MODE
226 unset BABELTRACE_MINIMAL_LOG_LEVEL
227
228 # Enable the python bindings
229 CONF_OPTS+=("--enable-python-bindings" "--enable-python-plugins")
230 ;;
231
232 doc)
233 echo "Documentation configuration"
234
235 CONF_OPTS+=("--enable-python-bindings" "--enable-python-bindings-doc" "--enable-python-plugins" "--enable-api-doc")
236 ;;
237
238 min)
239 echo "Minimal configuration"
240 ;;
241
242 *)
243 echo "Standard configuration"
244
245 # Enable the python bindings / plugins by default with babeltrace2,
246 # the test suite is mostly useless without it.
247 if vergte "$PACKAGE_VERSION" "2.0"; then
248 CONF_OPTS+=("--enable-python-bindings" "--enable-python-plugins")
249 fi
250 ;;
251 esac
252
253 # Build type
254 # oot : out-of-tree build
255 # dist : build via make dist
256 # oot-dist: build via make dist out-of-tree
257 # * : normal tree build
258 #
259 # Make sure to move to the build directory and run configure
260 # before continuing.
261 case "$build" in
262 oot)
263 echo "Out of tree build"
264
265 # Create and enter a temporary build directory
266 builddir=$(mktemp -d)
267 cd "$builddir"
268
269 "$SRCDIR/configure" "${CONF_OPTS[@]}" || failed_configure
270 ;;
271
272 dist)
273 echo "Distribution in-tree build"
274
275 # Run configure and generate the tar file
276 # in the source directory
277 ./configure || failed_configure
278 $MAKE dist
279
280 # Create and enter a temporary build directory
281 builddir=$(mktemp -d)
282 cd "$builddir"
283
284 # Extract the distribution tar in the build directory,
285 # ignore the first directory level
286 $TAR xvf "$SRCDIR"/*.tar.* --strip 1
287
288 # Build in extracted source tree
289 ./configure "${CONF_OPTS[@]}" || failed_configure
290 ;;
291
292 oot-dist)
293 echo "Distribution out of tree build"
294
295 # Create and enter a temporary build directory
296 builddir=$(mktemp -d)
297 cd "$builddir"
298
299 # Run configure out of tree and generate the tar file
300 "$SRCDIR/configure" || failed_configure
301 $MAKE dist
302
303 dist_srcdir="$(mktemp -d)"
304 cd "$dist_srcdir"
305
306 # Extract the distribution tar in the new source directory,
307 # ignore the first directory level
308 $TAR xvf "$builddir"/*.tar.* --strip 1
309
310 # Create and enter a second temporary build directory
311 builddir="$(mktemp -d)"
312 cd "$builddir"
313
314 # Run configure from the extracted distribution tar,
315 # out of the source tree
316 "$dist_srcdir/configure" "${CONF_OPTS[@]}" || failed_configure
317 ;;
318
319 *)
320 echo "Standard in-tree build"
321 ./configure "${CONF_OPTS[@]}" || failed_configure
322 ;;
323 esac
324
325 # We are now inside a configured build directory
326
327 # BUILD!
328 $MAKE -j "$($NPROC)" V=1
329
330 # Install in the workspace
331 $MAKE install DESTDIR="$WORKSPACE"
332
333 # Run tests, don't fail now, we want to run the archiving steps
334 failed_tests=0
335 if [ "$BABELTRACE_RUN_TESTS" = "yes" ]; then
336 $MAKE --keep-going check || failed_tests=1
337
338 # Copy tap logs for the jenkins tap parser before cleaning the build dir
339 rsync -a --exclude 'test-suite.log' --include '*/' --include '*.log' --exclude='*' tests/ "$WORKSPACE/tap"
340
341 # The test suite prior to 1.5 did not produce TAP logs
342 if verlt "$PACKAGE_VERSION" "1.5"; then
343 mkdir -p "$WORKSPACE/tap/no-log"
344 echo "1..1" > "$WORKSPACE/tap/no-log/tests.log"
345 echo "ok 1 - Test suite doesn't support logging" >> "$WORKSPACE/tap/no-log/tests.log"
346 fi
347 fi
348
349 # Clean the build directory
350 $MAKE clean
351
352 # Cleanup rpath in executables and shared libraries
353 find "$WORKSPACE/$PREFIX/bin" -type f -perm -0500 -exec chrpath --delete {} \;
354 find "$WORKSPACE/$PREFIX/lib" -name "*.so" -exec chrpath --delete {} \;
355
356 # Remove libtool .la files
357 find "$WORKSPACE/$PREFIX/lib" -name "*.la" -exec rm -f {} \;
358
359 # Exit with failure if any of the tests failed
360 exit $failed_tests
361
362 # EOF
This page took 0.037261 seconds and 5 git commands to generate.