jjb: Add env and os details printing to build jobs
[lttng-ci.git] / scripts / librseq / build.sh
1 #!/bin/bash
2 #
3 # Copyright (C) 2015 Jonathan Rajotte-Julien <jonathan.rajotte-julien@efficios.com>
4 # Copyright (C) 2019-2020 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 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
49 verlte() {
50 vercomp "$1" "$2"; local res="$?"
51 [ "$res" -eq "0" ] || [ "$res" -eq "2" ]
52 }
53
54 verlt() {
55 vercomp "$1" "$2"; local res="$?"
56 [ "$res" -eq "2" ]
57 }
58
59 vergte() {
60 vercomp "$1" "$2"; local res="$?"
61 [ "$res" -eq "0" ] || [ "$res" -eq "1" ]
62 }
63
64 vergt() {
65 vercomp "$1" "$2"; local res="$?"
66 [ "$res" -eq "1" ]
67 }
68
69 verne() {
70 vercomp "$1" "$2"; local res="$?"
71 [ "$res" -ne "0" ]
72 }
73
74 failed_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
84 # Required variables
85 WORKSPACE=${WORKSPACE:-}
86
87 arch=${arch:-}
88 conf=${conf:-}
89 build=${build:-}
90 cc=${cc:-}
91
92
93 SRCDIR="$WORKSPACE/src/librseq"
94 TMPDIR="$WORKSPACE/tmp"
95 PREFIX="/build"
96
97 # Create tmp directory
98 rm -rf "$TMPDIR"
99 mkdir -p "$TMPDIR"
100
101 export TMPDIR
102 export CFLAGS="-g -O2"
103
104 # Add the convenience headers in extra to the
105 # include path.
106 export CPPFLAGS="-I$SRCDIR/extra"
107
108 # Set compiler variables
109 case "$cc" in
110 gcc)
111 export CC=gcc
112 export CXX=g++
113 ;;
114 gcc-4.8)
115 export CC=gcc-4.8
116 export CXX=g++-4.8
117 ;;
118 gcc-5)
119 export CC=gcc-5
120 export CXX=g++-5
121 ;;
122 gcc-6)
123 export CC=gcc-6
124 export CXX=g++-6
125 ;;
126 gcc-7)
127 export CC=gcc-7
128 export CXX=g++-7
129 ;;
130 gcc-8)
131 export CC=gcc-8
132 export CXX=g++-8
133 ;;
134 clang)
135 export CC=clang
136 export CXX=clang++
137 ;;
138 clang-3.9)
139 export CC=clang-3.9
140 export CXX=clang++-3.9
141 ;;
142 clang-4.0)
143 export CC=clang-4.0
144 export CXX=clang++-4.0
145 ;;
146 clang-5.0)
147 export CC=clang-5.0
148 export CXX=clang++-5.0
149 ;;
150 clang-6.0)
151 export CC=clang-6.0
152 export CXX=clang++-6.0
153 ;;
154 clang-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 ;;
163 esac
164
165 if [ "x${CC:-}" != "x" ]; then
166 echo "Selected compiler:"
167 "$CC" -v
168 fi
169
170 # Set platform variables
171 case "$arch" 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 ;;
179 esac
180
181 # Print build env details
182 print_os || true
183 print_tooling || true
184
185 # Enter the source directory
186 cd "$SRCDIR"
187
188 # Run bootstrap in the source directory prior to configure
189 ./bootstrap
190
191 # Get source version from configure script
192 eval "$(grep '^PACKAGE_VERSION=' ./configure)"
193 PACKAGE_VERSION=${PACKAGE_VERSION//\-pre*/}
194
195
196 # Set configure options and environment variables for each build
197 # configuration.
198 CONF_OPTS=("--prefix=$PREFIX")
199 case "$conf" in
200 static)
201 echo "Static lib only configuration"
202
203 CONF_OPTS+=("--enable-static" "--disable-shared")
204 ;;
205
206 *)
207 echo "Standard configuration"
208 ;;
209 esac
210
211 # Build type
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
216 #
217 # Make sure to move to the build directory and run configure
218 # before continuing.
219 case "$build" in
220 oot)
221 echo "Out of tree build"
222
223 # Create and enter a temporary build directory
224 builddir=$(mktemp -d)
225 cd "$builddir"
226
227 "$SRCDIR/configure" "${CONF_OPTS[@]}" || failed_configure
228 ;;
229
230 dist)
231 echo "Distribution in-tree build"
232
233 # Run configure and generate the tar file
234 # in the source directory
235 ./configure || failed_configure
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
247 ./configure "${CONF_OPTS[@]}" || failed_configure
248 ;;
249
250 oot-dist)
251 echo "Distribution out of tree build"
252
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
258 "$SRCDIR/configure" || failed_configure
259 $MAKE dist
260
261 dist_srcdir="$(mktemp -d)"
262 cd "$dist_srcdir"
263
264 # Extract the distribution tar in the new source directory,
265 # ignore the first directory level
266 $TAR xvf "$builddir"/*.tar.* --strip 1
267
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
274 "$dist_srcdir/configure" "${CONF_OPTS[@]}" || failed_configure
275 ;;
276
277 *)
278 echo "Standard in-tree build"
279 ./configure "${CONF_OPTS[@]}" || failed_configure
280 ;;
281 esac
282
283 # We are now inside a configured build directory
284
285 # BUILD!
286 $MAKE -j "$($NPROC)" V=1
287
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
292 set +e
293 $MAKE --keep-going check
294 ret=$?
295 set -e
296
297 # Copy tap logs for the jenkins tap parser before cleaning the build dir
298 #rsync -a --exclude 'test-suite.log' --include '*/' --include '*.log' --exclude='*' tests/ "$WORKSPACE/tap"
299
300 # Clean the build directory
301 $MAKE clean
302
303 # Cleanup rpath in executables and shared libraries
304 #find "$WORKSPACE/$PREFIX/bin" -type f -perm -0500 -exec chrpath --delete {} \;
305 find "$WORKSPACE/$PREFIX/lib" -name "*.so" -exec chrpath --delete {} \;
306
307 # Remove libtool .la files
308 find "$WORKSPACE/$PREFIX/lib" -name "*.la" -exec rm -f {} \;
309
310 # Exit with the return code of the test suite
311 exit $ret
312
313 # EOF
This page took 0.04408 seconds and 4 git commands to generate.