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