| 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 | DEPS_INC="$WORKSPACE/deps/build/include" |
| 82 | DEPS_LIB="$WORKSPACE/deps/build/lib" |
| 83 | #DEPS_BIN="$WORKSPACE/deps/build/bin" |
| 84 | #DEPS_JAVA="$WORKSPACE/deps/build/share/java" |
| 85 | |
| 86 | export LD_LIBRARY_PATH="$DEPS_LIB:${LD_LIBRARY_PATH:-}" |
| 87 | export CPPFLAGS="-I$DEPS_INC" |
| 88 | export LDFLAGS="-L$DEPS_LIB" |
| 89 | |
| 90 | SRCDIR="$WORKSPACE/src/lttng-ust" |
| 91 | TMPDIR="$WORKSPACE/tmp" |
| 92 | PREFIX="/build" |
| 93 | |
| 94 | # Create tmp directory |
| 95 | rm -rf "$TMPDIR" |
| 96 | mkdir -p "$TMPDIR" |
| 97 | |
| 98 | export TMPDIR |
| 99 | export CFLAGS="-g -O2" |
| 100 | |
| 101 | # Set compiler variables |
| 102 | case "$cc" in |
| 103 | gcc) |
| 104 | export CC=gcc |
| 105 | export CXX=g++ |
| 106 | ;; |
| 107 | gcc-4.8) |
| 108 | export CC=gcc-4.8 |
| 109 | export CXX=g++-4.8 |
| 110 | ;; |
| 111 | gcc-5) |
| 112 | export CC=gcc-5 |
| 113 | export CXX=g++-5 |
| 114 | ;; |
| 115 | gcc-6) |
| 116 | export CC=gcc-6 |
| 117 | export CXX=g++-6 |
| 118 | ;; |
| 119 | gcc-7) |
| 120 | export CC=gcc-7 |
| 121 | export CXX=g++-7 |
| 122 | ;; |
| 123 | gcc-8) |
| 124 | export CC=gcc-8 |
| 125 | export CXX=g++-8 |
| 126 | ;; |
| 127 | clang) |
| 128 | export CC=clang |
| 129 | export CXX=clang++ |
| 130 | ;; |
| 131 | clang-3.9) |
| 132 | export CC=clang-3.9 |
| 133 | export CXX=clang++-3.9 |
| 134 | ;; |
| 135 | clang-4.0) |
| 136 | export CC=clang-4.0 |
| 137 | export CXX=clang++-4.0 |
| 138 | ;; |
| 139 | clang-5.0) |
| 140 | export CC=clang-5.0 |
| 141 | export CXX=clang++-5.0 |
| 142 | ;; |
| 143 | clang-6.0) |
| 144 | export CC=clang-6.0 |
| 145 | export CXX=clang++-6.0 |
| 146 | ;; |
| 147 | clang-7) |
| 148 | export CC=clang-7 |
| 149 | export CXX=clang++-7 |
| 150 | ;; |
| 151 | *) |
| 152 | if [ "x$cc" != "x" ]; then |
| 153 | export CC="$cc" |
| 154 | fi |
| 155 | ;; |
| 156 | esac |
| 157 | |
| 158 | if [ "x${CC:-}" != "x" ]; then |
| 159 | echo "Selected compiler:" |
| 160 | "$CC" -v |
| 161 | fi |
| 162 | |
| 163 | # Set platform variables |
| 164 | case "$arch" in |
| 165 | *) |
| 166 | export MAKE=make |
| 167 | export TAR=tar |
| 168 | export NPROC=nproc |
| 169 | export PYTHON="python3" |
| 170 | export PYTHON_CONFIG="python3-config" |
| 171 | ;; |
| 172 | esac |
| 173 | |
| 174 | # Enter the source directory |
| 175 | cd "$SRCDIR" |
| 176 | |
| 177 | # Run bootstrap in the source directory prior to configure |
| 178 | ./bootstrap |
| 179 | |
| 180 | # Get source version from configure script |
| 181 | eval "$(grep '^PACKAGE_VERSION=' ./configure)" |
| 182 | PACKAGE_VERSION=${PACKAGE_VERSION//\-pre*/} |
| 183 | |
| 184 | # Set configure options and environment variables for each build |
| 185 | # configuration. |
| 186 | CONF_OPTS=("--prefix=$PREFIX") |
| 187 | case "$conf" in |
| 188 | static) |
| 189 | echo "Static lib only configuration" |
| 190 | |
| 191 | CONF_OPTS+=("--enable-static" "--disable-shared") |
| 192 | |
| 193 | # Unsupported! liblttng-ust can't pull in it's static (.a) dependencies. |
| 194 | exit 1 |
| 195 | ;; |
| 196 | |
| 197 | agents) |
| 198 | echo "Java and Python agents configuration" |
| 199 | |
| 200 | export CLASSPATH="/usr/share/java/log4j-1.2.jar" |
| 201 | CONF_OPTS+=("--enable-java-agent-all" "--enable-jni-interface" "--enable-python-agent") |
| 202 | ;; |
| 203 | |
| 204 | debug-rcu) |
| 205 | echo "Enable RCU sanity checks for debugging" |
| 206 | export CPPFLAGS="${CPPFLAGS} -DDEBUG_RCU" |
| 207 | ;; |
| 208 | |
| 209 | *) |
| 210 | echo "Standard configuration" |
| 211 | ;; |
| 212 | esac |
| 213 | |
| 214 | # Build type |
| 215 | # oot : out-of-tree build |
| 216 | # dist : build via make dist |
| 217 | # oot-dist: build via make dist out-of-tree |
| 218 | # * : normal tree build |
| 219 | # |
| 220 | # Make sure to move to the build directory and run configure |
| 221 | # before continuing. |
| 222 | case "$build" in |
| 223 | oot) |
| 224 | echo "Out of tree build" |
| 225 | |
| 226 | # Create and enter a temporary build directory |
| 227 | builddir=$(mktemp -d) |
| 228 | cd "$builddir" |
| 229 | |
| 230 | "$SRCDIR/configure" "${CONF_OPTS[@]}" |
| 231 | ;; |
| 232 | |
| 233 | dist) |
| 234 | echo "Distribution in-tree build" |
| 235 | |
| 236 | # Run configure and generate the tar file |
| 237 | # in the source directory |
| 238 | ./configure |
| 239 | $MAKE dist |
| 240 | |
| 241 | # Create and enter a temporary build directory |
| 242 | builddir=$(mktemp -d) |
| 243 | cd "$builddir" |
| 244 | |
| 245 | # Extract the distribution tar in the build directory, |
| 246 | # ignore the first directory level |
| 247 | $TAR xvf "$SRCDIR"/*.tar.* --strip 1 |
| 248 | |
| 249 | # Build in extracted source tree |
| 250 | ./configure "${CONF_OPTS[@]}" |
| 251 | ;; |
| 252 | |
| 253 | oot-dist) |
| 254 | echo "Distribution out of tree build" |
| 255 | |
| 256 | # Create and enter a temporary build directory |
| 257 | builddir=$(mktemp -d) |
| 258 | cd "$builddir" |
| 259 | |
| 260 | # Run configure out of tree and generate the tar file |
| 261 | "$SRCDIR/configure" |
| 262 | $MAKE dist |
| 263 | |
| 264 | dist_srcdir="$(mktemp -d)" |
| 265 | cd "$dist_srcdir" |
| 266 | |
| 267 | # Extract the distribution tar in the new source directory, |
| 268 | # ignore the first directory level |
| 269 | $TAR xvf "$builddir"/*.tar.* --strip 1 |
| 270 | |
| 271 | # Create and enter a second temporary build directory |
| 272 | builddir="$(mktemp -d)" |
| 273 | cd "$builddir" |
| 274 | |
| 275 | # Run configure from the extracted distribution tar, |
| 276 | # out of the source tree |
| 277 | "$dist_srcdir/configure" "${CONF_OPTS[@]}" |
| 278 | ;; |
| 279 | |
| 280 | *) |
| 281 | echo "Standard in-tree build" |
| 282 | ./configure "${CONF_OPTS[@]}" |
| 283 | ;; |
| 284 | esac |
| 285 | |
| 286 | # We are now inside a configured build directory |
| 287 | |
| 288 | # BUILD! |
| 289 | $MAKE -j "$($NPROC)" V=1 |
| 290 | |
| 291 | # Install in the workspace |
| 292 | $MAKE install DESTDIR="$WORKSPACE" |
| 293 | |
| 294 | # Run tests, don't fail now, we want to run the archiving steps |
| 295 | failed_tests=0 |
| 296 | $MAKE --keep-going check || failed_tests=1 |
| 297 | |
| 298 | # Copy tap logs for the jenkins tap parser before cleaning the build dir |
| 299 | rsync -a --exclude 'test-suite.log' --include '*/' --include '*.log' --exclude='*' tests/ "$WORKSPACE/tap" |
| 300 | |
| 301 | # The test suite prior to 2.8 did not produce TAP logs |
| 302 | if verlt "$PACKAGE_VERSION" "2.8"; then |
| 303 | mkdir -p "$WORKSPACE/tap/no-log" |
| 304 | echo "1..1" > "$WORKSPACE/tap/no-log/tests.log" |
| 305 | echo "ok 1 - Test suite doesn't support logging" >> "$WORKSPACE/tap/no-log/tests.log" |
| 306 | fi |
| 307 | |
| 308 | # Clean the build directory |
| 309 | $MAKE clean |
| 310 | |
| 311 | # Cleanup rpath in executables and shared libraries |
| 312 | #find "$WORKSPACE/$PREFIX/bin" -type f -perm -0500 -exec chrpath --delete {} \; |
| 313 | find "$WORKSPACE/$PREFIX/lib" -name "*.so" -exec chrpath --delete {} \; |
| 314 | |
| 315 | # Remove libtool .la files |
| 316 | find "$WORKSPACE/$PREFIX/lib" -name "*.la" -exec rm -f {} \; |
| 317 | |
| 318 | # Exit with failure if any of the tests failed |
| 319 | exit $failed_tests |
| 320 | |
| 321 | # EOF |