da5f4ab96ff4ec1aa46a74e75ec5b97abbf72e66
[lttng-ci.git] / scripts / babeltrace / build.sh
1 #!/bin/bash -exu
2 #
3 # Copyright (C) 2015 - Jonathan Rajotte-Julien <jonathan.rajotte-julien@efficios.com>
4 # 2016 - 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 parameters
73 arch=${arch:-}
74 conf=${conf:-}
75 build=${build:-}
76 cc=${cc:-}
77 bt2_mode=${bt2_mode:-}
78
79
80 SRCDIR="$WORKSPACE/src/babeltrace"
81 TMPDIR="$WORKSPACE/tmp"
82 PREFIX="$WORKSPACE/build"
83
84 # Create build and tmp directories
85 rm -rf "$PREFIX" "$TMPDIR"
86 mkdir -p "$PREFIX" "$TMPDIR"
87
88 export TMPDIR
89 export CFLAGS="-g -O2"
90
91 # Set compiler variables
92 case "$cc" in
93 gcc)
94 export CC=gcc
95 export CXX=g++
96 ;;
97 gcc-4.8)
98 export CC=gcc-4.8
99 export CXX=g++-4.8
100 ;;
101 gcc-5)
102 export CC=gcc-5
103 export CXX=g++-5
104 ;;
105 gcc-6)
106 export CC=gcc-6
107 export CXX=g++-6
108 ;;
109 gcc-7)
110 export CC=gcc-7
111 export CXX=g++-7
112 ;;
113 gcc-8)
114 export CC=gcc-8
115 export CXX=g++-8
116 ;;
117 clang)
118 export CC=clang
119 export CXX=clang++
120 ;;
121 clang-3.9)
122 export CC=clang-3.9
123 export CXX=clang++-3.9
124 ;;
125 clang-4.0)
126 export CC=clang-4.0
127 export CXX=clang++-4.0
128 ;;
129 clang-5.0)
130 export CC=clang-5.0
131 export CXX=clang++-5.0
132 ;;
133 clang-6.0)
134 export CC=clang-6.0
135 export CXX=clang++-6.0
136 ;;
137 clang-7)
138 export CC=clang-7
139 export CXX=clang++-7
140 ;;
141 *)
142 if [ "x$cc" != "x" ]; then
143 export CC="$cc"
144 fi
145 ;;
146 esac
147
148 if [ "x${CC:-}" != "x" ]; then
149 echo "Selected compiler:"
150 "$CC" -v
151 fi
152
153 # Set platform variables
154 case "$arch" in
155 sol10-i386)
156 export MAKE=gmake
157 export TAR=gtar
158 export NPROC=gnproc
159 export BISON=bison
160 export YACC="$BISON -y"
161 export PATH="/opt/csw/bin:/usr/ccs/bin:$PATH"
162 export CPPFLAGS="-I/opt/csw/include"
163 export LDFLAGS="-L/opt/csw/lib -R/opt/csw/lib"
164 export PKG_CONFIG_PATH="/opt/csw/lib/pkgconfig"
165 ;;
166 sol11-i386)
167 export MAKE=gmake
168 export TAR=gtar
169 export NPROC=nproc
170 export PATH="$PATH:/usr/perl5/bin"
171 export LD_ALTEXEC=/usr/bin/gld
172 export LD=/usr/bin/gld
173 ;;
174 macosx)
175 export MAKE=make
176 export TAR=tar
177 export NPROC="getconf _NPROCESSORS_ONLN"
178 export BISON="bison"
179 export YACC="$BISON -y"
180 export PATH="/opt/local/bin:/opt/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"
181 export CFLAGS="$CFLAGS -I/opt/local/include"
182 export LDFLAGS="-L/opt/local/lib"
183 ;;
184 *)
185 export MAKE=make
186 export TAR=tar
187 export NPROC=nproc
188 ;;
189 esac
190
191 # Enter the source directory
192 cd "$SRCDIR"
193
194 # Run bootstrap in the source directory prior to configure
195 ./bootstrap
196
197 # Get source version from configure script
198 eval "$(grep '^PACKAGE_VERSION=' ./configure)"
199
200 # Enable dev mode by default for BT 2.0 builds
201 case "$bt2_mode" in
202 dev)
203 echo "Developer mode"
204 export BABELTRACE_DEBUG_MODE=1
205 export BABELTRACE_DEV_MODE=1
206 export BABELTRACE_MINIMAL_LOG_LEVEL=VERBOSE
207 ;;
208 *)
209 echo "Production mode (Default)"
210 export BABELTRACE_MINIMAL_LOG_LEVEL=INFO
211 ;;
212 esac
213
214 # Set configure options for each build configuration
215 CONF_OPTS=""
216 case "$conf" in
217 static)
218 echo "Static build"
219 CONF_OPTS="--enable-static --disable-shared"
220 if vergte "$PACKAGE_VERSION" "2.0"; then
221 CONF_OPTS="${CONF_OPTS} --enable-built-in-plugins"
222 fi
223 ;;
224 python-bindings)
225 echo "Build with python bindings"
226 # We only support bindings built with Python 3
227 export PYTHON="python3"
228 export PYTHON_CONFIG="/usr/bin/python3-config"
229 CONF_OPTS="--enable-python-bindings"
230
231 if vergte "$PACKAGE_VERSION" "2.0"; then
232 CONF_OPTS="${CONF_OPTS} --enable-python-bindings-doc --enable-python-plugins"
233 fi
234 ;;
235 *)
236 echo "Standard build"
237 CONF_OPTS=""
238 ;;
239 esac
240
241 # Build type
242 # oot : out-of-tree build
243 # dist: build via make dist
244 # * : normal tree build
245 #
246 # Make sure to move to the build_path and configure
247 # before continuing
248 BUILD_PATH="$SRCDIR"
249 case "$build" in
250 oot)
251 echo "Out of tree build"
252 BUILD_PATH="$WORKSPACE/oot"
253 mkdir -p "$BUILD_PATH"
254 cd "$BUILD_PATH"
255 "$SRCDIR/configure" --prefix="$PREFIX" $CONF_OPTS
256 ;;
257
258 dist)
259 echo "Distribution out of tree build"
260 BUILD_PATH="$(mktemp -d)"
261
262 # Initial configure and generate tarball
263 "$SRCDIR/configure"
264 $MAKE dist
265
266 mkdir -p "$BUILD_PATH"
267 cp ./*.tar.* "$BUILD_PATH/"
268 cd "$BUILD_PATH"
269
270 # Ignore level 1 of tar
271 $TAR xvf ./*.tar.* --strip 1
272
273 "$BUILD_PATH/configure" --prefix="$PREFIX" $CONF_OPTS
274 ;;
275
276 *)
277 echo "Standard in-tree build"
278 "$SRCDIR/configure" --prefix="$PREFIX" $CONF_OPTS
279 ;;
280 esac
281
282 # BUILD!
283 $MAKE -j "$($NPROC)" V=1
284 $MAKE install
285
286 # Run tests
287 $MAKE --keep-going check
288
289 # Copy tap logs for the jenkins tap parser
290 rsync -a --exclude 'test-suite.log' --include '*/' --include '*.log' --exclude='*' tests/ "$WORKSPACE/tap"
291
292 # Clean the build directory
293 $MAKE clean
294
295 # Cleanup rpath in executables and shared libraries
296 find "$PREFIX/bin" -type f -perm -0500 -exec chrpath --delete {} \;
297 find "$PREFIX/lib" -name "*.so" -exec chrpath --delete {} \;
298
299 # Remove libtool .la files
300 find "$PREFIX/lib" -name "*.la" -exec rm -f {} \;
301
302 # Clean temp dir for dist build
303 if [ "$build" = "dist" ]; then
304 cd "$SRCDIR"
305 rm -rf "$BUILD_PATH"
306 fi
307
308 # EOF
This page took 0.036403 seconds and 3 git commands to generate.