Commit | Line | Data |
---|---|---|
c56b9301 | 1 | #!/bin/bash -exu |
890bff23 MJ |
2 | # |
3 | # Copyright (C) 2015 - Jonathan Rajotte-Julien <jonathan.rajotte-julien@efficios.com> | |
0e9967db | 4 | # 2016 - Michael Jeanson <mjeanson@efficios.com> |
890bff23 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 | ||
a0b535b2 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:-} | |
76 | ||
c56b9301 | 77 | |
e6be9fb0 MJ |
78 | SRCDIR="$WORKSPACE/src/babeltrace" |
79 | TMPDIR="$WORKSPACE/tmp" | |
275b59d2 JRJ |
80 | PREFIX="$WORKSPACE/build" |
81 | ||
e6be9fb0 MJ |
82 | # Create build and tmp directories |
83 | rm -rf "$PREFIX" "$TMPDIR" | |
84 | mkdir -p "$PREFIX" "$TMPDIR" | |
85 | ||
0e9967db MJ |
86 | export TMPDIR |
87 | ||
c56b9301 | 88 | # Set platform variables |
87e41bca | 89 | case "$arch" in |
a0b535b2 MJ |
90 | sol10-i386) |
91 | export MAKE=gmake | |
92 | export TAR=gtar | |
93 | export NPROC=gnproc | |
94 | export BISON=bison | |
95 | export YACC="$BISON -y" | |
ad11244c | 96 | export PATH="/opt/csw/bin:/usr/ccs/bin:$PATH" |
a0b535b2 MJ |
97 | export CPPFLAGS="-I/opt/csw/include" |
98 | export LDFLAGS="-L/opt/csw/lib -R/opt/csw/lib" | |
99 | export PKG_CONFIG_PATH="/opt/csw/lib/pkgconfig" | |
87e41bca | 100 | ;; |
a0b535b2 MJ |
101 | sol11-i386) |
102 | export MAKE=gmake | |
103 | export TAR=gtar | |
104 | export NPROC=nproc | |
105 | export BISON="/opt/csw/bin/bison" | |
106 | export YACC="$BISON -y" | |
87e41bca | 107 | export PATH="$PATH:/usr/perl5/bin" |
a0b535b2 MJ |
108 | export LD_ALTEXEC=/usr/sfw/bin/gld |
109 | export LD=/usr/sfw/bin/gld | |
87e41bca | 110 | ;; |
221450b6 | 111 | macosx) |
a0b535b2 MJ |
112 | export MAKE=make |
113 | export TAR=tar | |
114 | export NPROC="getconf _NPROCESSORS_ONLN" | |
115 | export BISON="bison" | |
116 | export YACC="$BISON -y" | |
221450b6 MJ |
117 | export PATH="/opt/local/bin:/opt/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin" |
118 | export CFLAGS="-I/opt/local/include" | |
119 | export LDFLAGS="-L/opt/local/lib" | |
120 | ;; | |
87e41bca | 121 | *) |
a0b535b2 MJ |
122 | export MAKE=make |
123 | export TAR=tar | |
124 | export NPROC=nproc | |
87e41bca MJ |
125 | ;; |
126 | esac | |
127 | ||
a0b535b2 MJ |
128 | # Enter the source directory |
129 | cd "$SRCDIR" | |
130 | ||
131 | # Run bootstrap in the source directory prior to configure | |
132 | ./bootstrap | |
133 | ||
134 | # Get source version from configure script | |
135 | eval "$(grep '^PACKAGE_VERSION=' ./configure)" | |
136 | ||
c56b9301 MJ |
137 | # Set configure options for each build configuration |
138 | CONF_OPTS="" | |
275b59d2 JRJ |
139 | case "$conf" in |
140 | static) | |
141 | echo "Static build" | |
142 | CONF_OPTS="--enable-static --disable-shared" | |
a0b535b2 MJ |
143 | if vergte "$PACKAGE_VERSION" "2.0"; then |
144 | CONF_OPTS="${CONF_OPTS} --enable-built-in-plugins" | |
145 | fi | |
275b59d2 | 146 | ;; |
221450b6 | 147 | python-bindings) |
275b59d2 JRJ |
148 | echo "Build with python bindings" |
149 | # We only support bindings built with Python 3 | |
150 | export PYTHON="python3" | |
151 | export PYTHON_CONFIG="/usr/bin/python3-config" | |
152 | CONF_OPTS="--enable-python-bindings" | |
a0b535b2 MJ |
153 | |
154 | if vergte "$PACKAGE_VERSION" "2.0"; then | |
155 | CONF_OPTS="${CONF_OPTS} --enable-python-bindings-doc --enable-python-bindings-tests --enable-python-plugins" | |
156 | fi | |
275b59d2 JRJ |
157 | ;; |
158 | *) | |
159 | echo "Standard build" | |
160 | CONF_OPTS="" | |
161 | ;; | |
162 | esac | |
163 | ||
aad6ac90 JR |
164 | # Build type |
165 | # oot : out-of-tree build | |
166 | # dist: build via make dist | |
167 | # * : normal tree build | |
168 | # | |
169 | # Make sure to move to the build_path and configure | |
170 | # before continuing | |
e6be9fb0 | 171 | BUILD_PATH="$SRCDIR" |
aad6ac90 | 172 | case "$build" in |
c56b9301 MJ |
173 | oot) |
174 | echo "Out of tree build" | |
944a6c86 MJ |
175 | BUILD_PATH="$WORKSPACE/oot" |
176 | mkdir -p "$BUILD_PATH" | |
177 | cd "$BUILD_PATH" | |
a0b535b2 | 178 | "$SRCDIR/configure" --prefix="$PREFIX" $CONF_OPTS |
c56b9301 MJ |
179 | ;; |
180 | ||
181 | dist) | |
182 | echo "Distribution out of tree build" | |
a57a60d9 | 183 | BUILD_PATH="$(mktemp -d)" |
c56b9301 MJ |
184 | |
185 | # Initial configure and generate tarball | |
a0b535b2 | 186 | "$SRCDIR/configure" |
c56b9301 MJ |
187 | $MAKE dist |
188 | ||
944a6c86 MJ |
189 | mkdir -p "$BUILD_PATH" |
190 | cp ./*.tar.* "$BUILD_PATH/" | |
191 | cd "$BUILD_PATH" | |
c56b9301 MJ |
192 | |
193 | # Ignore level 1 of tar | |
944a6c86 | 194 | $TAR xvf ./*.tar.* --strip 1 |
c56b9301 | 195 | |
a0b535b2 | 196 | "$BUILD_PATH/configure" --prefix="$PREFIX" $CONF_OPTS |
c56b9301 MJ |
197 | ;; |
198 | ||
0628a9d8 MJ |
199 | clang) |
200 | echo "LLVM clang build" | |
201 | export CC=clang | |
202 | clang -v | |
a0b535b2 | 203 | "$SRCDIR/configure" --prefix="$PREFIX" $CONF_OPTS |
0628a9d8 MJ |
204 | ;; |
205 | *) | |
e6be9fb0 | 206 | echo "Standard in-tree build" |
a0b535b2 | 207 | "$SRCDIR/configure" --prefix="$PREFIX" $CONF_OPTS |
c56b9301 | 208 | ;; |
aad6ac90 JR |
209 | esac |
210 | ||
c56b9301 | 211 | # BUILD! |
a57a60d9 | 212 | $MAKE -j "$($NPROC)" V=1 |
87e41bca | 213 | $MAKE install |
c56b9301 MJ |
214 | |
215 | # Run tests | |
221450b6 | 216 | $MAKE check |
c56b9301 | 217 | |
e6be9fb0 MJ |
218 | # Copy tap logs for the jenkins tap parser |
219 | rsync -a --exclude 'test-suite.log' --include '*/' --include '*.log' --exclude='*' tests/ "$WORKSPACE/tap" | |
220 | ||
221 | # Clean the build directory | |
222 | $MAKE clean | |
275b59d2 | 223 | |
c56b9301 | 224 | # Cleanup rpath in executables and shared libraries |
944a6c86 MJ |
225 | find "$PREFIX/bin" -type f -perm -0500 -exec chrpath --delete {} \; |
226 | find "$PREFIX/lib" -name "*.so" -exec chrpath --delete {} \; | |
c56b9301 MJ |
227 | |
228 | # Remove libtool .la files | |
944a6c86 | 229 | find "$PREFIX/lib" -name "*.la" -exec rm -f {} \; |
aad6ac90 | 230 | |
c56b9301 MJ |
231 | # Clean temp dir for dist build |
232 | if [ "$build" = "dist" ]; then | |
944a6c86 MJ |
233 | cd "$SRCDIR" |
234 | rm -rf "$BUILD_PATH" | |
aad6ac90 | 235 | fi |
87e41bca MJ |
236 | |
237 | # EOF |