Commit | Line | Data |
---|---|---|
3b3282a6 | 1 | #!/bin/bash -exu |
2b68721a | 2 | # |
3579dc14 MJ |
3 | # Copyright (C) 2015 Jonathan Rajotte-Julien <jonathan.rajotte-julien@efficios.com> |
4 | # 2016-2019 Michael Jeanson <mjeanson@efficios.com> | |
2b68721a 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 | ||
3579dc14 MJ |
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 | ||
e04f80ef MJ |
72 | # Required variables |
73 | WORKSPACE=${WORKSPACE:-} | |
74 | ||
a57a60d9 MJ |
75 | arch=${arch:-} |
76 | conf=${conf:-} | |
77 | build=${build:-} | |
3579dc14 MJ |
78 | cc=${cc:-} |
79 | ||
a57a60d9 | 80 | |
3579dc14 MJ |
81 | DEPS_INC="$WORKSPACE/deps/build/include" |
82 | DEPS_LIB="$WORKSPACE/deps/build/lib" | |
5bd69da1 | 83 | DEPS_PKGCONFIG="$DEPS_LIB/pkgconfig" |
1d56e325 MJ |
84 | #DEPS_BIN="$WORKSPACE/deps/build/bin" |
85 | #DEPS_JAVA="$WORKSPACE/deps/build/share/java" | |
2b68721a | 86 | |
3579dc14 | 87 | export LD_LIBRARY_PATH="$DEPS_LIB:${LD_LIBRARY_PATH:-}" |
5bd69da1 | 88 | export PKG_CONFIG_PATH="$DEPS_PKGCONFIG" |
3579dc14 MJ |
89 | export CPPFLAGS="-I$DEPS_INC" |
90 | export LDFLAGS="-L$DEPS_LIB" | |
c3bc676b | 91 | |
1f4fba8c MJ |
92 | SRCDIR="$WORKSPACE/src/lttng-ust" |
93 | TMPDIR="$WORKSPACE/tmp" | |
3579dc14 | 94 | PREFIX="/build" |
3b3282a6 | 95 | |
3579dc14 MJ |
96 | # Create tmp directory |
97 | rm -rf "$TMPDIR" | |
98 | mkdir -p "$TMPDIR" | |
1f4fba8c MJ |
99 | |
100 | export TMPDIR | |
72d087d4 | 101 | export CFLAGS="-g -O2" |
1f4fba8c | 102 | |
3579dc14 MJ |
103 | # Set compiler variables |
104 | case "$cc" in | |
105 | gcc) | |
106 | export CC=gcc | |
107 | export CXX=g++ | |
108 | ;; | |
109 | gcc-4.8) | |
110 | export CC=gcc-4.8 | |
111 | export CXX=g++-4.8 | |
112 | ;; | |
113 | gcc-5) | |
114 | export CC=gcc-5 | |
115 | export CXX=g++-5 | |
116 | ;; | |
117 | gcc-6) | |
118 | export CC=gcc-6 | |
119 | export CXX=g++-6 | |
120 | ;; | |
121 | gcc-7) | |
122 | export CC=gcc-7 | |
123 | export CXX=g++-7 | |
124 | ;; | |
125 | gcc-8) | |
126 | export CC=gcc-8 | |
127 | export CXX=g++-8 | |
128 | ;; | |
129 | clang) | |
130 | export CC=clang | |
131 | export CXX=clang++ | |
132 | ;; | |
133 | clang-3.9) | |
134 | export CC=clang-3.9 | |
135 | export CXX=clang++-3.9 | |
136 | ;; | |
137 | clang-4.0) | |
138 | export CC=clang-4.0 | |
139 | export CXX=clang++-4.0 | |
140 | ;; | |
141 | clang-5.0) | |
142 | export CC=clang-5.0 | |
143 | export CXX=clang++-5.0 | |
144 | ;; | |
145 | clang-6.0) | |
146 | export CC=clang-6.0 | |
147 | export CXX=clang++-6.0 | |
148 | ;; | |
149 | clang-7) | |
150 | export CC=clang-7 | |
151 | export CXX=clang++-7 | |
152 | ;; | |
153 | *) | |
154 | if [ "x$cc" != "x" ]; then | |
155 | export CC="$cc" | |
156 | fi | |
157 | ;; | |
158 | esac | |
159 | ||
160 | if [ "x${CC:-}" != "x" ]; then | |
161 | echo "Selected compiler:" | |
162 | "$CC" -v | |
163 | fi | |
164 | ||
3b3282a6 MJ |
165 | # Set platform variables |
166 | case "$arch" in | |
167 | *) | |
3579dc14 MJ |
168 | export MAKE=make |
169 | export TAR=tar | |
170 | export NPROC=nproc | |
171 | export PYTHON="python3" | |
172 | export PYTHON_CONFIG="python3-config" | |
173 | ;; | |
3b3282a6 MJ |
174 | esac |
175 | ||
3579dc14 MJ |
176 | # Enter the source directory |
177 | cd "$SRCDIR" | |
c3bc676b | 178 | |
3579dc14 MJ |
179 | # Run bootstrap in the source directory prior to configure |
180 | ./bootstrap | |
ab89ec98 | 181 | |
3579dc14 MJ |
182 | # Get source version from configure script |
183 | eval "$(grep '^PACKAGE_VERSION=' ./configure)" | |
1d56e325 | 184 | PACKAGE_VERSION=${PACKAGE_VERSION//\-pre*/} |
c3bc676b | 185 | |
3579dc14 MJ |
186 | # Set configure options and environment variables for each build |
187 | # configuration. | |
188 | CONF_OPTS=("--prefix=$PREFIX") | |
c3bc676b | 189 | case "$conf" in |
3b3282a6 | 190 | static) |
3579dc14 MJ |
191 | echo "Static lib only configuration" |
192 | ||
193 | CONF_OPTS+=("--enable-static" "--disable-shared") | |
1d56e325 MJ |
194 | |
195 | # Unsupported! liblttng-ust can't pull in it's static (.a) dependencies. | |
196 | exit 1 | |
3b3282a6 MJ |
197 | ;; |
198 | ||
67122b96 | 199 | agents) |
3579dc14 | 200 | echo "Java and Python agents configuration" |
3b3282a6 | 201 | |
60bb9bde | 202 | export CLASSPATH='/usr/share/java/*' |
3579dc14 | 203 | CONF_OPTS+=("--enable-java-agent-all" "--enable-jni-interface" "--enable-python-agent") |
3b3282a6 MJ |
204 | ;; |
205 | ||
a76416f2 JR |
206 | debug-rcu) |
207 | echo "Enable RCU sanity checks for debugging" | |
3579dc14 | 208 | export CPPFLAGS="${CPPFLAGS} -DDEBUG_RCU" |
a76416f2 JR |
209 | ;; |
210 | ||
c3bc676b | 211 | *) |
3579dc14 | 212 | echo "Standard configuration" |
c3bc676b JRJ |
213 | ;; |
214 | esac | |
215 | ||
2b68721a | 216 | # Build type |
67122b96 MJ |
217 | # oot : out-of-tree build |
218 | # dist : build via make dist | |
219 | # oot-dist: build via make dist out-of-tree | |
220 | # * : normal tree build | |
2b68721a | 221 | # |
3579dc14 MJ |
222 | # Make sure to move to the build directory and run configure |
223 | # before continuing. | |
2b68721a | 224 | case "$build" in |
3b3282a6 MJ |
225 | oot) |
226 | echo "Out of tree build" | |
67122b96 | 227 | |
3579dc14 MJ |
228 | # Create and enter a temporary build directory |
229 | builddir=$(mktemp -d) | |
230 | cd "$builddir" | |
67122b96 | 231 | |
3579dc14 | 232 | "$SRCDIR/configure" "${CONF_OPTS[@]}" |
3b3282a6 MJ |
233 | ;; |
234 | ||
235 | dist) | |
3579dc14 | 236 | echo "Distribution in-tree build" |
3b3282a6 | 237 | |
3579dc14 MJ |
238 | # Run configure and generate the tar file |
239 | # in the source directory | |
240 | ./configure | |
3b3282a6 MJ |
241 | $MAKE dist |
242 | ||
3579dc14 MJ |
243 | # Create and enter a temporary build directory |
244 | builddir=$(mktemp -d) | |
245 | cd "$builddir" | |
3b3282a6 | 246 | |
3579dc14 MJ |
247 | # Extract the distribution tar in the build directory, |
248 | # ignore the first directory level | |
249 | $TAR xvf "$SRCDIR"/*.tar.* --strip 1 | |
3b3282a6 | 250 | |
67122b96 | 251 | # Build in extracted source tree |
3579dc14 | 252 | ./configure "${CONF_OPTS[@]}" |
3b3282a6 MJ |
253 | ;; |
254 | ||
67122b96 | 255 | oot-dist) |
3579dc14 | 256 | echo "Distribution out of tree build" |
67122b96 | 257 | |
3579dc14 MJ |
258 | # Create and enter a temporary build directory |
259 | builddir=$(mktemp -d) | |
260 | cd "$builddir" | |
261 | ||
262 | # Run configure out of tree and generate the tar file | |
263 | "$SRCDIR/configure" | |
67122b96 MJ |
264 | $MAKE dist |
265 | ||
3579dc14 MJ |
266 | dist_srcdir="$(mktemp -d)" |
267 | cd "$dist_srcdir" | |
67122b96 | 268 | |
3579dc14 MJ |
269 | # Extract the distribution tar in the new source directory, |
270 | # ignore the first directory level | |
271 | $TAR xvf "$builddir"/*.tar.* --strip 1 | |
67122b96 | 272 | |
3579dc14 MJ |
273 | # Create and enter a second temporary build directory |
274 | builddir="$(mktemp -d)" | |
275 | cd "$builddir" | |
67122b96 | 276 | |
3579dc14 MJ |
277 | # Run configure from the extracted distribution tar, |
278 | # out of the source tree | |
279 | "$dist_srcdir/configure" "${CONF_OPTS[@]}" | |
67122b96 MJ |
280 | ;; |
281 | ||
3b3282a6 | 282 | *) |
1f4fba8c | 283 | echo "Standard in-tree build" |
3579dc14 | 284 | ./configure "${CONF_OPTS[@]}" |
3b3282a6 | 285 | ;; |
2b68721a MJ |
286 | esac |
287 | ||
3579dc14 MJ |
288 | # We are now inside a configured build directory |
289 | ||
3b3282a6 | 290 | # BUILD! |
a57a60d9 | 291 | $MAKE -j "$($NPROC)" V=1 |
c3bc676b | 292 | |
3579dc14 MJ |
293 | # Install in the workspace |
294 | $MAKE install DESTDIR="$WORKSPACE" | |
295 | ||
296 | # Run tests, don't fail now, we want to run the archiving steps | |
1d56e325 MJ |
297 | failed_tests=0 |
298 | $MAKE --keep-going check || failed_tests=1 | |
c3bc676b | 299 | |
3579dc14 | 300 | # Copy tap logs for the jenkins tap parser before cleaning the build dir |
1f4fba8c | 301 | rsync -a --exclude 'test-suite.log' --include '*/' --include '*.log' --exclude='*' tests/ "$WORKSPACE/tap" |
c3bc676b | 302 | |
0fe4a4b4 MJ |
303 | # The test suite prior to 2.8 did not produce TAP logs |
304 | if verlt "$PACKAGE_VERSION" "2.8"; then | |
305 | mkdir -p "$WORKSPACE/tap/no-log" | |
306 | echo "1..1" > "$WORKSPACE/tap/no-log/tests.log" | |
307 | echo "ok 1 - Test suite doesn't support logging" >> "$WORKSPACE/tap/no-log/tests.log" | |
308 | fi | |
309 | ||
1f4fba8c | 310 | # Clean the build directory |
3b3282a6 | 311 | $MAKE clean |
c3bc676b | 312 | |
3b3282a6 | 313 | # Cleanup rpath in executables and shared libraries |
1d56e325 | 314 | #find "$WORKSPACE/$PREFIX/bin" -type f -perm -0500 -exec chrpath --delete {} \; |
3579dc14 | 315 | find "$WORKSPACE/$PREFIX/lib" -name "*.so" -exec chrpath --delete {} \; |
3b3282a6 MJ |
316 | |
317 | # Remove libtool .la files | |
3579dc14 | 318 | find "$WORKSPACE/$PREFIX/lib" -name "*.la" -exec rm -f {} \; |
2b68721a | 319 | |
1d56e325 MJ |
320 | # Exit with failure if any of the tests failed |
321 | exit $failed_tests | |
3b3282a6 MJ |
322 | |
323 | # EOF |