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