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