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