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