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