Merge pull request #19 from frdeso/kprobe_fuzzing_pr
[lttng-ci.git] / scripts / liburcu / build.sh
... / ...
CommitLineData
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
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
47verlte() {
48 vercomp "$1" "$2"; local res="$?"
49 [ "$res" -eq "0" ] || [ "$res" -eq "2" ]
50}
51
52verlt() {
53 vercomp "$1" "$2"; local res="$?"
54 [ "$res" -eq "2" ]
55}
56
57vergte() {
58 vercomp "$1" "$2"; local res="$?"
59 [ "$res" -eq "0" ] || [ "$res" -eq "1" ]
60}
61
62vergt() {
63 vercomp "$1" "$2"; local res="$?"
64 [ "$res" -eq "1" ]
65}
66
67verne() {
68 vercomp "$1" "$2"; local res="$?"
69 [ "$res" -ne "0" ]
70}
71
72# Required parameters
73arch=${arch:-}
74conf=${conf:-}
75build=${build:-}
76
77
78SRCDIR="$WORKSPACE/src/liburcu"
79TMPDIR="$WORKSPACE/tmp"
80PREFIX="$WORKSPACE/build"
81
82# Create build and tmp directories
83rm -rf "$PREFIX" "$TMPDIR"
84mkdir -p "$PREFIX" "$TMPDIR"
85
86export TMPDIR
87
88# Set platform variables
89case "$arch" in
90solaris10)
91 MAKE=gmake
92 TAR=gtar
93 NPROC=gnproc
94 LDFLAGS=""
95 CFLAGS=""
96 export PATH="/opt/csw/bin:/usr/ccs/bin:$PATH"
97 ;;
98
99solaris11)
100 MAKE=gmake
101 TAR=gtar
102 NPROC=nproc
103 LDFLAGS=""
104 CFLAGS=""
105 export PATH="$PATH:/usr/perl5/bin"
106 ;;
107
108macosx)
109 MAKE=make
110 TAR=tar
111 NPROC="getconf _NPROCESSORS_ONLN"
112 BISON="bison"
113 YACC="$BISON -y"
114 LDFLAGS="-L/opt/local/lib"
115 CFLAGS="-I/opt/local/include"
116 export PATH="/opt/local/bin:/opt/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"
117 ;;
118
119*)
120 MAKE=make
121 TAR=tar
122 NPROC=nproc
123 LDFLAGS=""
124 CFLAGS=""
125 ;;
126esac
127
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.
139CONF_OPTS=""
140case "$conf" in
141static)
142 echo "Static build"
143 CONF_OPTS="--enable-static --disable-shared"
144 ;;
145
146tls_fallback)
147 echo "Using pthread_getspecific() to emulate TLS"
148 CONF_OPTS="--disable-compiler-tls"
149 ;;
150
151debug-rcu)
152 echo "Enable RCU sanity checks for debugging"
153 if vergte "$PACKAGE_VERSION" "0.10"; then
154 CONF_OPTS="--enable-rcu-debug"
155 else
156 CFLAGS="$CFLAGS -DDEBUG_RCU"
157 fi
158 ;;
159
160*)
161 echo "Standard build"
162 CONF_OPTS=""
163 ;;
164esac
165
166# Build type
167# oot : out-of-tree build
168# dist: build via make dist
169# * : normal tree build
170#
171# Make sure to move to the build_path and configure
172# before continuing
173BUILD_PATH=$SRCDIR
174case "$build" in
175oot)
176 echo "Out of tree build"
177 BUILD_PATH=$WORKSPACE/oot
178 mkdir -p "$BUILD_PATH"
179 cd "$BUILD_PATH"
180 MAKE=$MAKE CFLAGS="$CFLAGS" LDFLAGS="$LDFLAGS" "$SRCDIR/configure" --prefix="$PREFIX" $CONF_OPTS
181 ;;
182
183dist)
184 echo "Distribution out of tree build"
185 BUILD_PATH=$(mktemp -d)
186
187 # Initial configure and generate tarball
188 MAKE=$MAKE "$SRCDIR/configure"
189 $MAKE dist
190
191 mkdir -p "$BUILD_PATH"
192 cp ./*.tar.* "$BUILD_PATH/"
193 cd "$BUILD_PATH"
194
195 # Ignore level 1 of tar
196 $TAR xvf ./*.tar.* --strip 1
197
198 MAKE=$MAKE CFLAGS="$CFLAGS" LDFLAGS="$LDFLAGS" "$BUILD_PATH/configure" --prefix="$PREFIX" $CONF_OPTS
199 ;;
200*)
201 echo "Standard in-tree build"
202 MAKE=$MAKE CFLAGS="$CFLAGS" LDFLAGS="$LDFLAGS" "$BUILD_PATH/configure" --prefix="$PREFIX" $CONF_OPTS
203 ;;
204esac
205
206# BUILD!
207$MAKE -j "$($NPROC)" V=1
208$MAKE install
209
210# Run tests
211$MAKE check
212# Only run regtest for 0.9 and up
213if vergte "$PACKAGE_VERSION" "0.9"; then
214 $MAKE regtest
215fi
216
217# Cleanup
218$MAKE clean
219
220# Cleanup rpath in executables and shared libraries
221#find $WORKSPACE/build/bin -type f -perm -0500 -exec chrpath --delete {} \;
222find "$PREFIX/lib" -name "*.so" -exec chrpath --delete {} \;
223
224# Remove libtool .la files
225find "$PREFIX/lib" -name "*.la" -exec rm -f {} \;
226
227# Cleanup temp directory of dist build
228if [ "$build" = "dist" ]; then
229 cd "$SRCDIR"
230 rm -rf "$BUILD_PATH"
231fi
232
233# EOF
This page took 0.022235 seconds and 4 git commands to generate.