-
Notifications
You must be signed in to change notification settings - Fork 5
/
build.sh
executable file
·254 lines (230 loc) · 6.02 KB
/
build.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
#!/bin/bash
# Copyright (c) 2018-2024 The Pastel Core developers
# Distributed under the MIT software license, see the accompanying
# file COPYING or https://www.opensource.org/licenses/mit-license.php.
#
# Usage:
# Linux: ./build.sh -j<job_count>
# MingW: HOST=x86_64-w64-mingw32 ./build.sh -j<job_count>
# macOS: HOST=x86_64-apple-darwin14 ./build.sh -j<job_count>
#
set -euo pipefail
JOBCOUNT=2
function cmd_pref()
{
if type -p "$2" > /dev/null; then
eval "$1=$2"
else
eval "$1=$3"
fi
}
# If a g-prefixed version of the command exists, use it preferentially.
function gprefix()
{
cmd_pref "$1" "g$2" "$2"
}
function show_usage()
{
cat <<EOF
Usage:
$0 --help
Show this help message and exit.
$0 [ --enable-lcov || --disable-tests ] [ --disable-mining ] [ --enable-proton ] [ --enable-compress ] [ --enable-debug ] [ --enable-pvs ] [ MAKEARGS... ]
Build Pastel and most of its transitive dependencies from
source. MAKEARGS are applied to both dependencies and Pastel itself.
If --enable-lcov is passed, Pastel is configured to add coverage
instrumentation, thus enabling "make cov" to work.
If --disable-tests is passed instead, the Pastel tests are not built.
If --disable-mining is passed, Pastel is configured to not build any mining
code. It must be passed after the test arguments, if present.
If --enable-proton is passed, Pastel is configured to build the Apache Qpid Proton
library required for AMQP support. This library is not built by default.
if --enable-compress is passed, Pastel is configured to compress ticket data with
zstd library. This is enabled by default.
if --enable-debug is passed, Pastel will be built with the debug options
if --enable-pvs is passed, PVS Studio static code analyzer will be used
EOF
}
OS=`uname | cut -f1 -d_`
# get number of cpus
#NCPUS=`nproc`
NCPUS=4
#JOBCOUNT=$NCPUS
gprefix READLINK readlink
BUILDDIR=`dirname $($READLINK -f $0)`
export BUILDDIR
cd $BUILDDIR
# Allow user overrides to $MAKE. Typical usage for users who need it:
# MAKE=gmake ./pcutil/build.sh -j$(nproc)
if test -z "${MAKE-}"; then
MAKE=make
fi
# Allow overrides to $BUILD and $HOST for porters. Most users will not need it.
# BUILD=i686-pc-linux-gnu ./build.sh
if test -z "${BUILD-}"; then
BUILD="$(./depends/config.guess)"
fi
if test -z "${HOST-}"; then
HOST="$BUILD"
fi
# Allow users to set arbitrary compile flags. Most users will not need this.
if test -z "${CONFIGURE_FLAGS-}"; then
CONFIGURE_FLAGS=""
fi
# enable ELF-hardening option by default
bHardening=1
# disable proton library by default
bProton=0
# verbose compiler output
bVerbose=1
# enable ticket compression by default
bCompress=1
# debug mode
bDebugMode=0
build_mode="release"
# enable/disable PVS
bUsePVS=0
if [[ "$HOST" == *darwin* ]]; then
bHardening=0
fi
# parse command-line parameters
PARAMS=
# positional arguments
POSARGS=
shopt -s extglob
while (( "$#" )); do
case "$1" in
--enable-lcov)
PARAMS+=" $1"
bHardening=0
shift
;;
--disable-tests)
PARAMS+=" --enable-tests=no"
shift
;;
--disable-mining)
PARAMS+=" --enable-mining=no"
shift
;;
--enable-proton)
bProton=1
PARAMS+=" $1"
shift
;;
--enable-compress)
bCompress=1
PARAMS+=" $1"
shift
;;
--enable-debug)
PARAMS+=" $1"
if [[ "$HOST" == *mingw32* ]]; then
PARAMS+=" CFLAGS=-g1"
else
PARAMS+=" CFLAGS=-ggdb"
# PARAMS+=" --enable-debug=yes"
fi
# POSARGS+=" DEBUG=1"
bDebugMode=1
build_mode="debug"
shift
;;
--enable-pvs)
bUsePVS=1
shift
;;
-j+([[:digit:]]))
JOBCOUNT=${1:2}
shift
;;
-j|--jobs)
if [ -n "${2-}" ] && [ ${2:0:1} != "-" ]; then
JOBCOUNT=$2
else
echo "Error: job count argument is missing" >&2
exit 1
fi
shift 2
;;
-h|--help)
show_usage
exit 0
;;
V=0)
bVerbose=0
shift
;;
V=1)
bVerbose=1
shift
;;
-*|--*=) # unsupported flags
echo "Error: unsupported option $1" >&2
exit 1
;;
*) # preserve positional arguments
POSARGS+=" $1"
shift
;;
esac
done
if (( $JOBCOUNT > $NCPUS )); then
echo "job count reduced to $NCPUS"
JOBCOUNT=$NCPUS
else
echo "job count: $JOBCOUNT"
fi
if (( $bHardening == 1 )); then
PARAMS+=" --enable-hardening"
else
PARAMS+=" --disable-hardening"
fi
if (( $bProton == 0 )); then
PARAMS+=" --enable-proton=no"
POSARGS+=" NO_PROTON=1"
fi
if (( $bCompress == 1 )); then
PARAMS+=" --enable-compress=yes"
fi
POSARGS+=" V=$bVerbose"
echo "=============== Pastel Core ${build_mode} BUILD ==(use [-h] for help, pid=$$)==========="
echo "OS: $OS"
set -x
eval "$MAKE" --version
as --version
ld -v
if (( $bUsePVS == 1 )); then
if ! command -v pvs-studio-analyzer &> /dev/null; then
echo "PVS Studio is not installed"
if command -v apt &> /dev/null
then
echo "Installing PVS Studio"
tmpInstallDir="$BUILDDIR/build-aux/tmp"
mkdir -p "$tmpInstallDir"
cd "$tmpInstallDir"
wget -q -O - https://files.viva64.com/etc/pubkey.txt | sudo apt-key add -
sudo wget -O /etc/apt/sources.list.d/viva64.list https://files.viva64.com/etc/viva64.list
sudo apt update
sudo apt install -y --no-install-recommends pvs-studio
cd "$BUILDDIR"
rm -rf "$tmpInstallDir"
fi
fi
echo "Using PVS Studio static code analyzer"
fi
echo PARAMS=$PARAMS; POSARGS=$POSARGS
# build Pastel dependent libraries in /depends folder
HOST="$HOST" BUILD="$BUILD" JOBCOUNT="$JOBCOUNT" \
"$MAKE" -C ./depends/ --jobs=$JOBCOUNT $POSARGS
# use autoconf to generate 'configure' script from configure.ac
./autogen.sh
# configure Pastel
CONFIG_SITE="$PWD/depends/$HOST/share/config.site" \
./configure $PARAMS $CONFIGURE_FLAGS
# build Pastel executables
if (( $bUsePVS == 1 )); then
pvs-studio-analyzer trace -- "$MAKE" --jobs=$JOBCOUNT $POSARGS
else
"$MAKE" --jobs=$JOBCOUNT $POSARGS
fi