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 | ||
a57a60d9 MJ |
72 | # Required parameters |
73 | arch=${arch:-} | |
74 | conf=${conf:-} | |
75 | build=${build:-} | |
6476f917 | 76 | cc=${cc:-} |
a57a60d9 | 77 | |
c56b9301 | 78 | |
e6be9fb0 MJ |
79 | SRCDIR="$WORKSPACE/src/babeltrace" |
80 | TMPDIR="$WORKSPACE/tmp" | |
275b59d2 JRJ |
81 | PREFIX="$WORKSPACE/build" |
82 | ||
1f620ba0 | 83 | # Create install and tmp directories |
e6be9fb0 MJ |
84 | rm -rf "$PREFIX" "$TMPDIR" |
85 | mkdir -p "$PREFIX" "$TMPDIR" | |
86 | ||
0e9967db | 87 | export TMPDIR |
72d087d4 | 88 | export CFLAGS="-g -O2" |
0e9967db | 89 | |
6476f917 MJ |
90 | # Set compiler variables |
91 | case "$cc" in | |
92 | gcc) | |
93 | export CC=gcc | |
94 | export CXX=g++ | |
95 | ;; | |
96 | gcc-4.8) | |
97 | export CC=gcc-4.8 | |
98 | export CXX=g++-4.8 | |
99 | ;; | |
100 | gcc-5) | |
101 | export CC=gcc-5 | |
102 | export CXX=g++-5 | |
103 | ;; | |
104 | gcc-6) | |
105 | export CC=gcc-6 | |
106 | export CXX=g++-6 | |
107 | ;; | |
108 | gcc-7) | |
109 | export CC=gcc-7 | |
110 | export CXX=g++-7 | |
111 | ;; | |
112 | gcc-8) | |
113 | export CC=gcc-8 | |
114 | export CXX=g++-8 | |
115 | ;; | |
116 | clang) | |
117 | export CC=clang | |
118 | export CXX=clang++ | |
119 | ;; | |
120 | clang-3.9) | |
121 | export CC=clang-3.9 | |
122 | export CXX=clang++-3.9 | |
123 | ;; | |
124 | clang-4.0) | |
125 | export CC=clang-4.0 | |
126 | export CXX=clang++-4.0 | |
127 | ;; | |
128 | clang-5.0) | |
129 | export CC=clang-5.0 | |
130 | export CXX=clang++-5.0 | |
131 | ;; | |
132 | clang-6.0) | |
133 | export CC=clang-6.0 | |
134 | export CXX=clang++-6.0 | |
135 | ;; | |
136 | clang-7) | |
137 | export CC=clang-7 | |
138 | export CXX=clang++-7 | |
139 | ;; | |
140 | *) | |
141 | if [ "x$cc" != "x" ]; then | |
142 | export CC="$cc" | |
143 | fi | |
144 | ;; | |
145 | esac | |
146 | ||
1183a118 | 147 | if [ "x${CC:-}" != "x" ]; then |
6476f917 MJ |
148 | echo "Selected compiler:" |
149 | "$CC" -v | |
150 | fi | |
151 | ||
c56b9301 | 152 | # Set platform variables |
87e41bca | 153 | case "$arch" in |
a0b535b2 MJ |
154 | sol10-i386) |
155 | export MAKE=gmake | |
156 | export TAR=gtar | |
157 | export NPROC=gnproc | |
158 | export BISON=bison | |
159 | export YACC="$BISON -y" | |
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 | ;; |
a0b535b2 MJ |
167 | sol11-i386) |
168 | export MAKE=gmake | |
169 | export TAR=gtar | |
170 | export NPROC=nproc | |
87e41bca | 171 | export PATH="$PATH:/usr/perl5/bin" |
cd808c9e MJ |
172 | export LD_ALTEXEC=/usr/bin/gld |
173 | export LD=/usr/bin/gld | |
1f620ba0 MJ |
174 | export PYTHON="python3" |
175 | export PYTHON_CONFIG="python3-config" | |
87e41bca | 176 | ;; |
221450b6 | 177 | macosx) |
a0b535b2 MJ |
178 | export MAKE=make |
179 | export TAR=tar | |
180 | export NPROC="getconf _NPROCESSORS_ONLN" | |
181 | export BISON="bison" | |
182 | export YACC="$BISON -y" | |
221450b6 | 183 | export PATH="/opt/local/bin:/opt/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin" |
72d087d4 | 184 | export CFLAGS="$CFLAGS -I/opt/local/include" |
221450b6 | 185 | export LDFLAGS="-L/opt/local/lib" |
1f620ba0 MJ |
186 | export PYTHON="python3" |
187 | export PYTHON_CONFIG="python3-config" | |
221450b6 | 188 | ;; |
87e41bca | 189 | *) |
a0b535b2 MJ |
190 | export MAKE=make |
191 | export TAR=tar | |
192 | export NPROC=nproc | |
1f620ba0 MJ |
193 | export PYTHON="python3" |
194 | export PYTHON_CONFIG="python3-config" | |
87e41bca MJ |
195 | ;; |
196 | esac | |
197 | ||
a0b535b2 MJ |
198 | # Enter the source directory |
199 | cd "$SRCDIR" | |
200 | ||
201 | # Run bootstrap in the source directory prior to configure | |
202 | ./bootstrap | |
203 | ||
204 | # Get source version from configure script | |
205 | eval "$(grep '^PACKAGE_VERSION=' ./configure)" | |
206 | ||
11ba7264 | 207 | # Enable dev mode by default for BT 2.0 builds |
9201e00d MJ |
208 | export BABELTRACE_DEBUG_MODE=1 |
209 | export BABELTRACE_DEV_MODE=1 | |
8130d845 | 210 | export BABELTRACE_MINIMAL_LOG_LEVEL=TRACE |
11ba7264 | 211 | |
c56b9301 | 212 | # Set configure options for each build configuration |
1f620ba0 | 213 | CONF_OPTS=() |
275b59d2 JRJ |
214 | case "$conf" in |
215 | static) | |
1f620ba0 MJ |
216 | echo "Static lib only configuration" |
217 | ||
218 | CONF_OPTS+=("--enable-static" "--disable-shared") | |
219 | ||
a0b535b2 | 220 | if vergte "$PACKAGE_VERSION" "2.0"; then |
1f620ba0 | 221 | CONF_OPTS+=("--enable-built-in-plugins") |
a0b535b2 | 222 | fi |
275b59d2 | 223 | ;; |
1f620ba0 | 224 | |
221450b6 | 225 | python-bindings) |
1f620ba0 MJ |
226 | echo "Python bindings configuration" |
227 | ||
228 | CONF_OPTS+=("--enable-python-bindings") | |
a0b535b2 MJ |
229 | |
230 | if vergte "$PACKAGE_VERSION" "2.0"; then | |
1f620ba0 | 231 | CONF_OPTS+=("--enable-python-bindings-doc" "--enable-python-plugins") |
a0b535b2 | 232 | fi |
275b59d2 | 233 | ;; |
1f620ba0 | 234 | |
0d30552d | 235 | prod) |
1f620ba0 | 236 | echo "Production configuration" |
9201e00d MJ |
237 | |
238 | # Unset the developper variables | |
239 | unset BABELTRACE_DEBUG_MODE | |
240 | unset BABELTRACE_DEV_MODE | |
241 | unset BABELTRACE_MINIMAL_LOG_LEVEL | |
242 | ||
243 | # Enable the python bindings | |
1f620ba0 | 244 | CONF_OPTS+=("--enable-python-bindings" "--enable-python-bindings-doc" "--enable-python-plugins") |
9201e00d | 245 | ;; |
1f620ba0 | 246 | |
0d30552d | 247 | min) |
1f620ba0 | 248 | echo "Minimal configuration" |
0d30552d | 249 | ;; |
1f620ba0 | 250 | |
275b59d2 | 251 | *) |
1f620ba0 | 252 | echo "Standard configuration" |
0d30552d | 253 | |
1f620ba0 | 254 | # Enable the python bindings / plugins by default with babeltrace2, |
0d30552d MJ |
255 | # the test suite is mostly useless without it. |
256 | if vergte "$PACKAGE_VERSION" "2.0"; then | |
1f620ba0 | 257 | CONF_OPTS+=("--enable-python-bindings" "--enable-python-plugins") |
0d30552d | 258 | fi |
275b59d2 JRJ |
259 | ;; |
260 | esac | |
261 | ||
aad6ac90 JR |
262 | # Build type |
263 | # oot : out-of-tree build | |
264 | # dist: build via make dist | |
265 | # * : normal tree build | |
266 | # | |
1f620ba0 MJ |
267 | # Make sure to move to the build dir and run configure |
268 | # before continuing. | |
aad6ac90 | 269 | case "$build" in |
b8475d72 MJ |
270 | oot) |
271 | echo "Out of tree build" | |
272 | ||
273 | # Create and enter a temporary build directory | |
274 | builddir=$(mktemp -d) | |
275 | cd "$builddir" | |
276 | ||
277 | "$SRCDIR/configure" --prefix="$PREFIX" "${CONF_OPTS[@]}" | |
278 | ;; | |
1f620ba0 | 279 | |
b8475d72 MJ |
280 | dist) |
281 | echo "Distribution in-tree build" | |
1f620ba0 | 282 | |
b8475d72 MJ |
283 | # Run configure and generate the tar file |
284 | # in the source directory | |
285 | ./configure | |
286 | $MAKE dist | |
c56b9301 | 287 | |
b8475d72 MJ |
288 | # Create and enter a temporary build directory |
289 | builddir=$(mktemp -d) | |
290 | cd "$builddir" | |
291 | ||
292 | # Extract the distribution tar in the build directory, | |
293 | # ignore the first directory level | |
294 | $TAR xvf "$SRCDIR"/*.tar.* --strip 1 | |
295 | ||
296 | ./configure --prefix="$PREFIX" "${CONF_OPTS[@]}" | |
297 | ;; | |
c56b9301 | 298 | |
b8475d72 MJ |
299 | oot-dist) |
300 | echo "Distribution out of tree build" | |
c56b9301 | 301 | |
b8475d72 MJ |
302 | # Create and enter a temporary build directory |
303 | builddir=$(mktemp -d) | |
304 | cd "$builddir" | |
c56b9301 | 305 | |
b8475d72 MJ |
306 | # Run configure out of tree and generate the tar file |
307 | "$SRCDIR/configure" | |
308 | $MAKE dist | |
c56b9301 | 309 | |
b8475d72 MJ |
310 | dist_srcdir="$(mktemp -d)" |
311 | cd "$dist_srcdir" | |
c56b9301 | 312 | |
b8475d72 MJ |
313 | # Extract the distribution tar in the new source directory, |
314 | # ignore the first directory level | |
315 | $TAR xvf "$builddir"/*.tar.* --strip 1 | |
316 | ||
317 | # Create and enter a second temporary build directory | |
318 | builddir="$(mktemp -d)" | |
319 | cd "$builddir" | |
320 | ||
321 | # Run configure from the extracted distribution tar, | |
322 | # out of the source tree | |
323 | "$dist_srcdir/configure" --prefix="$PREFIX" "${CONF_OPTS[@]}" | |
324 | ;; | |
325 | ||
326 | *) | |
327 | echo "Standard in-tree build" | |
328 | ./configure --prefix="$PREFIX" "${CONF_OPTS[@]}" | |
329 | ;; | |
aad6ac90 JR |
330 | esac |
331 | ||
1f620ba0 MJ |
332 | # We are now inside a configured build directory |
333 | ||
c56b9301 | 334 | # BUILD! |
a57a60d9 | 335 | $MAKE -j "$($NPROC)" V=1 |
87e41bca | 336 | $MAKE install |
c56b9301 | 337 | |
9d56171a MJ |
338 | # Run tests, don't fail now, we want to run the archiving steps |
339 | set +e | |
6827c67a | 340 | $MAKE --keep-going check |
9d56171a MJ |
341 | ret=$? |
342 | set -e | |
c56b9301 | 343 | |
1f620ba0 | 344 | # Copy tap logs for the jenkins tap parser before cleaning the build dir |
e6be9fb0 MJ |
345 | rsync -a --exclude 'test-suite.log' --include '*/' --include '*.log' --exclude='*' tests/ "$WORKSPACE/tap" |
346 | ||
347 | # Clean the build directory | |
348 | $MAKE clean | |
275b59d2 | 349 | |
c56b9301 | 350 | # Cleanup rpath in executables and shared libraries |
944a6c86 MJ |
351 | find "$PREFIX/bin" -type f -perm -0500 -exec chrpath --delete {} \; |
352 | find "$PREFIX/lib" -name "*.so" -exec chrpath --delete {} \; | |
c56b9301 MJ |
353 | |
354 | # Remove libtool .la files | |
944a6c86 | 355 | find "$PREFIX/lib" -name "*.la" -exec rm -f {} \; |
aad6ac90 | 356 | |
c56b9301 MJ |
357 | # Clean temp dir for dist build |
358 | if [ "$build" = "dist" ]; then | |
944a6c86 | 359 | cd "$SRCDIR" |
b8475d72 | 360 | rm -rf "$builddir" |
aad6ac90 | 361 | fi |
87e41bca | 362 | |
9d56171a MJ |
363 | # Exit with the return code of the test suite |
364 | exit $ret | |
365 | ||
87e41bca | 366 | # EOF |