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