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