jjb: depends-on: do not run tests of dependencies
[lttng-ci.git] / scripts / liburcu / build.sh
CommitLineData
51c9c62d 1#!/bin/bash
e3022ad9 2#
69d7af71 3# Copyright (C) 2015 Jonathan Rajotte-Julien <jonathan.rajotte-julien@efficios.com>
51c9c62d 4# Copyright (C) 2016-2020 Michael Jeanson <mjeanson@efficios.com>
e3022ad9
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
19set -exu
20
5fd8db76 21# Version compare functions
0a6e708b
MJ
22vercomp () {
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
5fd8db76 49verlte() {
0a6e708b
MJ
50 vercomp "$1" "$2"; local res="$?"
51 [ "$res" -eq "0" ] || [ "$res" -eq "2" ]
5fd8db76
MJ
52}
53
54verlt() {
0a6e708b
MJ
55 vercomp "$1" "$2"; local res="$?"
56 [ "$res" -eq "2" ]
5fd8db76
MJ
57}
58
59vergte() {
0a6e708b
MJ
60 vercomp "$1" "$2"; local res="$?"
61 [ "$res" -eq "0" ] || [ "$res" -eq "1" ]
5fd8db76
MJ
62}
63
64vergt() {
0a6e708b
MJ
65 vercomp "$1" "$2"; local res="$?"
66 [ "$res" -eq "1" ]
67}
68
69verne() {
70 vercomp "$1" "$2"; local res="$?"
71 [ "$res" -ne "0" ]
5fd8db76
MJ
72}
73
51c9c62d
MJ
74failed_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
80 # End the build with failure
81 exit 1
82}
83
1d56e325
MJ
84# Required variables
85WORKSPACE=${WORKSPACE:-}
86
a57a60d9
MJ
87arch=${arch:-}
88conf=${conf:-}
89build=${build:-}
1d56e325 90cc=${cc:-}
a57a60d9 91
aff4e3d1
JR
92# Controls if the tests are run
93USERSPACE_RCU_RUN_TESTS="${USERSPACE_RCU_RUN_TESTS:=yes}"
e3022ad9 94
6d35c326
MJ
95SRCDIR="$WORKSPACE/src/liburcu"
96TMPDIR="$WORKSPACE/tmp"
1d56e325 97PREFIX="/build"
69d7af71 98
1d56e325
MJ
99# Create tmp directory
100rm -rf "$TMPDIR"
101mkdir -p "$TMPDIR"
6d35c326
MJ
102
103export TMPDIR
72d087d4 104export CFLAGS="-g -O2"
6d35c326 105
1d56e325
MJ
106# Set compiler variables
107case "$cc" in
108gcc)
109 export CC=gcc
110 export CXX=g++
111 ;;
112gcc-4.8)
113 export CC=gcc-4.8
114 export CXX=g++-4.8
115 ;;
116gcc-5)
117 export CC=gcc-5
118 export CXX=g++-5
119 ;;
120gcc-6)
121 export CC=gcc-6
122 export CXX=g++-6
123 ;;
124gcc-7)
125 export CC=gcc-7
126 export CXX=g++-7
127 ;;
128gcc-8)
129 export CC=gcc-8
130 export CXX=g++-8
131 ;;
132clang)
133 export CC=clang
134 export CXX=clang++
135 ;;
136clang-3.9)
137 export CC=clang-3.9
138 export CXX=clang++-3.9
139 ;;
140clang-4.0)
141 export CC=clang-4.0
142 export CXX=clang++-4.0
143 ;;
144clang-5.0)
145 export CC=clang-5.0
146 export CXX=clang++-5.0
147 ;;
148clang-6.0)
149 export CC=clang-6.0
150 export CXX=clang++-6.0
151 ;;
152clang-7)
153 export CC=clang-7
154 export CXX=clang++-7
155 ;;
156*)
157 if [ "x$cc" != "x" ]; then
158 export CC="$cc"
159 fi
160 ;;
161esac
162
163if [ "x${CC:-}" != "x" ]; then
164 echo "Selected compiler:"
165 "$CC" -v
166fi
167
72f4f0c1 168# Set platform variables
7491c28d 169case "$arch" in
995ac8f2
MJ
170sol10-i386)
171 export MAKE=gmake
172 export TAR=gtar
173 export NPROC=gnproc
ad11244c 174 export PATH="/opt/csw/bin:/usr/ccs/bin:$PATH"
995ac8f2
MJ
175 export CPPFLAGS="-I/opt/csw/include"
176 export LDFLAGS="-L/opt/csw/lib -R/opt/csw/lib"
177 export PKG_CONFIG_PATH="/opt/csw/lib/pkgconfig"
1d56e325
MJ
178 export PYTHON="python3"
179 export PYTHON_CONFIG="python3-config"
7491c28d 180 ;;
1d56e325 181
995ac8f2
MJ
182sol11-i386)
183 export MAKE=gmake
184 export TAR=gtar
185 export NPROC=nproc
f2cd0939 186 export PATH="/opt/csw/bin:$PATH:/usr/perl5/bin"
1d56e325
MJ
187 export LD_ALTEXEC=/usr/bin/gld
188 export LD=/usr/bin/gld
189 export PYTHON="python3"
190 export PYTHON_CONFIG="python3-config"
f2cd0939 191 export PKG_CONFIG_PATH="/usr/lib/pkgconfig"
7491c28d 192 ;;
1d56e325 193
f0d7e5b1 194macos*)
995ac8f2
MJ
195 export MAKE=make
196 export TAR=tar
197 export NPROC="getconf _NPROCESSORS_ONLN"
f7bf4d7a 198 export PATH="/opt/local/bin:/opt/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"
1d56e325
MJ
199 export CPPFLAGS="-I/opt/local/include"
200 export LDFLAGS="-L/opt/local/lib"
0ef2148a
MJ
201 export PYTHON="python3.9"
202 export PYTHON_CONFIG="python3.9-config"
f7bf4d7a
MJ
203 ;;
204
6ad0e7e6
MJ
205freebsd)
206 export MAKE=gmake
207 export TAR=tar
208 export NPROC="getconf _NPROCESSORS_ONLN"
209 export CPPFLAGS="-I/usr/local/include"
210 export LDFLAGS="-L/usr/local/lib"
211 export PYTHON="python3"
212 export PYTHON_CONFIG="python3-config"
213 ;;
214
7491c28d 215*)
995ac8f2
MJ
216 export MAKE=make
217 export TAR=tar
218 export NPROC=nproc
1d56e325
MJ
219 export PYTHON="python3"
220 export PYTHON_CONFIG="python3-config"
7491c28d
MJ
221 ;;
222esac
223
51c9c62d
MJ
224# Print build env details
225print_os || true
226print_tooling || true
227
cd9733d5
JR
228# Enter the source directory
229cd "$SRCDIR"
230
231# Run bootstrap in the source directory prior to configure
232./bootstrap
233
234# Get source version from configure script
235eval "$(grep '^PACKAGE_VERSION=' ./configure)"
1d56e325 236PACKAGE_VERSION=${PACKAGE_VERSION//\-pre*/}
cd9733d5
JR
237
238# Set configure options and environment variables for each build
239# configuration.
1d56e325 240CONF_OPTS=("--prefix=$PREFIX")
56162e2a
JRJ
241case "$conf" in
242static)
1d56e325
MJ
243 echo "Static lib only configuration"
244
245 CONF_OPTS+=("--enable-static" "--disable-shared")
56162e2a 246 ;;
72f4f0c1 247
a57a60d9 248tls_fallback)
56162e2a 249 echo "Using pthread_getspecific() to emulate TLS"
1d56e325 250 CONF_OPTS+=("--disable-compiler-tls")
56162e2a 251 ;;
72f4f0c1 252
cd9733d5
JR
253debug-rcu)
254 echo "Enable RCU sanity checks for debugging"
a0493692 255 if vergte "$PACKAGE_VERSION" "0.10"; then
1d56e325 256 CONF_OPTS+=("--enable-rcu-debug")
cd9733d5 257 else
72d087d4 258 export CFLAGS="$CFLAGS -DDEBUG_RCU"
cd9733d5 259 fi
25e13783
JR
260
261 echo "Enable iterator sanity validator"
262 if vergte "$PACKAGE_VERSION" "0.11"; then
1d56e325 263 CONF_OPTS+=("--enable-cds-lfht-iter-debug")
25e13783 264 fi
cd9733d5
JR
265 ;;
266
56162e2a 267*)
1d56e325 268 echo "Standard configuration"
56162e2a
JRJ
269 ;;
270esac
271
595a34c7 272# Build type
1d56e325
MJ
273# oot : out-of-tree build
274# dist : build via make dist
275# oot-dist: build via make dist out-of-tree
276# * : normal tree build
595a34c7 277#
1d56e325 278# Make sure to move to the build directory and run configure
69d7af71 279# before continuing.
595a34c7 280case "$build" in
72f4f0c1
MJ
281oot)
282 echo "Out of tree build"
69d7af71 283
1d56e325
MJ
284 # Create and enter a temporary build directory
285 builddir=$(mktemp -d)
286 cd "$builddir"
69d7af71 287
51c9c62d 288 "$SRCDIR/configure" "${CONF_OPTS[@]}" || failed_configure
72f4f0c1
MJ
289 ;;
290
291dist)
1d56e325
MJ
292 echo "Distribution in-tree build"
293
294 # Run configure and generate the tar file
295 # in the source directory
51c9c62d 296 ./configure || failed_configure
1d56e325
MJ
297 $MAKE dist
298
299 # Create and enter a temporary build directory
300 builddir=$(mktemp -d)
301 cd "$builddir"
302
303 # Extract the distribution tar in the build directory,
304 # ignore the first directory level
305 $TAR xvf "$SRCDIR"/*.tar.* --strip 1
306
307 # Build in extracted source tree
51c9c62d 308 ./configure "${CONF_OPTS[@]}" || failed_configure
1d56e325
MJ
309 ;;
310
311oot-dist)
72f4f0c1 312 echo "Distribution out of tree build"
72f4f0c1 313
1d56e325
MJ
314 # Create and enter a temporary build directory
315 builddir=$(mktemp -d)
316 cd "$builddir"
69d7af71 317
1d56e325 318 # Run configure out of tree and generate the tar file
51c9c62d 319 "$SRCDIR/configure" || failed_configure
72f4f0c1
MJ
320 $MAKE dist
321
1d56e325
MJ
322 dist_srcdir="$(mktemp -d)"
323 cd "$dist_srcdir"
72f4f0c1 324
1d56e325
MJ
325 # Extract the distribution tar in the new source directory,
326 # ignore the first directory level
327 $TAR xvf "$builddir"/*.tar.* --strip 1
72f4f0c1 328
1d56e325
MJ
329 # Create and enter a second temporary build directory
330 builddir="$(mktemp -d)"
331 cd "$builddir"
332
333 # Run configure from the extracted distribution tar,
334 # out of the source tree
51c9c62d 335 "$dist_srcdir/configure" "${CONF_OPTS[@]}" || failed_configure
72f4f0c1 336 ;;
1d56e325 337
72f4f0c1 338*)
6d35c326 339 echo "Standard in-tree build"
51c9c62d 340 ./configure "${CONF_OPTS[@]}" || failed_configure
72f4f0c1 341 ;;
595a34c7
JR
342esac
343
1d56e325
MJ
344# We are now inside a configured build directory
345
72f4f0c1 346# BUILD!
a57a60d9 347$MAKE -j "$($NPROC)" V=1
72f4f0c1 348
1d56e325
MJ
349# Install in the workspace
350$MAKE install DESTDIR="$WORKSPACE"
351
352# Run tests, don't fail now, we want to run the archiving steps
353failed_tests=0
aff4e3d1
JR
354if [ "$USERSPACE_RCU_RUN_TESTS" = "yes" ]; then
355 $MAKE --keep-going check || failed_tests=1
356 # Only run regtest for 0.9 and up
357 if vergte "$PACKAGE_VERSION" "0.9"; then
358 $MAKE --keep-going regtest || failed_tests=1
359 fi
72f4f0c1 360
aff4e3d1
JR
361 # Copy tap logs for the jenkins tap parser before cleaning the build dir
362 rsync -a --exclude 'test-suite.log' --include '*/' --include '*.log' --exclude='*' tests/ "$WORKSPACE/tap"
69d7af71 363
aff4e3d1
JR
364 # The test suite prior to 0.11 did not produce TAP logs
365 if verlt "$PACKAGE_VERSION" "0.11"; then
366 mkdir -p "$WORKSPACE/tap/no-log"
367 echo "1..1" > "$WORKSPACE/tap/no-log/tests.log"
368 echo "ok 1 - Test suite doesn't support logging" >> "$WORKSPACE/tap/no-log/tests.log"
369 fi
e5d878d8
MJ
370fi
371
1d56e325 372# Clean the build directory
7491c28d 373$MAKE clean
56162e2a 374
72f4f0c1 375# Cleanup rpath in executables and shared libraries
1d56e325
MJ
376#find "$WORKSPACE/$PREFIX/bin" -type f -perm -0500 -exec chrpath --delete {} \;
377find "$WORKSPACE/$PREFIX/lib" -name "*.so" -exec chrpath --delete {} \;
72f4f0c1
MJ
378
379# Remove libtool .la files
1d56e325 380find "$WORKSPACE/$PREFIX/lib" -name "*.la" -exec rm -f {} \;
595a34c7 381
1d56e325
MJ
382# Exit with failure if any of the tests failed
383exit $failed_tests
7491c28d
MJ
384
385# EOF
This page took 0.047104 seconds and 4 git commands to generate.