jjb: babeltrace: prepare for ubuntu jammy upgrade
[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 ;;
d954b6a8
MJ
112gcc-*)
113 export CC=gcc-${cc#gcc-}
114 export CXX=g++-${cc#gcc-}
1d56e325
MJ
115 ;;
116clang)
117 export CC=clang
118 export CXX=clang++
119 ;;
d954b6a8
MJ
120clang-*)
121 export CC=clang-${cc#clang-}
122 export CXX=clang++-${cc#clang-}
1d56e325
MJ
123 ;;
124*)
125 if [ "x$cc" != "x" ]; then
126 export CC="$cc"
127 fi
128 ;;
129esac
130
131if [ "x${CC:-}" != "x" ]; then
132 echo "Selected compiler:"
133 "$CC" -v
134fi
135
72f4f0c1 136# Set platform variables
7491c28d 137case "$arch" in
f0d7e5b1 138macos*)
995ac8f2
MJ
139 export MAKE=make
140 export TAR=tar
141 export NPROC="getconf _NPROCESSORS_ONLN"
f7bf4d7a 142 export PATH="/opt/local/bin:/opt/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"
1d56e325
MJ
143 export CPPFLAGS="-I/opt/local/include"
144 export LDFLAGS="-L/opt/local/lib"
0ef2148a
MJ
145 export PYTHON="python3.9"
146 export PYTHON_CONFIG="python3.9-config"
f7bf4d7a
MJ
147 ;;
148
d954b6a8 149freebsd*)
6ad0e7e6
MJ
150 export MAKE=gmake
151 export TAR=tar
152 export NPROC="getconf _NPROCESSORS_ONLN"
153 export CPPFLAGS="-I/usr/local/include"
154 export LDFLAGS="-L/usr/local/lib"
155 export PYTHON="python3"
156 export PYTHON_CONFIG="python3-config"
157 ;;
158
7491c28d 159*)
995ac8f2
MJ
160 export MAKE=make
161 export TAR=tar
162 export NPROC=nproc
1d56e325
MJ
163 export PYTHON="python3"
164 export PYTHON_CONFIG="python3-config"
7491c28d
MJ
165 ;;
166esac
167
51c9c62d
MJ
168# Print build env details
169print_os || true
170print_tooling || true
171
cd9733d5
JR
172# Enter the source directory
173cd "$SRCDIR"
174
175# Run bootstrap in the source directory prior to configure
176./bootstrap
177
178# Get source version from configure script
179eval "$(grep '^PACKAGE_VERSION=' ./configure)"
1d56e325 180PACKAGE_VERSION=${PACKAGE_VERSION//\-pre*/}
cd9733d5
JR
181
182# Set configure options and environment variables for each build
183# configuration.
1d56e325 184CONF_OPTS=("--prefix=$PREFIX")
56162e2a
JRJ
185case "$conf" in
186static)
1d56e325
MJ
187 echo "Static lib only configuration"
188
189 CONF_OPTS+=("--enable-static" "--disable-shared")
56162e2a 190 ;;
72f4f0c1 191
a57a60d9 192tls_fallback)
56162e2a 193 echo "Using pthread_getspecific() to emulate TLS"
1d56e325 194 CONF_OPTS+=("--disable-compiler-tls")
56162e2a 195 ;;
72f4f0c1 196
cd9733d5
JR
197debug-rcu)
198 echo "Enable RCU sanity checks for debugging"
a0493692 199 if vergte "$PACKAGE_VERSION" "0.10"; then
1d56e325 200 CONF_OPTS+=("--enable-rcu-debug")
cd9733d5 201 else
72d087d4 202 export CFLAGS="$CFLAGS -DDEBUG_RCU"
cd9733d5 203 fi
25e13783
JR
204
205 echo "Enable iterator sanity validator"
206 if vergte "$PACKAGE_VERSION" "0.11"; then
1d56e325 207 CONF_OPTS+=("--enable-cds-lfht-iter-debug")
25e13783 208 fi
cd9733d5
JR
209 ;;
210
56162e2a 211*)
1d56e325 212 echo "Standard configuration"
56162e2a
JRJ
213 ;;
214esac
215
595a34c7 216# Build type
1d56e325
MJ
217# oot : out-of-tree build
218# dist : build via make dist
219# oot-dist: build via make dist out-of-tree
220# * : normal tree build
595a34c7 221#
1d56e325 222# Make sure to move to the build directory and run configure
69d7af71 223# before continuing.
595a34c7 224case "$build" in
72f4f0c1
MJ
225oot)
226 echo "Out of tree build"
69d7af71 227
1d56e325
MJ
228 # Create and enter a temporary build directory
229 builddir=$(mktemp -d)
230 cd "$builddir"
69d7af71 231
51c9c62d 232 "$SRCDIR/configure" "${CONF_OPTS[@]}" || failed_configure
72f4f0c1
MJ
233 ;;
234
235dist)
1d56e325
MJ
236 echo "Distribution in-tree build"
237
238 # Run configure and generate the tar file
239 # in the source directory
51c9c62d 240 ./configure || failed_configure
1d56e325
MJ
241 $MAKE dist
242
243 # Create and enter a temporary build directory
244 builddir=$(mktemp -d)
245 cd "$builddir"
246
247 # Extract the distribution tar in the build directory,
248 # ignore the first directory level
249 $TAR xvf "$SRCDIR"/*.tar.* --strip 1
250
251 # Build in extracted source tree
51c9c62d 252 ./configure "${CONF_OPTS[@]}" || failed_configure
1d56e325
MJ
253 ;;
254
255oot-dist)
72f4f0c1 256 echo "Distribution out of tree build"
72f4f0c1 257
1d56e325
MJ
258 # Create and enter a temporary build directory
259 builddir=$(mktemp -d)
260 cd "$builddir"
69d7af71 261
1d56e325 262 # Run configure out of tree and generate the tar file
51c9c62d 263 "$SRCDIR/configure" || failed_configure
72f4f0c1
MJ
264 $MAKE dist
265
1d56e325
MJ
266 dist_srcdir="$(mktemp -d)"
267 cd "$dist_srcdir"
72f4f0c1 268
1d56e325
MJ
269 # Extract the distribution tar in the new source directory,
270 # ignore the first directory level
271 $TAR xvf "$builddir"/*.tar.* --strip 1
72f4f0c1 272
1d56e325
MJ
273 # Create and enter a second temporary build directory
274 builddir="$(mktemp -d)"
275 cd "$builddir"
276
277 # Run configure from the extracted distribution tar,
278 # out of the source tree
51c9c62d 279 "$dist_srcdir/configure" "${CONF_OPTS[@]}" || failed_configure
72f4f0c1 280 ;;
1d56e325 281
72f4f0c1 282*)
6d35c326 283 echo "Standard in-tree build"
51c9c62d 284 ./configure "${CONF_OPTS[@]}" || failed_configure
72f4f0c1 285 ;;
595a34c7
JR
286esac
287
1d56e325
MJ
288# We are now inside a configured build directory
289
72f4f0c1 290# BUILD!
a57a60d9 291$MAKE -j "$($NPROC)" V=1
72f4f0c1 292
1d56e325
MJ
293# Install in the workspace
294$MAKE install DESTDIR="$WORKSPACE"
295
296# Run tests, don't fail now, we want to run the archiving steps
297failed_tests=0
aff4e3d1
JR
298if [ "$USERSPACE_RCU_RUN_TESTS" = "yes" ]; then
299 $MAKE --keep-going check || failed_tests=1
300 # Only run regtest for 0.9 and up
301 if vergte "$PACKAGE_VERSION" "0.9"; then
302 $MAKE --keep-going regtest || failed_tests=1
303 fi
72f4f0c1 304
aff4e3d1
JR
305 # Copy tap logs for the jenkins tap parser before cleaning the build dir
306 rsync -a --exclude 'test-suite.log' --include '*/' --include '*.log' --exclude='*' tests/ "$WORKSPACE/tap"
69d7af71 307
aff4e3d1
JR
308 # The test suite prior to 0.11 did not produce TAP logs
309 if verlt "$PACKAGE_VERSION" "0.11"; then
310 mkdir -p "$WORKSPACE/tap/no-log"
311 echo "1..1" > "$WORKSPACE/tap/no-log/tests.log"
312 echo "ok 1 - Test suite doesn't support logging" >> "$WORKSPACE/tap/no-log/tests.log"
313 fi
e5d878d8
MJ
314fi
315
1d56e325 316# Clean the build directory
7491c28d 317$MAKE clean
56162e2a 318
72f4f0c1 319# Cleanup rpath in executables and shared libraries
1d56e325
MJ
320#find "$WORKSPACE/$PREFIX/bin" -type f -perm -0500 -exec chrpath --delete {} \;
321find "$WORKSPACE/$PREFIX/lib" -name "*.so" -exec chrpath --delete {} \;
72f4f0c1
MJ
322
323# Remove libtool .la files
1d56e325 324find "$WORKSPACE/$PREFIX/lib" -name "*.la" -exec rm -f {} \;
595a34c7 325
1d56e325
MJ
326# Exit with failure if any of the tests failed
327exit $failed_tests
7491c28d
MJ
328
329# EOF
This page took 0.044369 seconds and 4 git commands to generate.