jjb: babeltrace: build.sh is now shellcheck clean
[lttng-ci.git] / scripts / liburcu / build.sh
CommitLineData
72f4f0c1 1#!/bin/bash -exu
e3022ad9
MJ
2#
3# Copyright (C) 2015 - Jonathan Rajotte-Julien <jonathan.rajotte-julien@efficios.com>
6d35c326 4# 2016 - Michael Jeanson <mjeanson@efficios.com>
e3022ad9
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
5fd8db76 19# Version compare functions
0a6e708b
MJ
20vercomp () {
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
5fd8db76 47verlte() {
0a6e708b
MJ
48 vercomp "$1" "$2"; local res="$?"
49 [ "$res" -eq "0" ] || [ "$res" -eq "2" ]
5fd8db76
MJ
50}
51
52verlt() {
0a6e708b
MJ
53 vercomp "$1" "$2"; local res="$?"
54 [ "$res" -eq "2" ]
5fd8db76
MJ
55}
56
57vergte() {
0a6e708b
MJ
58 vercomp "$1" "$2"; local res="$?"
59 [ "$res" -eq "0" ] || [ "$res" -eq "1" ]
5fd8db76
MJ
60}
61
62vergt() {
0a6e708b
MJ
63 vercomp "$1" "$2"; local res="$?"
64 [ "$res" -eq "1" ]
65}
66
67verne() {
68 vercomp "$1" "$2"; local res="$?"
69 [ "$res" -ne "0" ]
5fd8db76
MJ
70}
71
a57a60d9
MJ
72# Required parameters
73arch=${arch:-}
74conf=${conf:-}
75build=${build:-}
76
e3022ad9 77
6d35c326
MJ
78SRCDIR="$WORKSPACE/src/liburcu"
79TMPDIR="$WORKSPACE/tmp"
56162e2a
JRJ
80PREFIX="$WORKSPACE/build"
81
6d35c326
MJ
82# Create build and tmp directories
83rm -rf "$PREFIX" "$TMPDIR"
84mkdir -p "$PREFIX" "$TMPDIR"
85
86export TMPDIR
72d087d4 87export CFLAGS="-g -O2"
6d35c326 88
72f4f0c1 89# Set platform variables
7491c28d 90case "$arch" in
995ac8f2
MJ
91sol10-i386)
92 export MAKE=gmake
93 export TAR=gtar
94 export NPROC=gnproc
95 export BISON=bison
96 export YACC="$BISON -y"
ad11244c 97 export PATH="/opt/csw/bin:/usr/ccs/bin:$PATH"
995ac8f2
MJ
98 export CPPFLAGS="-I/opt/csw/include"
99 export LDFLAGS="-L/opt/csw/lib -R/opt/csw/lib"
100 export PKG_CONFIG_PATH="/opt/csw/lib/pkgconfig"
7491c28d 101 ;;
995ac8f2
MJ
102sol11-i386)
103 export MAKE=gmake
104 export TAR=gtar
105 export NPROC=nproc
7491c28d 106 export PATH="$PATH:/usr/perl5/bin"
995ac8f2
MJ
107 #export LD_ALTEXEC=/usr/sfw/bin/gld
108 #export LD=/usr/sfw/bin/gld
7491c28d 109 ;;
f7bf4d7a 110macosx)
995ac8f2
MJ
111 export MAKE=make
112 export TAR=tar
113 export NPROC="getconf _NPROCESSORS_ONLN"
114 export BISON="bison"
115 export YACC="$BISON -y"
116 export LDFLAGS="-L/opt/local/lib"
72d087d4 117 export CFLAGS="$CFLAGS -I/opt/local/include"
f7bf4d7a 118 export PATH="/opt/local/bin:/opt/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"
f7bf4d7a
MJ
119 ;;
120
7491c28d 121*)
995ac8f2
MJ
122 export MAKE=make
123 export TAR=tar
124 export NPROC=nproc
7491c28d
MJ
125 ;;
126esac
127
cd9733d5
JR
128# Enter the source directory
129cd "$SRCDIR"
130
131# Run bootstrap in the source directory prior to configure
132./bootstrap
133
134# Get source version from configure script
135eval "$(grep '^PACKAGE_VERSION=' ./configure)"
136
137# Set configure options and environment variables for each build
138# configuration.
72f4f0c1 139CONF_OPTS=""
56162e2a
JRJ
140case "$conf" in
141static)
142 echo "Static build"
143 CONF_OPTS="--enable-static --disable-shared"
144 ;;
72f4f0c1 145
a57a60d9 146tls_fallback)
56162e2a
JRJ
147 echo "Using pthread_getspecific() to emulate TLS"
148 CONF_OPTS="--disable-compiler-tls"
149 ;;
72f4f0c1 150
cd9733d5
JR
151debug-rcu)
152 echo "Enable RCU sanity checks for debugging"
a0493692 153 if vergte "$PACKAGE_VERSION" "0.10"; then
b3fa9d68 154 CONF_OPTS="--enable-rcu-debug"
cd9733d5 155 else
72d087d4 156 export CFLAGS="$CFLAGS -DDEBUG_RCU"
cd9733d5 157 fi
25e13783
JR
158
159 echo "Enable iterator sanity validator"
160 if vergte "$PACKAGE_VERSION" "0.11"; then
161 CONF_OPTS+=" --enable-cds-lfht-iter-debug"
162 fi
cd9733d5
JR
163 ;;
164
56162e2a
JRJ
165*)
166 echo "Standard build"
167 CONF_OPTS=""
168 ;;
169esac
170
595a34c7
JR
171# Build type
172# oot : out-of-tree build
173# dist: build via make dist
174# * : normal tree build
175#
176# Make sure to move to the build_path and configure
177# before continuing
6d35c326 178BUILD_PATH=$SRCDIR
595a34c7 179case "$build" in
72f4f0c1
MJ
180oot)
181 echo "Out of tree build"
182 BUILD_PATH=$WORKSPACE/oot
0a6e708b
MJ
183 mkdir -p "$BUILD_PATH"
184 cd "$BUILD_PATH"
995ac8f2 185 "$SRCDIR/configure" --prefix="$PREFIX" $CONF_OPTS
72f4f0c1
MJ
186 ;;
187
188dist)
189 echo "Distribution out of tree build"
a57a60d9 190 BUILD_PATH=$(mktemp -d)
72f4f0c1
MJ
191
192 # Initial configure and generate tarball
995ac8f2 193 "$SRCDIR/configure"
72f4f0c1
MJ
194 $MAKE dist
195
0a6e708b
MJ
196 mkdir -p "$BUILD_PATH"
197 cp ./*.tar.* "$BUILD_PATH/"
198 cd "$BUILD_PATH"
72f4f0c1
MJ
199
200 # Ignore level 1 of tar
0a6e708b 201 $TAR xvf ./*.tar.* --strip 1
72f4f0c1 202
995ac8f2 203 "$BUILD_PATH/configure" --prefix="$PREFIX" $CONF_OPTS
72f4f0c1
MJ
204 ;;
205*)
6d35c326 206 echo "Standard in-tree build"
995ac8f2 207 "$BUILD_PATH/configure" --prefix="$PREFIX" $CONF_OPTS
72f4f0c1 208 ;;
595a34c7
JR
209esac
210
72f4f0c1 211# BUILD!
a57a60d9 212$MAKE -j "$($NPROC)" V=1
7491c28d 213$MAKE install
72f4f0c1
MJ
214
215# Run tests
6827c67a 216$MAKE --keep-going check
5fd8db76
MJ
217# Only run regtest for 0.9 and up
218if vergte "$PACKAGE_VERSION" "0.9"; then
72f4f0c1 219 $MAKE regtest
5fd8db76 220fi
72f4f0c1
MJ
221
222# Cleanup
7491c28d 223$MAKE clean
56162e2a 224
72f4f0c1
MJ
225# Cleanup rpath in executables and shared libraries
226#find $WORKSPACE/build/bin -type f -perm -0500 -exec chrpath --delete {} \;
0a6e708b 227find "$PREFIX/lib" -name "*.so" -exec chrpath --delete {} \;
72f4f0c1
MJ
228
229# Remove libtool .la files
0a6e708b 230find "$PREFIX/lib" -name "*.la" -exec rm -f {} \;
595a34c7 231
cdcf7df4 232# Cleanup temp directory of dist build
72f4f0c1 233if [ "$build" = "dist" ]; then
0a6e708b
MJ
234 cd "$SRCDIR"
235 rm -rf "$BUILD_PATH"
595a34c7 236fi
7491c28d
MJ
237
238# EOF
This page took 0.095408 seconds and 4 git commands to generate.