jjb: build scripts cleanups
[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
87
72f4f0c1 88# Set platform variables
7491c28d
MJ
89case "$arch" in
90solaris10)
91 MAKE=gmake
92 TAR=gtar
93 NPROC=gnproc
94 CFLAGS="-D_XOPEN_SOURCE=1 -D_XOPEN_SOURCE_EXTENDED=1 -D__EXTENSIONS__=1"
95 ;;
72f4f0c1 96
7491c28d
MJ
97solaris11)
98 MAKE=gmake
99 TAR=gtar
100 NPROC=nproc
101 CFLAGS="-D_XOPEN_SOURCE=1 -D_XOPEN_SOURCE_EXTENDED=1 -D__EXTENSIONS__=1"
102 export PATH="$PATH:/usr/perl5/bin"
103 ;;
72f4f0c1 104
f7bf4d7a
MJ
105macosx)
106 MAKE=make
107 TAR=tar
108 NPROC="getconf _NPROCESSORS_ONLN"
109 BISON="bison"
110 YACC="$BISON -y"
111 export PATH="/opt/local/bin:/opt/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"
112 export CFLAGS="-I/opt/local/include"
113 export LDFLAGS="-L/opt/local/lib"
114 ;;
115
7491c28d
MJ
116*)
117 MAKE=make
118 TAR=tar
119 NPROC=nproc
120 CFLAGS=""
121 ;;
122esac
123
72f4f0c1
MJ
124# Set configure options for each build configuration
125CONF_OPTS=""
56162e2a
JRJ
126case "$conf" in
127static)
128 echo "Static build"
129 CONF_OPTS="--enable-static --disable-shared"
130 ;;
72f4f0c1 131
a57a60d9 132tls_fallback)
56162e2a
JRJ
133 echo "Using pthread_getspecific() to emulate TLS"
134 CONF_OPTS="--disable-compiler-tls"
135 ;;
72f4f0c1 136
56162e2a
JRJ
137*)
138 echo "Standard build"
139 CONF_OPTS=""
140 ;;
141esac
142
72f4f0c1 143
6d35c326
MJ
144# Enter the source directory
145cd "$SRCDIR"
146
147# Run bootstrap in the source directory prior to configure
72f4f0c1
MJ
148./bootstrap
149
5fd8db76 150# Get source version from configure script
a57a60d9 151eval "$(grep '^PACKAGE_VERSION=' ./configure)"
5fd8db76 152
72f4f0c1 153
595a34c7
JR
154# Build type
155# oot : out-of-tree build
156# dist: build via make dist
157# * : normal tree build
158#
159# Make sure to move to the build_path and configure
160# before continuing
6d35c326 161BUILD_PATH=$SRCDIR
595a34c7 162case "$build" in
72f4f0c1
MJ
163oot)
164 echo "Out of tree build"
165 BUILD_PATH=$WORKSPACE/oot
0a6e708b
MJ
166 mkdir -p "$BUILD_PATH"
167 cd "$BUILD_PATH"
168 MAKE=$MAKE CFLAGS="$CFLAGS" "$SRCDIR/configure" --prefix="$PREFIX" $CONF_OPTS
72f4f0c1
MJ
169 ;;
170
171dist)
172 echo "Distribution out of tree build"
a57a60d9 173 BUILD_PATH=$(mktemp -d)
72f4f0c1
MJ
174
175 # Initial configure and generate tarball
0a6e708b 176 MAKE=$MAKE "$SRCDIR/configure"
72f4f0c1
MJ
177 $MAKE dist
178
0a6e708b
MJ
179 mkdir -p "$BUILD_PATH"
180 cp ./*.tar.* "$BUILD_PATH/"
181 cd "$BUILD_PATH"
72f4f0c1
MJ
182
183 # Ignore level 1 of tar
0a6e708b 184 $TAR xvf ./*.tar.* --strip 1
72f4f0c1 185
0a6e708b 186 MAKE=$MAKE CFLAGS="$CFLAGS" "$BUILD_PATH/configure" --prefix="$PREFIX" $CONF_OPTS
72f4f0c1
MJ
187 ;;
188*)
6d35c326 189 echo "Standard in-tree build"
0a6e708b 190 MAKE=$MAKE CFLAGS="$CFLAGS" "$BUILD_PATH/configure" --prefix="$PREFIX" $CONF_OPTS
72f4f0c1 191 ;;
595a34c7
JR
192esac
193
72f4f0c1 194# BUILD!
a57a60d9 195$MAKE -j "$($NPROC)" V=1
7491c28d 196$MAKE install
72f4f0c1
MJ
197
198# Run tests
7491c28d 199$MAKE check
5fd8db76
MJ
200# Only run regtest for 0.9 and up
201if vergte "$PACKAGE_VERSION" "0.9"; then
72f4f0c1 202 $MAKE regtest
5fd8db76 203fi
72f4f0c1
MJ
204
205# Cleanup
7491c28d 206$MAKE clean
56162e2a 207
72f4f0c1
MJ
208# Cleanup rpath in executables and shared libraries
209#find $WORKSPACE/build/bin -type f -perm -0500 -exec chrpath --delete {} \;
0a6e708b 210find "$PREFIX/lib" -name "*.so" -exec chrpath --delete {} \;
72f4f0c1
MJ
211
212# Remove libtool .la files
0a6e708b 213find "$PREFIX/lib" -name "*.la" -exec rm -f {} \;
595a34c7 214
cdcf7df4 215# Cleanup temp directory of dist build
72f4f0c1 216if [ "$build" = "dist" ]; then
0a6e708b
MJ
217 cd "$SRCDIR"
218 rm -rf "$BUILD_PATH"
595a34c7 219fi
7491c28d
MJ
220
221# EOF
This page took 0.033832 seconds and 4 git commands to generate.