jjb: Add workaround for newer pahole versions with focal kernels
[lttng-ci.git] / scripts / librseq / build.sh
... / ...
CommitLineData
1#!/bin/bash
2#
3# SPDX-FileCopyrightText: 2015 Jonathan Rajotte-Julien <jonathan.rajotte-julien@efficios.com>
4# SPDX-FileCopyrightText: 2016-2023 Michael Jeanson <mjeanson@efficios.com>
5# SPDX-License-Identifier: GPL-2.0-or-later
6
7set -exu
8
9# Version compare functions
10vercomp () {
11 set +u
12 if [[ "$1" == "$2" ]]; then
13 return 0
14 fi
15 local IFS=.
16 # Ignore the shellcheck warning, we want splitting to happen based on IFS.
17 # shellcheck disable=SC2206
18 local i ver1=($1) ver2=($2)
19 # fill empty fields in ver1 with zeros
20 for ((i=${#ver1[@]}; i<${#ver2[@]}; i++)); do
21 ver1[i]=0
22 done
23 for ((i=0; i<${#ver1[@]}; i++)); do
24 if [[ -z ${ver2[i]} ]]; then
25 # fill empty fields in ver2 with zeros
26 ver2[i]=0
27 fi
28 if ((10#${ver1[i]} > 10#${ver2[i]})); then
29 return 1
30 fi
31 if ((10#${ver1[i]} < 10#${ver2[i]})); then
32 return 2
33 fi
34 done
35 set -u
36 return 0
37}
38
39verlte() {
40 vercomp "$1" "$2"; local res="$?"
41 [ "$res" -eq "0" ] || [ "$res" -eq "2" ]
42}
43
44verlt() {
45 vercomp "$1" "$2"; local res="$?"
46 [ "$res" -eq "2" ]
47}
48
49vergte() {
50 vercomp "$1" "$2"; local res="$?"
51 [ "$res" -eq "0" ] || [ "$res" -eq "1" ]
52}
53
54vergt() {
55 vercomp "$1" "$2"; local res="$?"
56 [ "$res" -eq "1" ]
57}
58
59verne() {
60 vercomp "$1" "$2"; local res="$?"
61 [ "$res" -ne "0" ]
62}
63
64print_header() {
65 set +x
66
67 local message=" $1 "
68 local message_len
69 local padding_len
70
71 message_len="${#message}"
72 padding_len=$(( (80 - (message_len)) / 2 ))
73
74 printf '\n'; printf -- '#%.0s' {1..80}; printf '\n'
75 printf -- '-%.0s' {1..80}; printf '\n'
76 printf -- '#%.0s' $(seq 1 $padding_len); printf '%s' "$message"; printf -- '#%.0s' $(seq 1 $padding_len); printf '\n'
77 printf -- '-%.0s' {1..80}; printf '\n'
78 printf -- '#%.0s' {1..80}; printf '\n\n'
79
80 set -x
81}
82
83failed_configure() {
84 # Assume we are in the configured build directory
85 print_header "BEGIN config.log"
86 cat config.log
87 print_header "END config.log"
88
89 # End the build with failure
90 exit 1
91}
92
93print_header "Librseq build script starting"
94
95# Required variables
96WORKSPACE=${WORKSPACE:-}
97
98# Axis
99platform=${platform:-}
100conf=${conf:-}
101build=${build:-}
102cc=${cc:-}
103
104# Build steps that can be overriden by the environment
105LIBRSEQ_MAKE_INSTALL="${LIBRSEQ_MAKE_INSTALL:-yes}"
106LIBRSEQ_MAKE_CLEAN="${LIBRSEQ_MAKE_CLEAN:-yes}"
107LIBRSEQ_GEN_COMPILE_COMMANDS="${LIBRSEQ_GEN_COMPILE_COMMANDS:-no}"
108LIBRSEQ_RUN_TESTS="${LIBRSEQ_RUN_TESTS:-yes}"
109
110SRCDIR="$WORKSPACE/src/librseq"
111TMPDIR="$WORKSPACE/tmp"
112PREFIX="/build"
113LIBDIR="lib"
114LIBDIR_ARCH="$LIBDIR"
115
116# RHEL and SLES both use lib64 but don't bother shipping a default autoconf
117# site config that matches this.
118if [[ ( -f /etc/redhat-release || -f /etc/products.d/SLES.prod || -f /etc/yocto-release ) ]]; then
119 # Detect the userspace bitness in a distro agnostic way
120 if file -L /bin/bash | grep '64-bit' >/dev/null 2>&1; then
121 LIBDIR_ARCH="${LIBDIR}64"
122 fi
123fi
124
125exit_status=0
126
127# Use bear to generate compile_commands.json when enabled
128BEAR=""
129if [ "$LIBRSEQ_GEN_COMPILE_COMMANDS" = "yes" ]; then
130 BEAR="bear"
131fi
132
133# Create tmp directory
134rm -rf "$TMPDIR"
135mkdir -p "$TMPDIR"
136
137export TMPDIR
138export CFLAGS="-g -O2"
139export CXXFLAGS="-g -O2"
140
141# Add the convenience headers in extra to the
142# include path.
143export CPPFLAGS="-I$SRCDIR/extra"
144
145# Set compiler variables
146case "$cc" in
147gcc)
148 export CC=gcc
149 export CXX=g++
150 ;;
151gcc-*)
152 export CC=gcc-${cc#gcc-}
153 export CXX=g++-${cc#gcc-}
154 ;;
155clang)
156 export CC=clang
157 export CXX=clang++
158 ;;
159clang-*)
160 export CC=clang-${cc#clang-}
161 export CXX=clang++-${cc#clang-}
162 ;;
163*)
164 if [ "x$cc" != "x" ]; then
165 export CC="$cc"
166 fi
167 ;;
168esac
169
170# Set platform variables
171case "$platform" in
172*)
173 export MAKE=make
174 export TAR=tar
175 export NPROC=nproc
176 export PYTHON="python3"
177 export PYTHON_CONFIG="python3-config"
178 ;;
179esac
180
181# Print build env details
182print_header "Build environment details"
183print_os || true
184print_tooling || true
185
186# Enter the source directory
187cd "$SRCDIR"
188
189# Run bootstrap in the source directory prior to configure
190print_header "Bootstrap autotools"
191./bootstrap
192
193# Get source version from configure script
194eval "$(grep '^PACKAGE_VERSION=' ./configure)"
195PACKAGE_VERSION=${PACKAGE_VERSION//\-pre*/}
196
197# Set configure options and environment variables for each build
198# configuration.
199CONF_OPTS=("--prefix=$PREFIX" "--libdir=$PREFIX/$LIBDIR_ARCH" "--disable-maintainer-mode")
200case "$conf" in
201static)
202 print_header "Conf: Static lib only"
203
204 CONF_OPTS+=("--enable-static" "--disable-shared")
205 ;;
206
207*)
208 print_header "Conf: Standard"
209 ;;
210esac
211
212# Build type
213# oot : out-of-tree build
214# dist : build via make dist
215# oot-dist: build via make dist out-of-tree
216# * : normal tree build
217#
218# Make sure to move to the build directory and run configure
219# before continuing.
220case "$build" in
221oot)
222 print_header "Build: Out of tree"
223
224 # Create and enter a temporary build directory
225 builddir=$(mktemp -d)
226 cd "$builddir"
227
228 "$SRCDIR/configure" "${CONF_OPTS[@]}" || failed_configure
229 ;;
230
231dist)
232 print_header "Build: Distribution In-tree"
233
234 # Run configure and generate the tar file
235 # in the source directory
236 ./configure || failed_configure
237 $MAKE dist
238
239 # Create and enter a temporary build directory
240 builddir=$(mktemp -d)
241 cd "$builddir"
242
243 # Extract the distribution tar in the build directory,
244 # ignore the first directory level
245 $TAR xvf "$SRCDIR"/*.tar.* --strip 1
246
247 # Build in extracted source tree
248 ./configure "${CONF_OPTS[@]}" || failed_configure
249 ;;
250
251oot-dist)
252 print_header "Build: Distribution Out of tree"
253
254 # Create and enter a temporary build directory
255 builddir=$(mktemp -d)
256 cd "$builddir"
257
258 # Run configure out of tree and generate the tar file
259 "$SRCDIR/configure" || failed_configure
260 $MAKE dist
261
262 dist_srcdir="$(mktemp -d)"
263 cd "$dist_srcdir"
264
265 # Extract the distribution tar in the new source directory,
266 # ignore the first directory level
267 $TAR xvf "$builddir"/*.tar.* --strip 1
268
269 # Create and enter a second temporary build directory
270 builddir="$(mktemp -d)"
271 cd "$builddir"
272
273 # Run configure from the extracted distribution tar,
274 # out of the source tree
275 "$dist_srcdir/configure" "${CONF_OPTS[@]}" || failed_configure
276 ;;
277
278*)
279 print_header "Build: Standard In-tree"
280
281 ./configure "${CONF_OPTS[@]}" || failed_configure
282 ;;
283esac
284
285# We are now inside a configured build directory
286
287# BUILD!
288print_header "BUILD!"
289$BEAR ${BEAR:+--} $MAKE -j "$($NPROC)" V=1
290
291# Install in the workspace if enabled
292if [ "$LIBRSEQ_MAKE_INSTALL" = "yes" ]; then
293 print_header "Install"
294
295 $MAKE install V=1 DESTDIR="$WORKSPACE"
296
297 # Cleanup rpath in executables and shared libraries
298 #find "$WORKSPACE/$PREFIX/bin" -type f -perm -0500 -exec chrpath --delete {} \;
299 find "$WORKSPACE/$PREFIX/$LIBDIR_ARCH" -name "*.so" -exec chrpath --delete {} \;
300
301 # Remove libtool .la files
302 find "$WORKSPACE/$PREFIX/$LIBDIR_ARCH" -name "*.la" -delete
303fi
304
305# Run tests if enabled
306if [ "$LIBRSEQ_RUN_TESTS" = "yes" ]; then
307 print_header "Run test suite"
308
309 # Run tests, don't fail now, we want to run the archiving steps
310 $MAKE --keep-going check || exit_status=1
311
312 # Copy tap logs for the jenkins tap parser before cleaning the build dir
313 rsync -a --exclude 'test-suite.log' --include '*/' --include '*.log' --exclude='*' tests/ "$WORKSPACE/tap"
314
315 # Copy the test suites top-level log which includes all tests failures
316 rsync -a --include 'test-suite.log' --include '*/' --exclude='*' tests/ "$WORKSPACE/log"
317fi
318
319# Clean the build directory
320if [ "$LIBRSEQ_MAKE_CLEAN" = "yes" ]; then
321 print_header "Clean"
322 $MAKE clean
323fi
324
325print_header "Librseq build script ended with: $(test $exit_status == 0 && echo SUCCESS || echo FAILURE)"
326
327# Exit with failure if any of the tests failed
328exit $exit_status
329
330# EOF
331# vim: expandtab tabstop=4 shiftwidth=4
This page took 0.022515 seconds and 4 git commands to generate.