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