jjb: build scripts cleanups
[lttng-ci.git] / scripts / babeltrace / build.sh
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 # Required parameters
20 arch=${arch:-}
21 conf=${conf:-}
22 build=${build:-}
23
24
25 SRCDIR="$WORKSPACE/src/babeltrace"
26 TMPDIR="$WORKSPACE/tmp"
27 PREFIX="$WORKSPACE/build"
28
29 # Create build and tmp directories
30 rm -rf "$PREFIX" "$TMPDIR"
31 mkdir -p "$PREFIX" "$TMPDIR"
32
33 export TMPDIR
34
35 # Set platform variables
36 case "$arch" in
37 solaris10)
38 MAKE=gmake
39 TAR=gtar
40 NPROC=gnproc
41 BISON=bison
42 YACC="$BISON -y"
43 ;;
44 solaris11)
45 MAKE=gmake
46 TAR=gtar
47 NPROC=nproc
48 BISON="/opt/csw/bin/bison"
49 YACC="$BISON -y"
50 export PATH="$PATH:/usr/perl5/bin"
51 ;;
52 macosx)
53 MAKE=make
54 TAR=tar
55 NPROC="getconf _NPROCESSORS_ONLN"
56 BISON="bison"
57 YACC="$BISON -y"
58 export PATH="/opt/local/bin:/opt/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"
59 export CFLAGS="-I/opt/local/include"
60 export LDFLAGS="-L/opt/local/lib"
61 ;;
62 *)
63 MAKE=make
64 TAR=tar
65 NPROC=nproc
66 BISON=bison
67 YACC="$BISON -y"
68 ;;
69 esac
70
71 # Set configure options for each build configuration
72 CONF_OPTS=""
73 case "$conf" in
74 static)
75 echo "Static build"
76 CONF_OPTS="--enable-static --disable-shared"
77 ;;
78 python-bindings)
79 echo "Build with python bindings"
80 # We only support bindings built with Python 3
81 export PYTHON="python3"
82 export PYTHON_CONFIG="/usr/bin/python3-config"
83 CONF_OPTS="--enable-python-bindings"
84 ;;
85 *)
86 echo "Standard build"
87 CONF_OPTS=""
88 ;;
89 esac
90
91 # Enter the source directory
92 cd "$SRCDIR"
93
94 # Run bootstrap in the source directory prior to configure
95 ./bootstrap
96
97
98 # Build type
99 # oot : out-of-tree build
100 # dist: build via make dist
101 # * : normal tree build
102 #
103 # Make sure to move to the build_path and configure
104 # before continuing
105 BUILD_PATH="$SRCDIR"
106 case "$build" in
107 oot)
108 echo "Out of tree build"
109 BUILD_PATH="$WORKSPACE/oot"
110 mkdir -p "$BUILD_PATH"
111 cd "$BUILD_PATH"
112 MAKE=$MAKE BISON="$BISON" YACC="$YACC" "$SRCDIR/configure" --prefix="$PREFIX" $CONF_OPTS
113 ;;
114
115 dist)
116 echo "Distribution out of tree build"
117 BUILD_PATH="$(mktemp -d)"
118
119 # Initial configure and generate tarball
120 MAKE=$MAKE BISON="$BISON" YACC="$YACC" "$SRCDIR/configure"
121 $MAKE dist
122
123 mkdir -p "$BUILD_PATH"
124 cp ./*.tar.* "$BUILD_PATH/"
125 cd "$BUILD_PATH"
126
127 # Ignore level 1 of tar
128 $TAR xvf ./*.tar.* --strip 1
129
130 MAKE=$MAKE BISON="$BISON" YACC="$YACC" "$BUILD_PATH/configure" --prefix="$PREFIX" $CONF_OPTS
131 ;;
132
133 clang)
134 echo "LLVM clang build"
135 export CC=clang
136 clang -v
137 MAKE=$MAKE BISON="$BISON" YACC="$YACC" "$SRCDIR/configure" --prefix="$PREFIX" $CONF_OPTS
138 ;;
139 *)
140 echo "Standard in-tree build"
141 MAKE=$MAKE BISON="$BISON" YACC="$YACC" "$SRCDIR/configure" --prefix="$PREFIX" $CONF_OPTS
142 ;;
143 esac
144
145 # BUILD!
146 $MAKE -j "$($NPROC)" V=1
147 $MAKE install
148
149 # Run tests
150 $MAKE check
151
152 # Copy tap logs for the jenkins tap parser
153 rsync -a --exclude 'test-suite.log' --include '*/' --include '*.log' --exclude='*' tests/ "$WORKSPACE/tap"
154
155 # Clean the build directory
156 $MAKE clean
157
158 # Cleanup rpath in executables and shared libraries
159 find "$PREFIX/bin" -type f -perm -0500 -exec chrpath --delete {} \;
160 find "$PREFIX/lib" -name "*.so" -exec chrpath --delete {} \;
161
162 # Remove libtool .la files
163 find "$PREFIX/lib" -name "*.la" -exec rm -f {} \;
164
165 # Clean temp dir for dist build
166 if [ "$build" = "dist" ]; then
167 cd "$SRCDIR"
168 rm -rf "$BUILD_PATH"
169 fi
170
171 # EOF
This page took 0.033803 seconds and 5 git commands to generate.