jjb: extend 'libdir = lib64' to yocto
[lttng-ci.git] / scripts / lttng-ust / build.sh
1 #!/bin/bash
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 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 # Ignore the shellcheck warning, we want splitting to happen based on IFS.
29 # shellcheck disable=SC2206
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
51 verlte() {
52 vercomp "$1" "$2"; local res="$?"
53 [ "$res" -eq "0" ] || [ "$res" -eq "2" ]
54 }
55
56 verlt() {
57 vercomp "$1" "$2"; local res="$?"
58 [ "$res" -eq "2" ]
59 }
60
61 vergte() {
62 vercomp "$1" "$2"; local res="$?"
63 [ "$res" -eq "0" ] || [ "$res" -eq "1" ]
64 }
65
66 vergt() {
67 vercomp "$1" "$2"; local res="$?"
68 [ "$res" -eq "1" ]
69 }
70
71 verne() {
72 vercomp "$1" "$2"; local res="$?"
73 [ "$res" -ne "0" ]
74 }
75
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
86 # Required variables
87 WORKSPACE=${WORKSPACE:-}
88
89 platform=${platform:-}
90 conf=${conf:-}
91 build=${build:-}
92 cc=${cc:-}
93
94 # Controls if the tests are run
95 LTTNG_UST_RUN_TESTS="${LTTNG_UST_RUN_TESTS:=yes}"
96
97 SRCDIR="$WORKSPACE/src/lttng-ust"
98 TMPDIR="$WORKSPACE/tmp"
99 PREFIX="/build"
100 LIBDIR="lib"
101
102 # RHEL and SLES both use lib64 but don't bother shipping a default autoconf
103 # site config that matches this.
104 if [[ ( -f /etc/redhat-release || -f /etc/SuSE-release || -f /etc/yocto-release ) ]]; then
105 # Detect the userspace bitness in a distro agnostic way
106 if file -L /bin/bash | grep '64-bit' >/dev/null 2>&1; then
107 LIBDIR_ARCH="${LIBDIR}64"
108 else
109 LIBDIR_ARCH="$LIBDIR"
110 fi
111 fi
112
113 DEPS_INC="$WORKSPACE/deps/build/include"
114 DEPS_LIB="$WORKSPACE/deps/build/$LIBDIR_ARCH"
115 DEPS_PKGCONFIG="$DEPS_LIB/pkgconfig"
116 #DEPS_BIN="$WORKSPACE/deps/build/bin"
117 #DEPS_JAVA="$WORKSPACE/deps/build/share/java"
118
119 export LD_LIBRARY_PATH="$DEPS_LIB:${LD_LIBRARY_PATH:-}"
120 export PKG_CONFIG_PATH="$DEPS_PKGCONFIG"
121 export CPPFLAGS="-I$DEPS_INC"
122 export LDFLAGS="-L$DEPS_LIB"
123
124 # Create tmp directory
125 rm -rf "$TMPDIR"
126 mkdir -p "$TMPDIR"
127
128 export TMPDIR
129 export CFLAGS="-g -O2"
130
131 # Set compiler variables
132 case "$cc" in
133 gcc)
134 export CC=gcc
135 export CXX=g++
136 ;;
137 gcc-*)
138 export CC=gcc-${cc#gcc-}
139 export CXX=g++-${cc#gcc-}
140 ;;
141 clang)
142 export CC=clang
143 export CXX=clang++
144 ;;
145 clang-*)
146 export CC=clang-${cc#clang-}
147 export CXX=clang++-${cc#clang-}
148 ;;
149 *)
150 if [ "x$cc" != "x" ]; then
151 export CC="$cc"
152 fi
153 ;;
154 esac
155
156 if [ "x${CC:-}" != "x" ]; then
157 echo "Selected compiler:"
158 "$CC" -v
159 fi
160
161 # Set platform variables
162 case "$platform" in
163 freebsd*)
164 export MAKE=gmake
165 export TAR=tar
166 export NPROC="getconf _NPROCESSORS_ONLN"
167 export CPPFLAGS="-I/usr/local/include $CPPFLAGS"
168 export LDFLAGS="-L/usr/local/lib $LDFLAGS"
169 export PYTHON="python3"
170 export PYTHON_CONFIG="python3-config"
171 export CLASSPATH='/usr/local/share/java/classes/*'
172 export JAVA_HOME='/usr/local/openjdk11'
173 ;;
174
175 *)
176 export MAKE=make
177 export TAR=tar
178 export NPROC=nproc
179 export PYTHON="python3"
180 export PYTHON_CONFIG="python3-config"
181 export CLASSPATH='/usr/share/java/log4j-api.jar:/usr/share/java/log4j-core.jar:/usr/share/java/log4j-1.2.jar'
182 ;;
183 esac
184
185 # Print build env details
186 print_os || true
187 print_tooling || true
188
189 # Enter the source directory
190 cd "$SRCDIR"
191
192 # Run bootstrap in the source directory prior to configure
193 ./bootstrap
194
195 # Get source version from configure script
196 eval "$(grep '^PACKAGE_VERSION=' ./configure)"
197 PACKAGE_VERSION=${PACKAGE_VERSION//\-pre*/}
198
199 # Gerrit will trigger build on FreeBSD regardless of the branch, exit
200 # successfuly when the version is < 2.13.
201 if [[ $platform == freebsd* ]] && verlt "$PACKAGE_VERSION" "2.13"; then
202 mkdir -p "$WORKSPACE/tap/no-log"
203 echo "1..1" > "$WORKSPACE/tap/no-log/tests.log"
204 echo "ok 1 - FreeBSD build unsupported in < 2.13" >> "$WORKSPACE/tap/no-log/tests.log"
205 exit 0
206 fi
207
208 # Set configure options and environment variables for each build
209 # configuration.
210 CONF_OPTS=("--prefix=$PREFIX" "--libdir=$PREFIX/$LIBDIR_ARCH")
211 case "$conf" in
212 static)
213 echo "Static lib only configuration"
214
215 CONF_OPTS+=("--enable-static" "--disable-shared")
216
217 # Unsupported! liblttng-ust can't pull in it's static (.a) dependencies.
218 exit 1
219 ;;
220
221 agents)
222 echo "Java and Python agents configuration"
223
224 CONF_OPTS+=("--enable-java-agent-all" "--enable-jni-interface" "--enable-python-agent")
225
226 # Explicitly add '--enable-java-agent-log4j2', it's not part of '-all' in stable 2.12/2.13
227 if verlt "$PACKAGE_VERSION" "2.14"; then
228 CONF_OPTS+=("--enable-java-agent-log4j2")
229 fi
230 ;;
231
232 debug-rcu)
233 echo "Enable RCU sanity checks for debugging"
234 export CPPFLAGS="${CPPFLAGS} -DDEBUG_RCU"
235 ;;
236
237 *)
238 echo "Standard configuration"
239
240 # Something is broken in docbook-xml on yocto
241 if [[ "$platform" = yocto* ]]; then
242 CONF_OPTS+=("--disable-man-pages")
243 fi
244 ;;
245 esac
246
247 # Build type
248 # oot : out-of-tree build
249 # dist : build via make dist
250 # oot-dist: build via make dist out-of-tree
251 # * : normal tree build
252 #
253 # Make sure to move to the build directory and run configure
254 # before continuing.
255 case "$build" in
256 oot)
257 echo "Out of tree build"
258
259 # Create and enter a temporary build directory
260 builddir=$(mktemp -d)
261 cd "$builddir"
262
263 "$SRCDIR/configure" "${CONF_OPTS[@]}" || failed_configure
264 ;;
265
266 dist)
267 echo "Distribution in-tree build"
268
269 # Run configure and generate the tar file
270 # in the source directory
271 ./configure --enable-jni-interface || failed_configure
272 $MAKE dist
273
274 # Create and enter a temporary build directory
275 builddir=$(mktemp -d)
276 cd "$builddir"
277
278 # Extract the distribution tar in the build directory,
279 # ignore the first directory level
280 $TAR xvf "$SRCDIR"/*.tar.* --strip 1
281
282 # Build in extracted source tree
283 ./configure "${CONF_OPTS[@]}" || failed_configure
284 ;;
285
286 oot-dist)
287 echo "Distribution out of tree build"
288
289 # Create and enter a temporary build directory
290 builddir=$(mktemp -d)
291 cd "$builddir"
292
293 # Run configure out of tree and generate the tar file
294 "$SRCDIR/configure" --enable-jni-interface || failed_configure
295 $MAKE dist
296
297 dist_srcdir="$(mktemp -d)"
298 cd "$dist_srcdir"
299
300 # Extract the distribution tar in the new source directory,
301 # ignore the first directory level
302 $TAR xvf "$builddir"/*.tar.* --strip 1
303
304 # Create and enter a second temporary build directory
305 builddir="$(mktemp -d)"
306 cd "$builddir"
307
308 # Run configure from the extracted distribution tar,
309 # out of the source tree
310 "$dist_srcdir/configure" "${CONF_OPTS[@]}" || failed_configure
311 ;;
312
313 *)
314 echo "Standard in-tree build"
315 ./configure "${CONF_OPTS[@]}" || failed_configure
316 ;;
317 esac
318
319 # We are now inside a configured build directory
320
321 # BUILD!
322 $MAKE -j "$($NPROC)" V=1
323
324 # Install in the workspace
325 $MAKE install DESTDIR="$WORKSPACE"
326
327 # Run tests, don't fail now, we want to run the archiving steps
328 failed_tests=0
329 if [ "$LTTNG_UST_RUN_TESTS" = "yes" ]; then
330 $MAKE --keep-going check || failed_tests=1
331
332 # Copy tap logs for the jenkins tap parser before cleaning the build dir
333 rsync -a --exclude 'test-suite.log' --include '*/' --include '*.log' --exclude='*' tests/ "$WORKSPACE/tap"
334
335 # The test suite prior to 2.8 did not produce TAP logs
336 if verlt "$PACKAGE_VERSION" "2.8"; then
337 mkdir -p "$WORKSPACE/tap/no-log"
338 echo "1..1" > "$WORKSPACE/tap/no-log/tests.log"
339 echo "ok 1 - Test suite doesn't support logging" >> "$WORKSPACE/tap/no-log/tests.log"
340 fi
341 fi
342
343 # Clean the build directory
344 $MAKE clean
345
346 # Cleanup rpath in executables and shared libraries
347 #find "$WORKSPACE/$PREFIX/bin" -type f -perm -0500 -exec chrpath --delete {} \;
348 find "$WORKSPACE/$PREFIX/$LIBDIR_ARCH" -name "*.so" -exec chrpath --delete {} \;
349
350 # Remove libtool .la files
351 find "$WORKSPACE/$PREFIX/$LIBDIR_ARCH" -name "*.la" -exec rm -f {} \;
352
353 # Exit with failure if any of the tests failed
354 exit $failed_tests
355
356 # EOF
This page took 0.042947 seconds and 5 git commands to generate.