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