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