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