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