Commit | Line | Data |
---|---|---|
51c9c62d | 1 | #!/bin/bash |
ae855ba1 MJ |
2 | # |
3 | # Copyright (C) 2015 Jonathan Rajotte-Julien <jonathan.rajotte-julien@efficios.com> | |
51c9c62d | 4 | # Copyright (C) 2019-2020 Michael Jeanson <mjeanson@efficios.com> |
ae855ba1 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 | ||
51c9c62d MJ |
19 | set -exu |
20 | ||
ae855ba1 MJ |
21 | # Version compare functions |
22 | vercomp () { | |
23 | set +u | |
24 | if [[ "$1" == "$2" ]]; then | |
25 | return 0 | |
26 | fi | |
27 | local IFS=. | |
28 | local i ver1=($1) ver2=($2) | |
29 | # fill empty fields in ver1 with zeros | |
30 | for ((i=${#ver1[@]}; i<${#ver2[@]}; i++)); do | |
31 | ver1[i]=0 | |
32 | done | |
33 | for ((i=0; i<${#ver1[@]}; i++)); do | |
34 | if [[ -z ${ver2[i]} ]]; then | |
35 | # fill empty fields in ver2 with zeros | |
36 | ver2[i]=0 | |
37 | fi | |
38 | if ((10#${ver1[i]} > 10#${ver2[i]})); then | |
39 | return 1 | |
40 | fi | |
41 | if ((10#${ver1[i]} < 10#${ver2[i]})); then | |
42 | return 2 | |
43 | fi | |
44 | done | |
45 | set -u | |
46 | return 0 | |
47 | } | |
48 | ||
49 | verlte() { | |
50 | vercomp "$1" "$2"; local res="$?" | |
51 | [ "$res" -eq "0" ] || [ "$res" -eq "2" ] | |
52 | } | |
53 | ||
54 | verlt() { | |
55 | vercomp "$1" "$2"; local res="$?" | |
56 | [ "$res" -eq "2" ] | |
57 | } | |
58 | ||
59 | vergte() { | |
60 | vercomp "$1" "$2"; local res="$?" | |
61 | [ "$res" -eq "0" ] || [ "$res" -eq "1" ] | |
62 | } | |
63 | ||
64 | vergt() { | |
65 | vercomp "$1" "$2"; local res="$?" | |
66 | [ "$res" -eq "1" ] | |
67 | } | |
68 | ||
69 | verne() { | |
70 | vercomp "$1" "$2"; local res="$?" | |
71 | [ "$res" -ne "0" ] | |
72 | } | |
73 | ||
51c9c62d MJ |
74 | failed_configure() { |
75 | # Assume we are in the configured build directory | |
76 | echo "#################### BEGIN config.log ####################" | |
77 | cat config.log | |
78 | echo "#################### END config.log ####################" | |
79 | ||
80 | # End the build with failure | |
81 | exit 1 | |
82 | } | |
83 | ||
1d56e325 MJ |
84 | # Required variables |
85 | WORKSPACE=${WORKSPACE:-} | |
86 | ||
ae855ba1 MJ |
87 | arch=${arch:-} |
88 | conf=${conf:-} | |
89 | build=${build:-} | |
90 | cc=${cc:-} | |
91 | ||
92 | ||
93 | SRCDIR="$WORKSPACE/src/librseq" | |
94 | TMPDIR="$WORKSPACE/tmp" | |
1d56e325 | 95 | PREFIX="/build" |
ae855ba1 | 96 | |
1d56e325 MJ |
97 | # Create tmp directory |
98 | rm -rf "$TMPDIR" | |
99 | mkdir -p "$TMPDIR" | |
ae855ba1 MJ |
100 | |
101 | export TMPDIR | |
102 | export CFLAGS="-g -O2" | |
1d56e325 MJ |
103 | |
104 | # Add the convenience headers in extra to the | |
105 | # include path. | |
ae855ba1 MJ |
106 | export CPPFLAGS="-I$SRCDIR/extra" |
107 | ||
108 | # Set compiler variables | |
109 | case "$cc" in | |
110 | gcc) | |
111 | export CC=gcc | |
112 | export CXX=g++ | |
113 | ;; | |
114 | gcc-4.8) | |
115 | export CC=gcc-4.8 | |
116 | export CXX=g++-4.8 | |
117 | ;; | |
118 | gcc-5) | |
119 | export CC=gcc-5 | |
120 | export CXX=g++-5 | |
121 | ;; | |
122 | gcc-6) | |
123 | export CC=gcc-6 | |
124 | export CXX=g++-6 | |
125 | ;; | |
126 | gcc-7) | |
127 | export CC=gcc-7 | |
128 | export CXX=g++-7 | |
129 | ;; | |
130 | gcc-8) | |
131 | export CC=gcc-8 | |
132 | export CXX=g++-8 | |
133 | ;; | |
134 | clang) | |
135 | export CC=clang | |
136 | export CXX=clang++ | |
137 | ;; | |
138 | clang-3.9) | |
139 | export CC=clang-3.9 | |
140 | export CXX=clang++-3.9 | |
141 | ;; | |
142 | clang-4.0) | |
143 | export CC=clang-4.0 | |
144 | export CXX=clang++-4.0 | |
145 | ;; | |
146 | clang-5.0) | |
147 | export CC=clang-5.0 | |
148 | export CXX=clang++-5.0 | |
149 | ;; | |
150 | clang-6.0) | |
151 | export CC=clang-6.0 | |
152 | export CXX=clang++-6.0 | |
153 | ;; | |
154 | clang-7) | |
155 | export CC=clang-7 | |
156 | export CXX=clang++-7 | |
157 | ;; | |
158 | *) | |
159 | if [ "x$cc" != "x" ]; then | |
160 | export CC="$cc" | |
161 | fi | |
162 | ;; | |
163 | esac | |
164 | ||
1d56e325 MJ |
165 | if [ "x${CC:-}" != "x" ]; then |
166 | echo "Selected compiler:" | |
167 | "$CC" -v | |
168 | fi | |
169 | ||
ae855ba1 MJ |
170 | # Set platform variables |
171 | case "$arch" in | |
172 | *) | |
173 | export MAKE=make | |
174 | export TAR=tar | |
175 | export NPROC=nproc | |
1d56e325 MJ |
176 | export PYTHON="python3" |
177 | export PYTHON_CONFIG="python3-config" | |
ae855ba1 MJ |
178 | ;; |
179 | esac | |
180 | ||
51c9c62d MJ |
181 | # Print build env details |
182 | print_os || true | |
183 | print_tooling || true | |
184 | ||
ae855ba1 MJ |
185 | # Enter the source directory |
186 | cd "$SRCDIR" | |
187 | ||
188 | # Run bootstrap in the source directory prior to configure | |
189 | ./bootstrap | |
190 | ||
191 | # Get source version from configure script | |
192 | eval "$(grep '^PACKAGE_VERSION=' ./configure)" | |
1d56e325 | 193 | PACKAGE_VERSION=${PACKAGE_VERSION//\-pre*/} |
ae855ba1 | 194 | |
ae855ba1 MJ |
195 | |
196 | # Set configure options and environment variables for each build | |
197 | # configuration. | |
1d56e325 | 198 | CONF_OPTS=("--prefix=$PREFIX") |
ae855ba1 MJ |
199 | case "$conf" in |
200 | static) | |
1d56e325 MJ |
201 | echo "Static lib only configuration" |
202 | ||
203 | CONF_OPTS+=("--enable-static" "--disable-shared") | |
ae855ba1 MJ |
204 | ;; |
205 | ||
206 | *) | |
1d56e325 | 207 | echo "Standard configuration" |
ae855ba1 MJ |
208 | ;; |
209 | esac | |
210 | ||
211 | # Build type | |
1d56e325 MJ |
212 | # oot : out-of-tree build |
213 | # dist : build via make dist | |
214 | # oot-dist: build via make dist out-of-tree | |
215 | # * : normal tree build | |
ae855ba1 | 216 | # |
1d56e325 MJ |
217 | # Make sure to move to the build directory and run configure |
218 | # before continuing. | |
ae855ba1 MJ |
219 | case "$build" in |
220 | oot) | |
221 | echo "Out of tree build" | |
1d56e325 MJ |
222 | |
223 | # Create and enter a temporary build directory | |
224 | builddir=$(mktemp -d) | |
225 | cd "$builddir" | |
226 | ||
51c9c62d | 227 | "$SRCDIR/configure" "${CONF_OPTS[@]}" || failed_configure |
ae855ba1 MJ |
228 | ;; |
229 | ||
230 | dist) | |
1d56e325 MJ |
231 | echo "Distribution in-tree build" |
232 | ||
233 | # Run configure and generate the tar file | |
234 | # in the source directory | |
51c9c62d | 235 | ./configure || failed_configure |
1d56e325 MJ |
236 | $MAKE dist |
237 | ||
238 | # Create and enter a temporary build directory | |
239 | builddir=$(mktemp -d) | |
240 | cd "$builddir" | |
241 | ||
242 | # Extract the distribution tar in the build directory, | |
243 | # ignore the first directory level | |
244 | $TAR xvf "$SRCDIR"/*.tar.* --strip 1 | |
245 | ||
246 | # Build in extracted source tree | |
51c9c62d | 247 | ./configure "${CONF_OPTS[@]}" || failed_configure |
1d56e325 MJ |
248 | ;; |
249 | ||
250 | oot-dist) | |
ae855ba1 | 251 | echo "Distribution out of tree build" |
ae855ba1 | 252 | |
1d56e325 MJ |
253 | # Create and enter a temporary build directory |
254 | builddir=$(mktemp -d) | |
255 | cd "$builddir" | |
256 | ||
257 | # Run configure out of tree and generate the tar file | |
51c9c62d | 258 | "$SRCDIR/configure" || failed_configure |
ae855ba1 MJ |
259 | $MAKE dist |
260 | ||
1d56e325 MJ |
261 | dist_srcdir="$(mktemp -d)" |
262 | cd "$dist_srcdir" | |
ae855ba1 | 263 | |
1d56e325 MJ |
264 | # Extract the distribution tar in the new source directory, |
265 | # ignore the first directory level | |
266 | $TAR xvf "$builddir"/*.tar.* --strip 1 | |
ae855ba1 | 267 | |
1d56e325 MJ |
268 | # Create and enter a second temporary build directory |
269 | builddir="$(mktemp -d)" | |
270 | cd "$builddir" | |
271 | ||
272 | # Run configure from the extracted distribution tar, | |
273 | # out of the source tree | |
51c9c62d | 274 | "$dist_srcdir/configure" "${CONF_OPTS[@]}" || failed_configure |
ae855ba1 MJ |
275 | ;; |
276 | ||
277 | *) | |
278 | echo "Standard in-tree build" | |
51c9c62d | 279 | ./configure "${CONF_OPTS[@]}" || failed_configure |
ae855ba1 MJ |
280 | ;; |
281 | esac | |
282 | ||
1d56e325 MJ |
283 | # We are now inside a configured build directory |
284 | ||
ae855ba1 MJ |
285 | # BUILD! |
286 | $MAKE -j "$($NPROC)" V=1 | |
ae855ba1 | 287 | |
1d56e325 MJ |
288 | # Install in the workspace |
289 | $MAKE install DESTDIR="$WORKSPACE" | |
290 | ||
291 | # Run tests, don't fail now, we want to run the archiving steps | |
292 | set +e | |
ae855ba1 | 293 | $MAKE --keep-going check |
1d56e325 MJ |
294 | ret=$? |
295 | set -e | |
ae855ba1 | 296 | |
1d56e325 | 297 | # Copy tap logs for the jenkins tap parser before cleaning the build dir |
4b8ed6e3 | 298 | #rsync -a --exclude 'test-suite.log' --include '*/' --include '*.log' --exclude='*' tests/ "$WORKSPACE/tap" |
1d56e325 MJ |
299 | |
300 | # Clean the build directory | |
ae855ba1 MJ |
301 | $MAKE clean |
302 | ||
303 | # Cleanup rpath in executables and shared libraries | |
1d56e325 MJ |
304 | #find "$WORKSPACE/$PREFIX/bin" -type f -perm -0500 -exec chrpath --delete {} \; |
305 | find "$WORKSPACE/$PREFIX/lib" -name "*.so" -exec chrpath --delete {} \; | |
ae855ba1 MJ |
306 | |
307 | # Remove libtool .la files | |
1d56e325 | 308 | find "$WORKSPACE/$PREFIX/lib" -name "*.la" -exec rm -f {} \; |
ae855ba1 | 309 | |
1d56e325 MJ |
310 | # Exit with the return code of the test suite |
311 | exit $ret | |
ae855ba1 MJ |
312 | |
313 | # EOF |