8c875432c0e9eaae06798ef594e8d1c3725866be
[lttng-ci.git] / scripts / liburcu / build.sh
1 #!/bin/bash
2 #
3 # Copyright (C) 2015 Jonathan Rajotte-Julien <jonathan.rajotte-julien@efficios.com>
4 # Copyright (C) 2016-2020 Michael Jeanson <mjeanson@efficios.com>
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
19 set -exu
20
21 # Version compare functions
22 vercomp () {
23 set +u
24 if [[ "$1" == "$2" ]]; then
25 return 0
26 fi
27 local IFS=.
28 # Ignore the shellcheck warning, we want splitting to happen based on IFS.
29 # shellcheck disable=SC2206
30 local i ver1=($1) ver2=($2)
31 # fill empty fields in ver1 with zeros
32 for ((i=${#ver1[@]}; i<${#ver2[@]}; i++)); do
33 ver1[i]=0
34 done
35 for ((i=0; i<${#ver1[@]}; i++)); do
36 if [[ -z ${ver2[i]} ]]; then
37 # fill empty fields in ver2 with zeros
38 ver2[i]=0
39 fi
40 if ((10#${ver1[i]} > 10#${ver2[i]})); then
41 return 1
42 fi
43 if ((10#${ver1[i]} < 10#${ver2[i]})); then
44 return 2
45 fi
46 done
47 set -u
48 return 0
49 }
50
51 verlte() {
52 vercomp "$1" "$2"; local res="$?"
53 [ "$res" -eq "0" ] || [ "$res" -eq "2" ]
54 }
55
56 verlt() {
57 vercomp "$1" "$2"; local res="$?"
58 [ "$res" -eq "2" ]
59 }
60
61 vergte() {
62 vercomp "$1" "$2"; local res="$?"
63 [ "$res" -eq "0" ] || [ "$res" -eq "1" ]
64 }
65
66 vergt() {
67 vercomp "$1" "$2"; local res="$?"
68 [ "$res" -eq "1" ]
69 }
70
71 verne() {
72 vercomp "$1" "$2"; local res="$?"
73 [ "$res" -ne "0" ]
74 }
75
76 failed_configure() {
77 # Assume we are in the configured build directory
78 echo "#################### BEGIN config.log ####################"
79 cat config.log
80 echo "#################### END config.log ####################"
81
82 # End the build with failure
83 exit 1
84 }
85
86 # Required variables
87 WORKSPACE=${WORKSPACE:-}
88
89 platform=${platform:-}
90 conf=${conf:-}
91 build=${build:-}
92 cc=${cc:-}
93
94 # Controls if the tests are run
95 USERSPACE_RCU_RUN_TESTS="${USERSPACE_RCU_RUN_TESTS:=yes}"
96
97 SRCDIR="$WORKSPACE/src/liburcu"
98 TMPDIR="$WORKSPACE/tmp"
99 PREFIX="/build"
100 LIBDIR="lib"
101
102 # RHEL and SLES both use lib64 but don't bother shipping a default autoconf
103 # site config that matches this.
104 if [[ ( -f /etc/redhat-release || -f /etc/SuSE-release || -f /etc/yocto-release ) ]]; then
105 # Detect the userspace bitness in a distro agnostic way
106 if file -L /bin/bash | grep '64-bit' >/dev/null 2>&1; then
107 LIBDIR_ARCH="${LIBDIR}64"
108 else
109 LIBDIR_ARCH="$LIBDIR"
110 fi
111 fi
112
113 # Create tmp directory
114 rm -rf "$TMPDIR"
115 mkdir -p "$TMPDIR"
116
117 export TMPDIR
118 export CFLAGS="-g -O2"
119
120 # Set compiler variables
121 case "$cc" in
122 gcc)
123 export CC=gcc
124 export CXX=g++
125 ;;
126 gcc-*)
127 export CC=gcc-${cc#gcc-}
128 export CXX=g++-${cc#gcc-}
129 ;;
130 clang)
131 export CC=clang
132 export CXX=clang++
133 ;;
134 clang-*)
135 export CC=clang-${cc#clang-}
136 export CXX=clang++-${cc#clang-}
137 ;;
138 *)
139 if [ "x$cc" != "x" ]; then
140 export CC="$cc"
141 fi
142 ;;
143 esac
144
145 if [ "x${CC:-}" != "x" ]; then
146 echo "Selected compiler:"
147 "$CC" -v
148 fi
149
150 # Set platform variables
151 case "$platform" in
152 macos*)
153 export MAKE=make
154 export TAR=tar
155 export NPROC="getconf _NPROCESSORS_ONLN"
156 export PATH="/opt/local/bin:/opt/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"
157 export CPPFLAGS="-I/opt/local/include"
158 export LDFLAGS="-L/opt/local/lib"
159 export PYTHON="python3"
160 export PYTHON_CONFIG="python3-config"
161 ;;
162
163 freebsd*)
164 export MAKE=gmake
165 export TAR=tar
166 export NPROC="getconf _NPROCESSORS_ONLN"
167 export CPPFLAGS="-I/usr/local/include"
168 export LDFLAGS="-L/usr/local/lib"
169 export PYTHON="python3"
170 export PYTHON_CONFIG="python3-config"
171 ;;
172
173 *)
174 export MAKE=make
175 export TAR=tar
176 export NPROC=nproc
177 export PYTHON="python3"
178 export PYTHON_CONFIG="python3-config"
179 ;;
180 esac
181
182 # Print build env details
183 print_os || true
184 print_tooling || true
185
186 # Enter the source directory
187 cd "$SRCDIR"
188
189 # Run bootstrap in the source directory prior to configure
190 ./bootstrap
191
192 # Get source version from configure script
193 eval "$(grep '^PACKAGE_VERSION=' ./configure)"
194 PACKAGE_VERSION=${PACKAGE_VERSION//\-pre*/}
195
196 # Set configure options and environment variables for each build
197 # configuration.
198 CONF_OPTS=("--prefix=$PREFIX" "--libdir=$PREFIX/$LIBDIR_ARCH")
199 case "$conf" in
200 static)
201 echo "Static lib only configuration"
202
203 CONF_OPTS+=("--enable-static" "--disable-shared")
204 ;;
205
206 tls_fallback)
207 echo "Using pthread_getspecific() to emulate TLS"
208 CONF_OPTS+=("--disable-compiler-tls")
209 ;;
210
211 debug-rcu)
212 echo "Enable RCU sanity checks for debugging"
213 if vergte "$PACKAGE_VERSION" "0.10"; then
214 CONF_OPTS+=("--enable-rcu-debug")
215 else
216 export CFLAGS="$CFLAGS -DDEBUG_RCU"
217 fi
218
219 echo "Enable iterator sanity validator"
220 if vergte "$PACKAGE_VERSION" "0.11"; then
221 CONF_OPTS+=("--enable-cds-lfht-iter-debug")
222 fi
223 ;;
224
225 *)
226 echo "Standard configuration"
227 ;;
228 esac
229
230 # Build type
231 # oot : out-of-tree build
232 # dist : build via make dist
233 # oot-dist: build via make dist out-of-tree
234 # * : normal tree build
235 #
236 # Make sure to move to the build directory and run configure
237 # before continuing.
238 case "$build" in
239 oot)
240 echo "Out of tree build"
241
242 # Create and enter a temporary build directory
243 builddir=$(mktemp -d)
244 cd "$builddir"
245
246 "$SRCDIR/configure" "${CONF_OPTS[@]}" || failed_configure
247 ;;
248
249 dist)
250 echo "Distribution in-tree build"
251
252 # Run configure and generate the tar file
253 # in the source directory
254 ./configure || failed_configure
255 $MAKE dist
256
257 # Create and enter a temporary build directory
258 builddir=$(mktemp -d)
259 cd "$builddir"
260
261 # Extract the distribution tar in the build directory,
262 # ignore the first directory level
263 $TAR xvf "$SRCDIR"/*.tar.* --strip 1
264
265 # Build in extracted source tree
266 ./configure "${CONF_OPTS[@]}" || failed_configure
267 ;;
268
269 oot-dist)
270 echo "Distribution out of tree build"
271
272 # Create and enter a temporary build directory
273 builddir=$(mktemp -d)
274 cd "$builddir"
275
276 # Run configure out of tree and generate the tar file
277 "$SRCDIR/configure" || failed_configure
278 $MAKE dist
279
280 dist_srcdir="$(mktemp -d)"
281 cd "$dist_srcdir"
282
283 # Extract the distribution tar in the new source directory,
284 # ignore the first directory level
285 $TAR xvf "$builddir"/*.tar.* --strip 1
286
287 # Create and enter a second temporary build directory
288 builddir="$(mktemp -d)"
289 cd "$builddir"
290
291 # Run configure from the extracted distribution tar,
292 # out of the source tree
293 "$dist_srcdir/configure" "${CONF_OPTS[@]}" || failed_configure
294 ;;
295
296 *)
297 echo "Standard in-tree build"
298 ./configure "${CONF_OPTS[@]}" || failed_configure
299 ;;
300 esac
301
302 # We are now inside a configured build directory
303
304 # BUILD!
305 $MAKE -j "$($NPROC)" V=1
306
307 # Install in the workspace
308 $MAKE install DESTDIR="$WORKSPACE"
309
310 # Run tests, don't fail now, we want to run the archiving steps
311 failed_tests=0
312 if [ "$USERSPACE_RCU_RUN_TESTS" = "yes" ]; then
313 $MAKE --keep-going check || failed_tests=1
314 # Only run regtest for 0.9 and up
315 if vergte "$PACKAGE_VERSION" "0.9"; then
316 $MAKE --keep-going regtest || failed_tests=1
317 fi
318
319 # Copy tap logs for the jenkins tap parser before cleaning the build dir
320 rsync -a --exclude 'test-suite.log' --include '*/' --include '*.log' --exclude='*' tests/ "$WORKSPACE/tap"
321
322 # The test suite prior to 0.11 did not produce TAP logs
323 if verlt "$PACKAGE_VERSION" "0.11"; then
324 mkdir -p "$WORKSPACE/tap/no-log"
325 echo "1..1" > "$WORKSPACE/tap/no-log/tests.log"
326 echo "ok 1 - Test suite doesn't support logging" >> "$WORKSPACE/tap/no-log/tests.log"
327 fi
328 fi
329
330 # Clean the build directory
331 $MAKE clean
332
333 # Cleanup rpath in executables and shared libraries
334 #find "$WORKSPACE/$PREFIX/bin" -type f -perm -0500 -exec chrpath --delete {} \;
335 find "$WORKSPACE/$PREFIX/$LIBDIR_ARCH" -name "*.so" -exec chrpath --delete {} \;
336
337 # Remove libtool .la files
338 find "$WORKSPACE/$PREFIX/$LIBDIR_ARCH" -name "*.la" -exec rm -f {} \;
339
340 # Exit with failure if any of the tests failed
341 exit $failed_tests
342
343 # EOF
This page took 0.0360819999999999 seconds and 3 git commands to generate.