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
9 # Version compare functions
12 if [[ "$1" == "$2" ]]; then
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
23 for ((i
=0; i
<${#ver1[@]}; i
++)); do
24 if [[ -z ${ver2[i]} ]]; then
25 # fill empty fields in ver2 with zeros
28 if ((10#${ver1[i]} > 10#${ver2[i]})); then
31 if ((10#${ver1[i]} < 10#${ver2[i]})); then
40 vercomp
"$1" "$2"; local res
="$?"
41 [ "$res" -eq "0" ] ||
[ "$res" -eq "2" ]
45 vercomp
"$1" "$2"; local res
="$?"
50 vercomp
"$1" "$2"; local res
="$?"
51 [ "$res" -eq "0" ] ||
[ "$res" -eq "1" ]
55 vercomp
"$1" "$2"; local res
="$?"
60 vercomp
"$1" "$2"; local res
="$?"
71 message_len
="${#message}"
72 padding_len
=$
(( (80 - (message_len
)) / 2 ))
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'
84 # Assume we are in the configured build directory
85 print_header
"BEGIN config.log"
87 print_header
"END config.log"
89 # End the build with failure
93 print_header
"Librseq build script starting"
96 WORKSPACE
=${WORKSPACE:-}
99 platform
=${platform:-}
104 # Build steps that can be overriden by the environment
105 LIBRSEQ_MAKE_INSTALL
="${LIBRSEQ_MAKE_INSTALL:-yes}"
106 LIBRSEQ_MAKE_CLEAN
="${LIBRSEQ_MAKE_CLEAN:-yes}"
107 LIBRSEQ_GEN_COMPILE_COMMANDS
="${LIBRSEQ_GEN_COMPILE_COMMANDS:-no}"
108 LIBRSEQ_RUN_TESTS
="${LIBRSEQ_RUN_TESTS:-yes}"
110 SRCDIR
="$WORKSPACE/src/librseq"
111 TMPDIR
="$WORKSPACE/tmp"
114 LIBDIR_ARCH
="$LIBDIR"
116 # RHEL and SLES both use lib64 but don't bother shipping a default autoconf
117 # site config that matches this.
118 if [[ ( -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"
127 # Use bear to generate compile_commands.json when enabled
129 if [ "$LIBRSEQ_GEN_COMPILE_COMMANDS" = "yes" ]; then
133 # Create tmp directory
138 export CFLAGS
="-g -O2"
139 export CXXFLAGS
="-g -O2"
141 # Add the convenience headers in extra to the
143 export CPPFLAGS
="-I$SRCDIR/extra"
145 # Set compiler variables
152 export CC
=gcc-
${cc#gcc-}
153 export CXX
=g
++-${cc#gcc-}
160 export CC
=clang-
${cc#clang-}
161 export CXX
=clang
++-${cc#clang-}
164 if [ "x$cc" != "x" ]; then
170 # Set platform variables
176 export PYTHON
="python3"
177 export PYTHON_CONFIG
="python3-config"
181 # Print build env details
182 print_header
"Build environment details"
184 print_tooling || true
186 # Enter the source directory
189 # Run bootstrap in the source directory prior to configure
190 print_header
"Bootstrap autotools"
193 # Get source version from configure script
194 eval "$(grep '^PACKAGE_VERSION=' ./configure)"
195 PACKAGE_VERSION
=${PACKAGE_VERSION//\-pre*/}
197 # Set configure options and environment variables for each build
199 CONF_OPTS
=("--prefix=$PREFIX" "--libdir=$PREFIX/$LIBDIR_ARCH" "--disable-maintainer-mode")
202 print_header
"Conf: Static lib only"
204 CONF_OPTS
+=("--enable-static" "--disable-shared")
208 print_header
"Conf: Standard"
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
218 # Make sure to move to the build directory and run configure
222 print_header
"Build: Out of tree"
224 # Create and enter a temporary build directory
225 builddir
=$
(mktemp
-d)
228 "$SRCDIR/configure" "${CONF_OPTS[@]}" || failed_configure
232 print_header
"Build: Distribution In-tree"
234 # Run configure and generate the tar file
235 # in the source directory
236 .
/configure || failed_configure
239 # Create and enter a temporary build directory
240 builddir
=$
(mktemp
-d)
243 # Extract the distribution tar in the build directory,
244 # ignore the first directory level
245 $TAR xvf
"$SRCDIR"/*.
tar.
* --strip 1
247 # Build in extracted source tree
248 .
/configure
"${CONF_OPTS[@]}" || failed_configure
252 print_header
"Build: Distribution Out of tree"
254 # Create and enter a temporary build directory
255 builddir
=$
(mktemp
-d)
258 # Run configure out of tree and generate the tar file
259 "$SRCDIR/configure" || failed_configure
262 dist_srcdir
="$(mktemp -d)"
265 # Extract the distribution tar in the new source directory,
266 # ignore the first directory level
267 $TAR xvf
"$builddir"/*.
tar.
* --strip 1
269 # Create and enter a second temporary build directory
270 builddir
="$(mktemp -d)"
273 # Run configure from the extracted distribution tar,
274 # out of the source tree
275 "$dist_srcdir/configure" "${CONF_OPTS[@]}" || failed_configure
279 print_header
"Build: Standard In-tree"
281 .
/configure
"${CONF_OPTS[@]}" || failed_configure
285 # We are now inside a configured build directory
288 print_header
"BUILD!"
289 $BEAR ${BEAR:+--} $MAKE -j "$($NPROC)" V
=1
291 # Install in the workspace if enabled
292 if [ "$LIBRSEQ_MAKE_INSTALL" = "yes" ]; then
293 print_header
"Install"
295 $MAKE install V
=1 DESTDIR
="$WORKSPACE"
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 {} \
;
301 # Remove libtool .la files
302 find "$WORKSPACE/$PREFIX/$LIBDIR_ARCH" -name "*.la" -delete
305 # Run tests if enabled
306 if [ "$LIBRSEQ_RUN_TESTS" = "yes" ]; then
307 print_header
"Run test suite"
309 # Run tests, don't fail now, we want to run the archiving steps
310 $MAKE --keep-going check || exit_status
=1
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"
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"
319 # Clean the build directory
320 if [ "$LIBRSEQ_MAKE_CLEAN" = "yes" ]; then
325 print_header
"Librseq build script ended with: $(test $exit_status == 0 && echo SUCCESS || echo FAILURE)"
327 # Exit with failure if any of the tests failed
331 # vim: expandtab tabstop=4 shiftwidth=4