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