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