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