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 | ||
72 | # Required parameters | |
73 | arch=${arch:-} | |
74 | conf=${conf:-} | |
75 | build=${build:-} | |
76 | cc=${cc:-} | |
77 | ||
78 | ||
79 | SRCDIR="$WORKSPACE/src/librseq" | |
80 | TMPDIR="$WORKSPACE/tmp" | |
81 | PREFIX="$WORKSPACE/build" | |
82 | ||
83 | # Create build and tmp directories | |
84 | rm -rf "$PREFIX" "$TMPDIR" | |
85 | mkdir -p "$PREFIX" "$TMPDIR" | |
86 | ||
87 | export TMPDIR | |
88 | export CFLAGS="-g -O2" | |
89 | export CPPFLAGS="-I$SRCDIR/extra" | |
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 | # Set platform variables | |
149 | case "$arch" in | |
150 | *) | |
151 | export MAKE=make | |
152 | export TAR=tar | |
153 | export NPROC=nproc | |
154 | ;; | |
155 | esac | |
156 | ||
157 | # Enter the source directory | |
158 | cd "$SRCDIR" | |
159 | ||
160 | # Run bootstrap in the source directory prior to configure | |
161 | ./bootstrap | |
162 | ||
163 | # Get source version from configure script | |
164 | eval "$(grep '^PACKAGE_VERSION=' ./configure)" | |
165 | ||
166 | TARBALL_FILE="librseq-$PACKAGE_VERSION.tar.bz2" | |
167 | ||
168 | # Set configure options and environment variables for each build | |
169 | # configuration. | |
170 | CONF_OPTS="" | |
171 | case "$conf" in | |
172 | static) | |
173 | echo "Static build" | |
174 | CONF_OPTS="--enable-static --disable-shared" | |
175 | ;; | |
176 | ||
177 | *) | |
178 | echo "Standard build" | |
179 | CONF_OPTS="" | |
180 | ;; | |
181 | esac | |
182 | ||
183 | # Build type | |
184 | # oot : out-of-tree build | |
185 | # dist: build via make dist | |
186 | # * : normal tree build | |
187 | # | |
188 | # Make sure to move to the build_path and configure | |
189 | # before continuing | |
190 | BUILD_PATH=$SRCDIR | |
191 | case "$build" in | |
192 | oot) | |
193 | echo "Out of tree build" | |
194 | BUILD_PATH=$WORKSPACE/oot | |
195 | mkdir -p "$BUILD_PATH" | |
196 | cd "$BUILD_PATH" | |
197 | "$SRCDIR/configure" --prefix="$PREFIX" $CONF_OPTS | |
198 | ;; | |
199 | ||
200 | dist) | |
201 | echo "Distribution out of tree build" | |
202 | BUILD_PATH=$(mktemp -d) | |
203 | ||
204 | # Initial configure and generate tarball | |
205 | "$SRCDIR/configure" | |
206 | $MAKE dist | |
207 | ||
208 | mkdir -p "$BUILD_PATH" | |
209 | cp "./$TARBALL_FILE" "$BUILD_PATH/" | |
210 | cd "$BUILD_PATH" | |
211 | ||
212 | # Ignore level 1 of tar | |
213 | $TAR xvf "$TARBALL_FILE" --strip 1 | |
214 | ||
215 | "$BUILD_PATH/configure" --prefix="$PREFIX" $CONF_OPTS | |
216 | ;; | |
217 | ||
218 | *) | |
219 | echo "Standard in-tree build" | |
220 | "$BUILD_PATH/configure" --prefix="$PREFIX" $CONF_OPTS | |
221 | ;; | |
222 | esac | |
223 | ||
224 | # BUILD! | |
225 | $MAKE -j "$($NPROC)" V=1 | |
226 | $MAKE install | |
227 | ||
228 | # Run tests | |
229 | $MAKE --keep-going check | |
230 | ||
231 | # Cleanup | |
232 | $MAKE clean | |
233 | ||
234 | # Cleanup rpath in executables and shared libraries | |
235 | find "$PREFIX/lib" -name "*.so" -exec chrpath --delete {} \; | |
236 | ||
237 | # Remove libtool .la files | |
238 | find "$PREFIX/lib" -name "*.la" -exec rm -f {} \; | |
239 | ||
240 | # Cleanup temp directory of dist build | |
241 | if [ "$build" = "dist" ]; then | |
242 | cd "$SRCDIR" | |
243 | rm -rf "$BUILD_PATH" | |
244 | fi | |
245 | ||
246 | # EOF |