jjb: liburcu: Use "--enable-rcu-debug" when version >=0.10
[lttng-ci.git] / scripts / liburcu / build.sh
1 #!/bin/bash -exu
2 #
3 # Copyright (C) 2015 - Jonathan Rajotte-Julien <jonathan.rajotte-julien@efficios.com>
4 # 2016 - 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
77
78 SRCDIR="$WORKSPACE/src/liburcu"
79 TMPDIR="$WORKSPACE/tmp"
80 PREFIX="$WORKSPACE/build"
81
82 # Create build and tmp directories
83 rm -rf "$PREFIX" "$TMPDIR"
84 mkdir -p "$PREFIX" "$TMPDIR"
85
86 export TMPDIR
87
88 # Set platform variables
89 case "$arch" in
90 solaris10)
91 MAKE=gmake
92 TAR=gtar
93 NPROC=gnproc
94 LDFLAGS=""
95 CFLAGS="-D_XOPEN_SOURCE=1 -D_XOPEN_SOURCE_EXTENDED=1 -D__EXTENSIONS__=1"
96 ;;
97
98 solaris11)
99 MAKE=gmake
100 TAR=gtar
101 NPROC=nproc
102 LDFLAGS=""
103 CFLAGS="-D_XOPEN_SOURCE=1 -D_XOPEN_SOURCE_EXTENDED=1 -D__EXTENSIONS__=1"
104 export PATH="$PATH:/usr/perl5/bin"
105 ;;
106
107 macosx)
108 MAKE=make
109 TAR=tar
110 NPROC="getconf _NPROCESSORS_ONLN"
111 BISON="bison"
112 YACC="$BISON -y"
113 LDFLAGS="-L/opt/local/lib"
114 CFLAGS="-I/opt/local/include"
115 export PATH="/opt/local/bin:/opt/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"
116 ;;
117
118 *)
119 MAKE=make
120 TAR=tar
121 NPROC=nproc
122 LDFLAGS=""
123 CFLAGS=""
124 ;;
125 esac
126
127 # Enter the source directory
128 cd "$SRCDIR"
129
130 # Run bootstrap in the source directory prior to configure
131 ./bootstrap
132
133 # Get source version from configure script
134 eval "$(grep '^PACKAGE_VERSION=' ./configure)"
135
136 # Set configure options and environment variables for each build
137 # configuration.
138 CONF_OPTS=""
139 case "$conf" in
140 static)
141 echo "Static build"
142 CONF_OPTS="--enable-static --disable-shared"
143 ;;
144
145 tls_fallback)
146 echo "Using pthread_getspecific() to emulate TLS"
147 CONF_OPTS="--disable-compiler-tls"
148 ;;
149
150 debug-rcu)
151 echo "Enable RCU sanity checks for debugging"
152 if vergte "$PACKAGE_VERSION" "0.10"; then
153 CONF_OPTS="--enable-rcu-debug"
154 else
155 CFLAGS="$CFLAGS -DDEBUG_RCU"
156 fi
157 ;;
158
159 *)
160 echo "Standard build"
161 CONF_OPTS=""
162 ;;
163 esac
164
165 # Build type
166 # oot : out-of-tree build
167 # dist: build via make dist
168 # * : normal tree build
169 #
170 # Make sure to move to the build_path and configure
171 # before continuing
172 BUILD_PATH=$SRCDIR
173 case "$build" in
174 oot)
175 echo "Out of tree build"
176 BUILD_PATH=$WORKSPACE/oot
177 mkdir -p "$BUILD_PATH"
178 cd "$BUILD_PATH"
179 MAKE=$MAKE CFLAGS="$CFLAGS" LDFLAGS="$LDFLAGS" "$SRCDIR/configure" --prefix="$PREFIX" $CONF_OPTS
180 ;;
181
182 dist)
183 echo "Distribution out of tree build"
184 BUILD_PATH=$(mktemp -d)
185
186 # Initial configure and generate tarball
187 MAKE=$MAKE "$SRCDIR/configure"
188 $MAKE dist
189
190 mkdir -p "$BUILD_PATH"
191 cp ./*.tar.* "$BUILD_PATH/"
192 cd "$BUILD_PATH"
193
194 # Ignore level 1 of tar
195 $TAR xvf ./*.tar.* --strip 1
196
197 MAKE=$MAKE CFLAGS="$CFLAGS" LDFLAGS="$LDFLAGS" "$BUILD_PATH/configure" --prefix="$PREFIX" $CONF_OPTS
198 ;;
199 *)
200 echo "Standard in-tree build"
201 MAKE=$MAKE CFLAGS="$CFLAGS" LDFLAGS="$LDFLAGS" "$BUILD_PATH/configure" --prefix="$PREFIX" $CONF_OPTS
202 ;;
203 esac
204
205 # BUILD!
206 $MAKE -j "$($NPROC)" V=1
207 $MAKE install
208
209 # Run tests
210 $MAKE check
211 # Only run regtest for 0.9 and up
212 if vergte "$PACKAGE_VERSION" "0.9"; then
213 $MAKE regtest
214 fi
215
216 # Cleanup
217 $MAKE clean
218
219 # Cleanup rpath in executables and shared libraries
220 #find $WORKSPACE/build/bin -type f -perm -0500 -exec chrpath --delete {} \;
221 find "$PREFIX/lib" -name "*.so" -exec chrpath --delete {} \;
222
223 # Remove libtool .la files
224 find "$PREFIX/lib" -name "*.la" -exec rm -f {} \;
225
226 # Cleanup temp directory of dist build
227 if [ "$build" = "dist" ]; then
228 cd "$SRCDIR"
229 rm -rf "$BUILD_PATH"
230 fi
231
232 # EOF
This page took 0.11311 seconds and 5 git commands to generate.