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 | |
e3c32202 JR |
91 | # Controls if the tests are run |
92 | BABELTRACE_RUN_TESTS="${BABELTRACE_RUN_TESTS:=yes}" | |
c56b9301 | 93 | |
e6be9fb0 MJ |
94 | SRCDIR="$WORKSPACE/src/babeltrace" |
95 | TMPDIR="$WORKSPACE/tmp" | |
07dafe32 | 96 | PREFIX="/build" |
275b59d2 | 97 | |
07dafe32 MJ |
98 | # Create tmp directory |
99 | rm -rf "$TMPDIR" | |
100 | mkdir -p "$TMPDIR" | |
e6be9fb0 | 101 | |
0e9967db | 102 | export TMPDIR |
72d087d4 | 103 | export CFLAGS="-g -O2" |
0e9967db | 104 | |
6476f917 MJ |
105 | # Set compiler variables |
106 | case "$cc" in | |
107 | gcc) | |
108 | export CC=gcc | |
109 | export CXX=g++ | |
110 | ;; | |
0f505d21 MJ |
111 | gcc-*) |
112 | export CC=gcc-${cc#gcc-} | |
113 | export CXX=g++-${cc#gcc-} | |
6476f917 MJ |
114 | ;; |
115 | clang) | |
116 | export CC=clang | |
117 | export CXX=clang++ | |
118 | ;; | |
0f505d21 MJ |
119 | clang-*) |
120 | export CC=clang-${cc#clang-} | |
121 | export CXX=clang++-${cc#clang-} | |
6476f917 MJ |
122 | ;; |
123 | *) | |
124 | if [ "x$cc" != "x" ]; then | |
125 | export CC="$cc" | |
126 | fi | |
127 | ;; | |
128 | esac | |
129 | ||
1183a118 | 130 | if [ "x${CC:-}" != "x" ]; then |
6476f917 MJ |
131 | echo "Selected compiler:" |
132 | "$CC" -v | |
133 | fi | |
134 | ||
c56b9301 | 135 | # Set platform variables |
87e41bca | 136 | case "$arch" in |
f0d7e5b1 | 137 | macos*) |
a0b535b2 MJ |
138 | export MAKE=make |
139 | export TAR=tar | |
140 | export NPROC="getconf _NPROCESSORS_ONLN" | |
221450b6 | 141 | export PATH="/opt/local/bin:/opt/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin" |
07dafe32 | 142 | export CPPFLAGS="-I/opt/local/include" |
221450b6 | 143 | export LDFLAGS="-L/opt/local/lib" |
0ef2148a MJ |
144 | export PYTHON="python3.9" |
145 | export PYTHON_CONFIG="python3.9-config" | |
221450b6 | 146 | ;; |
07dafe32 | 147 | |
0f505d21 | 148 | freebsd*) |
894db5f1 MJ |
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 | ||
87e41bca | 161 | *) |
a0b535b2 MJ |
162 | export MAKE=make |
163 | export TAR=tar | |
164 | export NPROC=nproc | |
1f620ba0 MJ |
165 | export PYTHON="python3" |
166 | export PYTHON_CONFIG="python3-config" | |
87e41bca MJ |
167 | ;; |
168 | esac | |
169 | ||
51c9c62d MJ |
170 | # Print build env details |
171 | print_os || true | |
172 | print_tooling || true | |
173 | ||
a0b535b2 MJ |
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)" | |
07dafe32 | 182 | PACKAGE_VERSION=${PACKAGE_VERSION//\-pre*/} |
a0b535b2 | 183 | |
11ba7264 | 184 | # Enable dev mode by default for BT 2.0 builds |
9201e00d MJ |
185 | export BABELTRACE_DEBUG_MODE=1 |
186 | export BABELTRACE_DEV_MODE=1 | |
8130d845 | 187 | export BABELTRACE_MINIMAL_LOG_LEVEL=TRACE |
11ba7264 | 188 | |
07dafe32 MJ |
189 | # Set configure options and environment variables for each build |
190 | # configuration. | |
191 | CONF_OPTS=("--prefix=$PREFIX") | |
f0d7e5b1 MJ |
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 | ||
275b59d2 JRJ |
199 | case "$conf" in |
200 | static) | |
1f620ba0 MJ |
201 | echo "Static lib only configuration" |
202 | ||
203 | CONF_OPTS+=("--enable-static" "--disable-shared") | |
204 | ||
a0b535b2 | 205 | if vergte "$PACKAGE_VERSION" "2.0"; then |
1f620ba0 | 206 | CONF_OPTS+=("--enable-built-in-plugins") |
a0b535b2 | 207 | fi |
275b59d2 | 208 | ;; |
1f620ba0 | 209 | |
221450b6 | 210 | python-bindings) |
1f620ba0 MJ |
211 | echo "Python bindings configuration" |
212 | ||
213 | CONF_OPTS+=("--enable-python-bindings") | |
a0b535b2 MJ |
214 | |
215 | if vergte "$PACKAGE_VERSION" "2.0"; then | |
1f620ba0 | 216 | CONF_OPTS+=("--enable-python-bindings-doc" "--enable-python-plugins") |
a0b535b2 | 217 | fi |
275b59d2 | 218 | ;; |
1f620ba0 | 219 | |
0d30552d | 220 | prod) |
1f620ba0 | 221 | echo "Production configuration" |
9201e00d MJ |
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 | |
1f620ba0 | 229 | CONF_OPTS+=("--enable-python-bindings" "--enable-python-bindings-doc" "--enable-python-plugins") |
9201e00d | 230 | ;; |
1f620ba0 | 231 | |
0d30552d | 232 | min) |
1f620ba0 | 233 | echo "Minimal configuration" |
0d30552d | 234 | ;; |
1f620ba0 | 235 | |
275b59d2 | 236 | *) |
1f620ba0 | 237 | echo "Standard configuration" |
0d30552d | 238 | |
1f620ba0 | 239 | # Enable the python bindings / plugins by default with babeltrace2, |
0d30552d MJ |
240 | # the test suite is mostly useless without it. |
241 | if vergte "$PACKAGE_VERSION" "2.0"; then | |
1f620ba0 | 242 | CONF_OPTS+=("--enable-python-bindings" "--enable-python-plugins") |
0d30552d | 243 | fi |
275b59d2 JRJ |
244 | ;; |
245 | esac | |
246 | ||
aad6ac90 | 247 | # Build type |
07dafe32 MJ |
248 | # oot : out-of-tree build |
249 | # dist : build via make dist | |
250 | # oot-dist: build via make dist out-of-tree | |
251 | # * : normal tree build | |
aad6ac90 | 252 | # |
07dafe32 | 253 | # Make sure to move to the build directory and run configure |
1f620ba0 | 254 | # before continuing. |
aad6ac90 | 255 | case "$build" in |
b8475d72 MJ |
256 | oot) |
257 | echo "Out of tree build" | |
258 | ||
259 | # Create and enter a temporary build directory | |
260 | builddir=$(mktemp -d) | |
261 | cd "$builddir" | |
262 | ||
51c9c62d | 263 | "$SRCDIR/configure" "${CONF_OPTS[@]}" || failed_configure |
b8475d72 | 264 | ;; |
1f620ba0 | 265 | |
b8475d72 MJ |
266 | dist) |
267 | echo "Distribution in-tree build" | |
1f620ba0 | 268 | |
b8475d72 MJ |
269 | # Run configure and generate the tar file |
270 | # in the source directory | |
51c9c62d | 271 | ./configure || failed_configure |
b8475d72 | 272 | $MAKE dist |
c56b9301 | 273 | |
b8475d72 MJ |
274 | # Create and enter a temporary build directory |
275 | builddir=$(mktemp -d) | |
276 | cd "$builddir" | |
277 | ||
278 | # Extract the distribution tar in the build directory, | |
279 | # ignore the first directory level | |
280 | $TAR xvf "$SRCDIR"/*.tar.* --strip 1 | |
281 | ||
07dafe32 | 282 | # Build in extracted source tree |
51c9c62d | 283 | ./configure "${CONF_OPTS[@]}" || failed_configure |
b8475d72 | 284 | ;; |
c56b9301 | 285 | |
b8475d72 MJ |
286 | oot-dist) |
287 | echo "Distribution out of tree build" | |
c56b9301 | 288 | |
b8475d72 MJ |
289 | # Create and enter a temporary build directory |
290 | builddir=$(mktemp -d) | |
291 | cd "$builddir" | |
c56b9301 | 292 | |
b8475d72 | 293 | # Run configure out of tree and generate the tar file |
51c9c62d | 294 | "$SRCDIR/configure" || failed_configure |
b8475d72 | 295 | $MAKE dist |
c56b9301 | 296 | |
b8475d72 MJ |
297 | dist_srcdir="$(mktemp -d)" |
298 | cd "$dist_srcdir" | |
c56b9301 | 299 | |
b8475d72 MJ |
300 | # Extract the distribution tar in the new source directory, |
301 | # ignore the first directory level | |
302 | $TAR xvf "$builddir"/*.tar.* --strip 1 | |
303 | ||
304 | # Create and enter a second temporary build directory | |
305 | builddir="$(mktemp -d)" | |
306 | cd "$builddir" | |
307 | ||
308 | # Run configure from the extracted distribution tar, | |
309 | # out of the source tree | |
51c9c62d | 310 | "$dist_srcdir/configure" "${CONF_OPTS[@]}" || failed_configure |
b8475d72 MJ |
311 | ;; |
312 | ||
313 | *) | |
314 | echo "Standard in-tree build" | |
51c9c62d | 315 | ./configure "${CONF_OPTS[@]}" || failed_configure |
b8475d72 | 316 | ;; |
aad6ac90 JR |
317 | esac |
318 | ||
1f620ba0 MJ |
319 | # We are now inside a configured build directory |
320 | ||
c56b9301 | 321 | # BUILD! |
a57a60d9 | 322 | $MAKE -j "$($NPROC)" V=1 |
07dafe32 MJ |
323 | |
324 | # Install in the workspace | |
325 | $MAKE install DESTDIR="$WORKSPACE" | |
c56b9301 | 326 | |
9d56171a | 327 | # Run tests, don't fail now, we want to run the archiving steps |
1d56e325 | 328 | failed_tests=0 |
e3c32202 JR |
329 | if [ "$BABELTRACE_RUN_TESTS" = "yes" ]; then |
330 | $MAKE --keep-going check || failed_tests=1 | |
331 | ||
332 | # Copy tap logs for the jenkins tap parser before cleaning the build dir | |
333 | rsync -a --exclude 'test-suite.log' --include '*/' --include '*.log' --exclude='*' tests/ "$WORKSPACE/tap" | |
334 | ||
335 | # The test suite prior to 1.5 did not produce TAP logs | |
336 | if verlt "$PACKAGE_VERSION" "1.5"; then | |
337 | mkdir -p "$WORKSPACE/tap/no-log" | |
338 | echo "1..1" > "$WORKSPACE/tap/no-log/tests.log" | |
339 | echo "ok 1 - Test suite doesn't support logging" >> "$WORKSPACE/tap/no-log/tests.log" | |
340 | fi | |
649c39a6 MJ |
341 | fi |
342 | ||
e6be9fb0 MJ |
343 | # Clean the build directory |
344 | $MAKE clean | |
275b59d2 | 345 | |
c56b9301 | 346 | # Cleanup rpath in executables and shared libraries |
07dafe32 MJ |
347 | find "$WORKSPACE/$PREFIX/bin" -type f -perm -0500 -exec chrpath --delete {} \; |
348 | find "$WORKSPACE/$PREFIX/lib" -name "*.so" -exec chrpath --delete {} \; | |
c56b9301 MJ |
349 | |
350 | # Remove libtool .la files | |
07dafe32 | 351 | find "$WORKSPACE/$PREFIX/lib" -name "*.la" -exec rm -f {} \; |
87e41bca | 352 | |
1d56e325 MJ |
353 | # Exit with failure if any of the tests failed |
354 | exit $failed_tests | |
9d56171a | 355 | |
87e41bca | 356 | # EOF |