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=. | |
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 | 49 | verlte() { |
0a6e708b MJ |
50 | vercomp "$1" "$2"; local res="$?" |
51 | [ "$res" -eq "0" ] || [ "$res" -eq "2" ] | |
5fd8db76 MJ |
52 | } |
53 | ||
54 | verlt() { | |
0a6e708b MJ |
55 | vercomp "$1" "$2"; local res="$?" |
56 | [ "$res" -eq "2" ] | |
5fd8db76 MJ |
57 | } |
58 | ||
59 | vergte() { | |
0a6e708b MJ |
60 | vercomp "$1" "$2"; local res="$?" |
61 | [ "$res" -eq "0" ] || [ "$res" -eq "1" ] | |
5fd8db76 MJ |
62 | } |
63 | ||
64 | vergt() { | |
0a6e708b MJ |
65 | vercomp "$1" "$2"; local res="$?" |
66 | [ "$res" -eq "1" ] | |
67 | } | |
68 | ||
69 | verne() { | |
70 | vercomp "$1" "$2"; local res="$?" | |
71 | [ "$res" -ne "0" ] | |
5fd8db76 MJ |
72 | } |
73 | ||
51c9c62d MJ |
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 | ||
1d56e325 MJ |
84 | # Required variables |
85 | WORKSPACE=${WORKSPACE:-} | |
86 | ||
a57a60d9 MJ |
87 | arch=${arch:-} |
88 | conf=${conf:-} | |
89 | build=${build:-} | |
1d56e325 | 90 | cc=${cc:-} |
a57a60d9 | 91 | |
e3022ad9 | 92 | |
6d35c326 MJ |
93 | SRCDIR="$WORKSPACE/src/liburcu" |
94 | TMPDIR="$WORKSPACE/tmp" | |
1d56e325 | 95 | PREFIX="/build" |
69d7af71 | 96 | |
1d56e325 MJ |
97 | # Create tmp directory |
98 | rm -rf "$TMPDIR" | |
99 | mkdir -p "$TMPDIR" | |
6d35c326 MJ |
100 | |
101 | export TMPDIR | |
72d087d4 | 102 | export CFLAGS="-g -O2" |
6d35c326 | 103 | |
1d56e325 MJ |
104 | # Set compiler variables |
105 | case "$cc" in | |
106 | gcc) | |
107 | export CC=gcc | |
108 | export CXX=g++ | |
109 | ;; | |
110 | gcc-4.8) | |
111 | export CC=gcc-4.8 | |
112 | export CXX=g++-4.8 | |
113 | ;; | |
114 | gcc-5) | |
115 | export CC=gcc-5 | |
116 | export CXX=g++-5 | |
117 | ;; | |
118 | gcc-6) | |
119 | export CC=gcc-6 | |
120 | export CXX=g++-6 | |
121 | ;; | |
122 | gcc-7) | |
123 | export CC=gcc-7 | |
124 | export CXX=g++-7 | |
125 | ;; | |
126 | gcc-8) | |
127 | export CC=gcc-8 | |
128 | export CXX=g++-8 | |
129 | ;; | |
130 | clang) | |
131 | export CC=clang | |
132 | export CXX=clang++ | |
133 | ;; | |
134 | clang-3.9) | |
135 | export CC=clang-3.9 | |
136 | export CXX=clang++-3.9 | |
137 | ;; | |
138 | clang-4.0) | |
139 | export CC=clang-4.0 | |
140 | export CXX=clang++-4.0 | |
141 | ;; | |
142 | clang-5.0) | |
143 | export CC=clang-5.0 | |
144 | export CXX=clang++-5.0 | |
145 | ;; | |
146 | clang-6.0) | |
147 | export CC=clang-6.0 | |
148 | export CXX=clang++-6.0 | |
149 | ;; | |
150 | clang-7) | |
151 | export CC=clang-7 | |
152 | export CXX=clang++-7 | |
153 | ;; | |
154 | *) | |
155 | if [ "x$cc" != "x" ]; then | |
156 | export CC="$cc" | |
157 | fi | |
158 | ;; | |
159 | esac | |
160 | ||
161 | if [ "x${CC:-}" != "x" ]; then | |
162 | echo "Selected compiler:" | |
163 | "$CC" -v | |
164 | fi | |
165 | ||
72f4f0c1 | 166 | # Set platform variables |
7491c28d | 167 | case "$arch" in |
995ac8f2 MJ |
168 | sol10-i386) |
169 | export MAKE=gmake | |
170 | export TAR=gtar | |
171 | export NPROC=gnproc | |
ad11244c | 172 | export PATH="/opt/csw/bin:/usr/ccs/bin:$PATH" |
995ac8f2 MJ |
173 | export CPPFLAGS="-I/opt/csw/include" |
174 | export LDFLAGS="-L/opt/csw/lib -R/opt/csw/lib" | |
175 | export PKG_CONFIG_PATH="/opt/csw/lib/pkgconfig" | |
1d56e325 MJ |
176 | export PYTHON="python3" |
177 | export PYTHON_CONFIG="python3-config" | |
7491c28d | 178 | ;; |
1d56e325 | 179 | |
995ac8f2 MJ |
180 | sol11-i386) |
181 | export MAKE=gmake | |
182 | export TAR=gtar | |
183 | export NPROC=nproc | |
f2cd0939 | 184 | export PATH="/opt/csw/bin:$PATH:/usr/perl5/bin" |
1d56e325 MJ |
185 | export LD_ALTEXEC=/usr/bin/gld |
186 | export LD=/usr/bin/gld | |
187 | export PYTHON="python3" | |
188 | export PYTHON_CONFIG="python3-config" | |
f2cd0939 | 189 | export PKG_CONFIG_PATH="/usr/lib/pkgconfig" |
7491c28d | 190 | ;; |
1d56e325 | 191 | |
f0d7e5b1 | 192 | macos*) |
995ac8f2 MJ |
193 | export MAKE=make |
194 | export TAR=tar | |
195 | export NPROC="getconf _NPROCESSORS_ONLN" | |
f7bf4d7a | 196 | export PATH="/opt/local/bin:/opt/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin" |
1d56e325 MJ |
197 | export CPPFLAGS="-I/opt/local/include" |
198 | export LDFLAGS="-L/opt/local/lib" | |
0ef2148a MJ |
199 | export PYTHON="python3.9" |
200 | export PYTHON_CONFIG="python3.9-config" | |
f7bf4d7a MJ |
201 | ;; |
202 | ||
6ad0e7e6 MJ |
203 | freebsd) |
204 | export MAKE=gmake | |
205 | export TAR=tar | |
206 | export NPROC="getconf _NPROCESSORS_ONLN" | |
207 | export CPPFLAGS="-I/usr/local/include" | |
208 | export LDFLAGS="-L/usr/local/lib" | |
209 | export PYTHON="python3" | |
210 | export PYTHON_CONFIG="python3-config" | |
211 | ;; | |
212 | ||
7491c28d | 213 | *) |
995ac8f2 MJ |
214 | export MAKE=make |
215 | export TAR=tar | |
216 | export NPROC=nproc | |
1d56e325 MJ |
217 | export PYTHON="python3" |
218 | export PYTHON_CONFIG="python3-config" | |
7491c28d MJ |
219 | ;; |
220 | esac | |
221 | ||
51c9c62d MJ |
222 | # Print build env details |
223 | print_os || true | |
224 | print_tooling || true | |
225 | ||
cd9733d5 JR |
226 | # Enter the source directory |
227 | cd "$SRCDIR" | |
228 | ||
229 | # Run bootstrap in the source directory prior to configure | |
230 | ./bootstrap | |
231 | ||
232 | # Get source version from configure script | |
233 | eval "$(grep '^PACKAGE_VERSION=' ./configure)" | |
1d56e325 | 234 | PACKAGE_VERSION=${PACKAGE_VERSION//\-pre*/} |
cd9733d5 JR |
235 | |
236 | # Set configure options and environment variables for each build | |
237 | # configuration. | |
1d56e325 | 238 | CONF_OPTS=("--prefix=$PREFIX") |
56162e2a JRJ |
239 | case "$conf" in |
240 | static) | |
1d56e325 MJ |
241 | echo "Static lib only configuration" |
242 | ||
243 | CONF_OPTS+=("--enable-static" "--disable-shared") | |
56162e2a | 244 | ;; |
72f4f0c1 | 245 | |
a57a60d9 | 246 | tls_fallback) |
56162e2a | 247 | echo "Using pthread_getspecific() to emulate TLS" |
1d56e325 | 248 | CONF_OPTS+=("--disable-compiler-tls") |
56162e2a | 249 | ;; |
72f4f0c1 | 250 | |
cd9733d5 JR |
251 | debug-rcu) |
252 | echo "Enable RCU sanity checks for debugging" | |
a0493692 | 253 | if vergte "$PACKAGE_VERSION" "0.10"; then |
1d56e325 | 254 | CONF_OPTS+=("--enable-rcu-debug") |
cd9733d5 | 255 | else |
72d087d4 | 256 | export CFLAGS="$CFLAGS -DDEBUG_RCU" |
cd9733d5 | 257 | fi |
25e13783 JR |
258 | |
259 | echo "Enable iterator sanity validator" | |
260 | if vergte "$PACKAGE_VERSION" "0.11"; then | |
1d56e325 | 261 | CONF_OPTS+=("--enable-cds-lfht-iter-debug") |
25e13783 | 262 | fi |
cd9733d5 JR |
263 | ;; |
264 | ||
56162e2a | 265 | *) |
1d56e325 | 266 | echo "Standard configuration" |
56162e2a JRJ |
267 | ;; |
268 | esac | |
269 | ||
595a34c7 | 270 | # Build type |
1d56e325 MJ |
271 | # oot : out-of-tree build |
272 | # dist : build via make dist | |
273 | # oot-dist: build via make dist out-of-tree | |
274 | # * : normal tree build | |
595a34c7 | 275 | # |
1d56e325 | 276 | # Make sure to move to the build directory and run configure |
69d7af71 | 277 | # before continuing. |
595a34c7 | 278 | case "$build" in |
72f4f0c1 MJ |
279 | oot) |
280 | echo "Out of tree build" | |
69d7af71 | 281 | |
1d56e325 MJ |
282 | # Create and enter a temporary build directory |
283 | builddir=$(mktemp -d) | |
284 | cd "$builddir" | |
69d7af71 | 285 | |
51c9c62d | 286 | "$SRCDIR/configure" "${CONF_OPTS[@]}" || failed_configure |
72f4f0c1 MJ |
287 | ;; |
288 | ||
289 | dist) | |
1d56e325 MJ |
290 | echo "Distribution in-tree build" |
291 | ||
292 | # Run configure and generate the tar file | |
293 | # in the source directory | |
51c9c62d | 294 | ./configure || failed_configure |
1d56e325 MJ |
295 | $MAKE dist |
296 | ||
297 | # Create and enter a temporary build directory | |
298 | builddir=$(mktemp -d) | |
299 | cd "$builddir" | |
300 | ||
301 | # Extract the distribution tar in the build directory, | |
302 | # ignore the first directory level | |
303 | $TAR xvf "$SRCDIR"/*.tar.* --strip 1 | |
304 | ||
305 | # Build in extracted source tree | |
51c9c62d | 306 | ./configure "${CONF_OPTS[@]}" || failed_configure |
1d56e325 MJ |
307 | ;; |
308 | ||
309 | oot-dist) | |
72f4f0c1 | 310 | echo "Distribution out of tree build" |
72f4f0c1 | 311 | |
1d56e325 MJ |
312 | # Create and enter a temporary build directory |
313 | builddir=$(mktemp -d) | |
314 | cd "$builddir" | |
69d7af71 | 315 | |
1d56e325 | 316 | # Run configure out of tree and generate the tar file |
51c9c62d | 317 | "$SRCDIR/configure" || failed_configure |
72f4f0c1 MJ |
318 | $MAKE dist |
319 | ||
1d56e325 MJ |
320 | dist_srcdir="$(mktemp -d)" |
321 | cd "$dist_srcdir" | |
72f4f0c1 | 322 | |
1d56e325 MJ |
323 | # Extract the distribution tar in the new source directory, |
324 | # ignore the first directory level | |
325 | $TAR xvf "$builddir"/*.tar.* --strip 1 | |
72f4f0c1 | 326 | |
1d56e325 MJ |
327 | # Create and enter a second temporary build directory |
328 | builddir="$(mktemp -d)" | |
329 | cd "$builddir" | |
330 | ||
331 | # Run configure from the extracted distribution tar, | |
332 | # out of the source tree | |
51c9c62d | 333 | "$dist_srcdir/configure" "${CONF_OPTS[@]}" || failed_configure |
72f4f0c1 | 334 | ;; |
1d56e325 | 335 | |
72f4f0c1 | 336 | *) |
6d35c326 | 337 | echo "Standard in-tree build" |
51c9c62d | 338 | ./configure "${CONF_OPTS[@]}" || failed_configure |
72f4f0c1 | 339 | ;; |
595a34c7 JR |
340 | esac |
341 | ||
1d56e325 MJ |
342 | # We are now inside a configured build directory |
343 | ||
72f4f0c1 | 344 | # BUILD! |
a57a60d9 | 345 | $MAKE -j "$($NPROC)" V=1 |
72f4f0c1 | 346 | |
1d56e325 MJ |
347 | # Install in the workspace |
348 | $MAKE install DESTDIR="$WORKSPACE" | |
349 | ||
350 | # Run tests, don't fail now, we want to run the archiving steps | |
351 | failed_tests=0 | |
352 | $MAKE --keep-going check || failed_tests=1 | |
5fd8db76 MJ |
353 | # Only run regtest for 0.9 and up |
354 | if vergte "$PACKAGE_VERSION" "0.9"; then | |
1d56e325 | 355 | $MAKE --keep-going regtest || failed_tests=1 |
5fd8db76 | 356 | fi |
72f4f0c1 | 357 | |
1d56e325 | 358 | # Copy tap logs for the jenkins tap parser before cleaning the build dir |
69d7af71 MJ |
359 | rsync -a --exclude 'test-suite.log' --include '*/' --include '*.log' --exclude='*' tests/ "$WORKSPACE/tap" |
360 | ||
e5d878d8 MJ |
361 | # The test suite prior to 0.11 did not produce TAP logs |
362 | if verlt "$PACKAGE_VERSION" "0.11"; then | |
363 | mkdir -p "$WORKSPACE/tap/no-log" | |
364 | echo "1..1" > "$WORKSPACE/tap/no-log/tests.log" | |
365 | echo "ok 1 - Test suite doesn't support logging" >> "$WORKSPACE/tap/no-log/tests.log" | |
366 | fi | |
367 | ||
1d56e325 | 368 | # Clean the build directory |
7491c28d | 369 | $MAKE clean |
56162e2a | 370 | |
72f4f0c1 | 371 | # Cleanup rpath in executables and shared libraries |
1d56e325 MJ |
372 | #find "$WORKSPACE/$PREFIX/bin" -type f -perm -0500 -exec chrpath --delete {} \; |
373 | find "$WORKSPACE/$PREFIX/lib" -name "*.so" -exec chrpath --delete {} \; | |
72f4f0c1 MJ |
374 | |
375 | # Remove libtool .la files | |
1d56e325 | 376 | find "$WORKSPACE/$PREFIX/lib" -name "*.la" -exec rm -f {} \; |
595a34c7 | 377 | |
1d56e325 MJ |
378 | # Exit with failure if any of the tests failed |
379 | exit $failed_tests | |
7491c28d MJ |
380 | |
381 | # EOF |