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 | ||
9a07183c | 87 | platform=${platform:-} |
ae855ba1 MJ |
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 | ;; | |
9a07183c MJ |
114 | gcc-*) |
115 | export CC=gcc-${cc#gcc-} | |
116 | export CXX=g++-${cc#gcc-} | |
ae855ba1 MJ |
117 | ;; |
118 | clang) | |
119 | export CC=clang | |
120 | export CXX=clang++ | |
121 | ;; | |
9a07183c MJ |
122 | clang-*) |
123 | export CC=clang-${cc#clang-} | |
124 | export CXX=clang++-${cc#clang-} | |
ae855ba1 MJ |
125 | ;; |
126 | *) | |
127 | if [ "x$cc" != "x" ]; then | |
128 | export CC="$cc" | |
129 | fi | |
130 | ;; | |
131 | esac | |
132 | ||
1d56e325 MJ |
133 | if [ "x${CC:-}" != "x" ]; then |
134 | echo "Selected compiler:" | |
135 | "$CC" -v | |
136 | fi | |
137 | ||
ae855ba1 | 138 | # Set platform variables |
9a07183c | 139 | case "$platform" in |
ae855ba1 MJ |
140 | *) |
141 | export MAKE=make | |
142 | export TAR=tar | |
143 | export NPROC=nproc | |
1d56e325 MJ |
144 | export PYTHON="python3" |
145 | export PYTHON_CONFIG="python3-config" | |
ae855ba1 MJ |
146 | ;; |
147 | esac | |
148 | ||
51c9c62d MJ |
149 | # Print build env details |
150 | print_os || true | |
151 | print_tooling || true | |
152 | ||
ae855ba1 MJ |
153 | # Enter the source directory |
154 | cd "$SRCDIR" | |
155 | ||
156 | # Run bootstrap in the source directory prior to configure | |
157 | ./bootstrap | |
158 | ||
159 | # Get source version from configure script | |
160 | eval "$(grep '^PACKAGE_VERSION=' ./configure)" | |
1d56e325 | 161 | PACKAGE_VERSION=${PACKAGE_VERSION//\-pre*/} |
ae855ba1 | 162 | |
ae855ba1 MJ |
163 | |
164 | # Set configure options and environment variables for each build | |
165 | # configuration. | |
1d56e325 | 166 | CONF_OPTS=("--prefix=$PREFIX") |
ae855ba1 MJ |
167 | case "$conf" in |
168 | static) | |
1d56e325 MJ |
169 | echo "Static lib only configuration" |
170 | ||
171 | CONF_OPTS+=("--enable-static" "--disable-shared") | |
ae855ba1 MJ |
172 | ;; |
173 | ||
174 | *) | |
1d56e325 | 175 | echo "Standard configuration" |
ae855ba1 MJ |
176 | ;; |
177 | esac | |
178 | ||
179 | # Build type | |
1d56e325 MJ |
180 | # oot : out-of-tree build |
181 | # dist : build via make dist | |
182 | # oot-dist: build via make dist out-of-tree | |
183 | # * : normal tree build | |
ae855ba1 | 184 | # |
1d56e325 MJ |
185 | # Make sure to move to the build directory and run configure |
186 | # before continuing. | |
ae855ba1 MJ |
187 | case "$build" in |
188 | oot) | |
189 | echo "Out of tree build" | |
1d56e325 MJ |
190 | |
191 | # Create and enter a temporary build directory | |
192 | builddir=$(mktemp -d) | |
193 | cd "$builddir" | |
194 | ||
51c9c62d | 195 | "$SRCDIR/configure" "${CONF_OPTS[@]}" || failed_configure |
ae855ba1 MJ |
196 | ;; |
197 | ||
198 | dist) | |
1d56e325 MJ |
199 | echo "Distribution in-tree build" |
200 | ||
201 | # Run configure and generate the tar file | |
202 | # in the source directory | |
51c9c62d | 203 | ./configure || failed_configure |
1d56e325 MJ |
204 | $MAKE dist |
205 | ||
206 | # Create and enter a temporary build directory | |
207 | builddir=$(mktemp -d) | |
208 | cd "$builddir" | |
209 | ||
210 | # Extract the distribution tar in the build directory, | |
211 | # ignore the first directory level | |
212 | $TAR xvf "$SRCDIR"/*.tar.* --strip 1 | |
213 | ||
214 | # Build in extracted source tree | |
51c9c62d | 215 | ./configure "${CONF_OPTS[@]}" || failed_configure |
1d56e325 MJ |
216 | ;; |
217 | ||
218 | oot-dist) | |
ae855ba1 | 219 | echo "Distribution out of tree build" |
ae855ba1 | 220 | |
1d56e325 MJ |
221 | # Create and enter a temporary build directory |
222 | builddir=$(mktemp -d) | |
223 | cd "$builddir" | |
224 | ||
225 | # Run configure out of tree and generate the tar file | |
51c9c62d | 226 | "$SRCDIR/configure" || failed_configure |
ae855ba1 MJ |
227 | $MAKE dist |
228 | ||
1d56e325 MJ |
229 | dist_srcdir="$(mktemp -d)" |
230 | cd "$dist_srcdir" | |
ae855ba1 | 231 | |
1d56e325 MJ |
232 | # Extract the distribution tar in the new source directory, |
233 | # ignore the first directory level | |
234 | $TAR xvf "$builddir"/*.tar.* --strip 1 | |
ae855ba1 | 235 | |
1d56e325 MJ |
236 | # Create and enter a second temporary build directory |
237 | builddir="$(mktemp -d)" | |
238 | cd "$builddir" | |
239 | ||
240 | # Run configure from the extracted distribution tar, | |
241 | # out of the source tree | |
51c9c62d | 242 | "$dist_srcdir/configure" "${CONF_OPTS[@]}" || failed_configure |
ae855ba1 MJ |
243 | ;; |
244 | ||
245 | *) | |
246 | echo "Standard in-tree build" | |
51c9c62d | 247 | ./configure "${CONF_OPTS[@]}" || failed_configure |
ae855ba1 MJ |
248 | ;; |
249 | esac | |
250 | ||
1d56e325 MJ |
251 | # We are now inside a configured build directory |
252 | ||
ae855ba1 MJ |
253 | # BUILD! |
254 | $MAKE -j "$($NPROC)" V=1 | |
ae855ba1 | 255 | |
1d56e325 MJ |
256 | # Install in the workspace |
257 | $MAKE install DESTDIR="$WORKSPACE" | |
258 | ||
259 | # Run tests, don't fail now, we want to run the archiving steps | |
260 | set +e | |
ae855ba1 | 261 | $MAKE --keep-going check |
1d56e325 MJ |
262 | ret=$? |
263 | set -e | |
ae855ba1 | 264 | |
1d56e325 | 265 | # Copy tap logs for the jenkins tap parser before cleaning the build dir |
10c9bf80 | 266 | rsync -a --exclude 'test-suite.log' --include '*/' --include '*.log' --exclude='*' tests/ "$WORKSPACE/tap" |
1d56e325 | 267 | |
4174b905 MJ |
268 | # Copy the test suites top-level log which includes all tests failures |
269 | rsync -a --include 'test-suite.log' --include '*/' --exclude='*' tests/ "$WORKSPACE/log" | |
270 | ||
1d56e325 | 271 | # Clean the build directory |
ae855ba1 MJ |
272 | $MAKE clean |
273 | ||
274 | # Cleanup rpath in executables and shared libraries | |
1d56e325 MJ |
275 | #find "$WORKSPACE/$PREFIX/bin" -type f -perm -0500 -exec chrpath --delete {} \; |
276 | find "$WORKSPACE/$PREFIX/lib" -name "*.so" -exec chrpath --delete {} \; | |
ae855ba1 MJ |
277 | |
278 | # Remove libtool .la files | |
1d56e325 | 279 | find "$WORKSPACE/$PREFIX/lib" -name "*.la" -exec rm -f {} \; |
ae855ba1 | 280 | |
1d56e325 MJ |
281 | # Exit with the return code of the test suite |
282 | exit $ret | |
ae855ba1 MJ |
283 | |
284 | # EOF |