d56a399fcdbe9869c88c971b44e24de5ff014c8e
[lttng-ci.git] / scripts / librseq / build.sh
1 #!/bin/bash
2 #
3 # Copyright (C) 2015 Jonathan Rajotte-Julien <jonathan.rajotte-julien@efficios.com>
4 # Copyright (C) 2019-2020 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 set -exu
20
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
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
84 # Required variables
85 WORKSPACE=${WORKSPACE:-}
86
87 platform=${platform:-}
88 conf=${conf:-}
89 build=${build:-}
90 cc=${cc:-}
91
92
93 SRCDIR="$WORKSPACE/src/librseq"
94 TMPDIR="$WORKSPACE/tmp"
95 PREFIX="/build"
96
97 # Create tmp directory
98 rm -rf "$TMPDIR"
99 mkdir -p "$TMPDIR"
100
101 export TMPDIR
102 export CFLAGS="-g -O2"
103
104 # Add the convenience headers in extra to the
105 # include path.
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-*)
115 export CC=gcc-${cc#gcc-}
116 export CXX=g++-${cc#gcc-}
117 ;;
118 clang)
119 export CC=clang
120 export CXX=clang++
121 ;;
122 clang-*)
123 export CC=clang-${cc#clang-}
124 export CXX=clang++-${cc#clang-}
125 ;;
126 *)
127 if [ "x$cc" != "x" ]; then
128 export CC="$cc"
129 fi
130 ;;
131 esac
132
133 if [ "x${CC:-}" != "x" ]; then
134 echo "Selected compiler:"
135 "$CC" -v
136 fi
137
138 # Set platform variables
139 case "$platform" in
140 *)
141 export MAKE=make
142 export TAR=tar
143 export NPROC=nproc
144 export PYTHON="python3"
145 export PYTHON_CONFIG="python3-config"
146 ;;
147 esac
148
149 # Print build env details
150 print_os || true
151 print_tooling || true
152
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)"
161 PACKAGE_VERSION=${PACKAGE_VERSION//\-pre*/}
162
163
164 # Set configure options and environment variables for each build
165 # configuration.
166 CONF_OPTS=("--prefix=$PREFIX")
167 case "$conf" in
168 static)
169 echo "Static lib only configuration"
170
171 CONF_OPTS+=("--enable-static" "--disable-shared")
172 ;;
173
174 *)
175 echo "Standard configuration"
176 ;;
177 esac
178
179 # Build type
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
184 #
185 # Make sure to move to the build directory and run configure
186 # before continuing.
187 case "$build" in
188 oot)
189 echo "Out of tree build"
190
191 # Create and enter a temporary build directory
192 builddir=$(mktemp -d)
193 cd "$builddir"
194
195 "$SRCDIR/configure" "${CONF_OPTS[@]}" || failed_configure
196 ;;
197
198 dist)
199 echo "Distribution in-tree build"
200
201 # Run configure and generate the tar file
202 # in the source directory
203 ./configure || failed_configure
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
215 ./configure "${CONF_OPTS[@]}" || failed_configure
216 ;;
217
218 oot-dist)
219 echo "Distribution out of tree build"
220
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
226 "$SRCDIR/configure" || failed_configure
227 $MAKE dist
228
229 dist_srcdir="$(mktemp -d)"
230 cd "$dist_srcdir"
231
232 # Extract the distribution tar in the new source directory,
233 # ignore the first directory level
234 $TAR xvf "$builddir"/*.tar.* --strip 1
235
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
242 "$dist_srcdir/configure" "${CONF_OPTS[@]}" || failed_configure
243 ;;
244
245 *)
246 echo "Standard in-tree build"
247 ./configure "${CONF_OPTS[@]}" || failed_configure
248 ;;
249 esac
250
251 # We are now inside a configured build directory
252
253 # BUILD!
254 $MAKE -j "$($NPROC)" V=1
255
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
261 $MAKE --keep-going check
262 ret=$?
263 set -e
264
265 # Copy tap logs for the jenkins tap parser before cleaning the build dir
266 rsync -a --exclude 'test-suite.log' --include '*/' --include '*.log' --exclude='*' tests/ "$WORKSPACE/tap"
267
268 # Clean the build directory
269 $MAKE clean
270
271 # Cleanup rpath in executables and shared libraries
272 #find "$WORKSPACE/$PREFIX/bin" -type f -perm -0500 -exec chrpath --delete {} \;
273 find "$WORKSPACE/$PREFIX/lib" -name "*.so" -exec chrpath --delete {} \;
274
275 # Remove libtool .la files
276 find "$WORKSPACE/$PREFIX/lib" -name "*.la" -exec rm -f {} \;
277
278 # Exit with the return code of the test suite
279 exit $ret
280
281 # EOF
This page took 0.066551 seconds and 3 git commands to generate.