jjb: babeltrace: use --enable-asan (on some builds)
[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 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
49 verlte() {
50 vercomp "$1" "$2"; local res="$?"
51 [ "$res" -eq "0" ] || [ "$res" -eq "2" ]
52 }
53
54 verlt() {
55 vercomp "$1" "$2"; local res="$?"
56 [ "$res" -eq "2" ]
57 }
58
59 vergte() {
60 vercomp "$1" "$2"; local res="$?"
61 [ "$res" -eq "0" ] || [ "$res" -eq "1" ]
62 }
63
64 vergt() {
65 vercomp "$1" "$2"; local res="$?"
66 [ "$res" -eq "1" ]
67 }
68
69 verne() {
70 vercomp "$1" "$2"; local res="$?"
71 [ "$res" -ne "0" ]
72 }
73
74 failed_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
84 # Required variables
85 WORKSPACE=${WORKSPACE:-}
86
87 platform=${platform:-}
88 conf=${conf:-}
89 build=${build:-}
90 cc=${cc:-}
91
92 # Controls if the tests are run
93 USERSPACE_RCU_RUN_TESTS="${USERSPACE_RCU_RUN_TESTS:=yes}"
94
95 SRCDIR="$WORKSPACE/src/liburcu"
96 TMPDIR="$WORKSPACE/tmp"
97 PREFIX="/build"
98
99 # Create tmp directory
100 rm -rf "$TMPDIR"
101 mkdir -p "$TMPDIR"
102
103 export TMPDIR
104 export CFLAGS="-g -O2"
105
106 # Set compiler variables
107 case "$cc" in
108 gcc)
109 export CC=gcc
110 export CXX=g++
111 ;;
112 gcc-*)
113 export CC=gcc-${cc#gcc-}
114 export CXX=g++-${cc#gcc-}
115 ;;
116 clang)
117 export CC=clang
118 export CXX=clang++
119 ;;
120 clang-*)
121 export CC=clang-${cc#clang-}
122 export CXX=clang++-${cc#clang-}
123 ;;
124 *)
125 if [ "x$cc" != "x" ]; then
126 export CC="$cc"
127 fi
128 ;;
129 esac
130
131 if [ "x${CC:-}" != "x" ]; then
132 echo "Selected compiler:"
133 "$CC" -v
134 fi
135
136 # Set platform variables
137 case "$platform" in
138 macos*)
139 export MAKE=make
140 export TAR=tar
141 export NPROC="getconf _NPROCESSORS_ONLN"
142 export PATH="/opt/local/bin:/opt/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"
143 export CPPFLAGS="-I/opt/local/include"
144 export LDFLAGS="-L/opt/local/lib"
145 export PYTHON="python3"
146 export PYTHON_CONFIG="python3-config"
147 ;;
148
149 freebsd*)
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
159 *)
160 export MAKE=make
161 export TAR=tar
162 export NPROC=nproc
163 export PYTHON="python3"
164 export PYTHON_CONFIG="python3-config"
165 ;;
166 esac
167
168 # Print build env details
169 print_os || true
170 print_tooling || true
171
172 # Enter the source directory
173 cd "$SRCDIR"
174
175 # Run bootstrap in the source directory prior to configure
176 ./bootstrap
177
178 # Get source version from configure script
179 eval "$(grep '^PACKAGE_VERSION=' ./configure)"
180 PACKAGE_VERSION=${PACKAGE_VERSION//\-pre*/}
181
182 # Set configure options and environment variables for each build
183 # configuration.
184 CONF_OPTS=("--prefix=$PREFIX")
185 case "$conf" in
186 static)
187 echo "Static lib only configuration"
188
189 CONF_OPTS+=("--enable-static" "--disable-shared")
190 ;;
191
192 tls_fallback)
193 echo "Using pthread_getspecific() to emulate TLS"
194 CONF_OPTS+=("--disable-compiler-tls")
195 ;;
196
197 debug-rcu)
198 echo "Enable RCU sanity checks for debugging"
199 if vergte "$PACKAGE_VERSION" "0.10"; then
200 CONF_OPTS+=("--enable-rcu-debug")
201 else
202 export CFLAGS="$CFLAGS -DDEBUG_RCU"
203 fi
204
205 echo "Enable iterator sanity validator"
206 if vergte "$PACKAGE_VERSION" "0.11"; then
207 CONF_OPTS+=("--enable-cds-lfht-iter-debug")
208 fi
209 ;;
210
211 *)
212 echo "Standard configuration"
213 ;;
214 esac
215
216 # Build type
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
221 #
222 # Make sure to move to the build directory and run configure
223 # before continuing.
224 case "$build" in
225 oot)
226 echo "Out of tree build"
227
228 # Create and enter a temporary build directory
229 builddir=$(mktemp -d)
230 cd "$builddir"
231
232 "$SRCDIR/configure" "${CONF_OPTS[@]}" || failed_configure
233 ;;
234
235 dist)
236 echo "Distribution in-tree build"
237
238 # Run configure and generate the tar file
239 # in the source directory
240 ./configure || failed_configure
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
252 ./configure "${CONF_OPTS[@]}" || failed_configure
253 ;;
254
255 oot-dist)
256 echo "Distribution out of tree build"
257
258 # Create and enter a temporary build directory
259 builddir=$(mktemp -d)
260 cd "$builddir"
261
262 # Run configure out of tree and generate the tar file
263 "$SRCDIR/configure" || failed_configure
264 $MAKE dist
265
266 dist_srcdir="$(mktemp -d)"
267 cd "$dist_srcdir"
268
269 # Extract the distribution tar in the new source directory,
270 # ignore the first directory level
271 $TAR xvf "$builddir"/*.tar.* --strip 1
272
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
279 "$dist_srcdir/configure" "${CONF_OPTS[@]}" || failed_configure
280 ;;
281
282 *)
283 echo "Standard in-tree build"
284 ./configure "${CONF_OPTS[@]}" || failed_configure
285 ;;
286 esac
287
288 # We are now inside a configured build directory
289
290 # BUILD!
291 $MAKE -j "$($NPROC)" V=1
292
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
297 failed_tests=0
298 if [ "$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
304
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"
307
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
314 fi
315
316 # Clean the build directory
317 $MAKE clean
318
319 # Cleanup rpath in executables and shared libraries
320 #find "$WORKSPACE/$PREFIX/bin" -type f -perm -0500 -exec chrpath --delete {} \;
321 find "$WORKSPACE/$PREFIX/lib" -name "*.so" -exec chrpath --delete {} \;
322
323 # Remove libtool .la files
324 find "$WORKSPACE/$PREFIX/lib" -name "*.la" -exec rm -f {} \;
325
326 # Exit with failure if any of the tests failed
327 exit $failed_tests
328
329 # EOF
This page took 0.055787 seconds and 4 git commands to generate.