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