-
Notifications
You must be signed in to change notification settings - Fork 5
/
prepare_deps
executable file
·222 lines (212 loc) · 6.71 KB
/
prepare_deps
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
#!/usr/bin/env bash
# Prerequisites:
# - GNU Bash (at least v3.1 for the '+=' string-concatenation operator).
# - Latest GCC ('gcc' and 'g++') available in PATH.
# - Environment variables:
# - BOOST_DIR: Absolute or relative directory to Boost repo clone.
# - GTEST_DIR: Absolute or relative directory to Google Test repo clone.
# - HUNSPELL_DIR: Absolute or relative directory to Hunspell repo clone.
# - CRYPTOPP_DIR: Absolute or relative directory to Crypto++ repo clone.
# - OPENSSL_DIR: Absolute or relative directory to OpenSSL repo clone.
# - GNU_MAKE: Executable name of GNU Make (at least v4.2.1).
# - BAZEL: Executable name of Bazel. (Set to "true" for Makefile workaround.)
# - GIT: Executable name of Git (relatively modern version with submodules).
# - AR: Executable name of GCC's 'ar' tool. (Unnecessary on macOS.)
# - RANLIB: Executable name of GCC's 'ranlib' tool. (Unnecessary on macOS.)
# - CLEAN_BUILD: (Optional) Clean up existing build artifacts before building.
export BOOST_DIR=${BOOST_DIR:-boost}
export GTEST_DIR=${GTEST_DIR:-googletest}
export HUNSPELL_DIR=${HUNSPELL_DIR:-hunspell}
export CRYPTOPP_DIR=${CRYPTOPP_DIR:-cryptopp}
export OPENSSL_DIR=${OPENSSL_DIR:-openssl}
export GNU_MAKE=${GNU_MAKE:-make}
export BAZEL=${BAZEL:-true}
export GIT=${GIT:-git}
if [[ $(uname) != "Darwin" && $(uname -o) != "Android" ]]
then
export AR=${AR:-gcc-ar}
export RANLIB=${RANLIB:-gcc-ranlib}
fi
function checkout {
local repoURL="$1"
local dir="$2"
local branch="$3"
local testFiles="$4"
shift 4
# The Travis Cache plugin creates the directories beforehand, so we can't
# use [[ ! -d $dir ]] here
if echo -e "$testFiles" | xargs -t -n1 -I% [ ! -f "$dir"/% ]
then
$GIT clone --depth 1 --shallow-submodules --no-tags $repoURL "$dir"
pushd "$dir"
else
pushd "$dir"
if [[ -n "$CLEAN_BUILD" ]]
then
$GIT clean --force -Xd
$GIT checkout --force "$branch"
fi
$GIT pull --prune
fi
$GIT submodule update --init --recursive --depth 1 -- $@
}
function build_boost {
checkout https://github.com/boostorg/boost.git \
"$BOOST_DIR" \
master \
bootstrap.sh \
tools/build libs/config tools/boost_install libs/headers \
libs/algorithm \
libs/align \
libs/asio \
libs/assert \
libs/beast \
libs/bind \
libs/concept_check \
libs/container_hash \
libs/core \
libs/date_time \
libs/describe \
libs/detail \
libs/endian \
libs/function \
libs/integer \
libs/intrusive \
libs/io \
libs/iostreams \
libs/iterator \
libs/move \
libs/mp11 \
libs/mpl \
libs/numeric \
libs/optional \
libs/predef \
libs/preprocessor \
libs/range \
libs/scope_exit \
libs/smart_ptr \
libs/static_assert \
libs/static_string \
libs/system \
libs/throw_exception \
libs/type_index \
libs/typeof \
libs/type_traits \
libs/utility \
libs/winapi
./bootstrap.sh --with-toolset=gcc
./b2 headers
./b2 --layout=system toolset=gcc variant=release address-model=64 -j 2 \
--with-system
}
function build_gtest {
checkout https://github.com/google/googletest.git \
"$GTEST_DIR" \
main \
"BUILD.bazel\nWORKSPACE"
if [[ $BAZEL != "true" ]]
then
compiler_override="--incompatible_enable_cc_toolchain_resolution=false"
system_name=$(uname -s)
if [[ $system_name =~ ^MINGW ]]; then
compiler_override+=" --compiler=mingw-gcc"
elif [[ $system_name =~ ^MSYS_ ]]; then
compiler_override+=" --compiler=msys-gcc"
fi
compiler_override+=" --cxxopt=-std=c++14"
$BAZEL --batch build $compiler_override gtest gtest_main
else
git fetch --shallow-since=2019-06-12 || git fetch --unshallow || true
git checkout 6b8c138154~1 -- googletest/make
pushd googletest/make
echo -e '*.o\n*.a\nsample1_unittest' > .gitignore
$GNU_MAKE -kj 2 CXXFLAGS="-g -Wall -Wextra -pthread -std=c++14"
popd
[[ -d bazel-bin ]] || mkdir bazel-bin
pushd bazel-bin
ln -fs ../googletest/make/*.a .
fi
}
function build_hunspell {
checkout https://github.com/hunspell/hunspell.git \
"$HUNSPELL_DIR" \
master \
configure.ac
if [[ -n "$CLEAN_BUILD" ]]
then
rm -f config.cache
fi
if [[ -z `command -v autopoint` &&
`uname` == Linux && `uname -o` != Android &&
`lsb_release -s -i` == Ubuntu ]]
then
sudo apt install -y autopoint
fi
export LDFLAGS=-L/usr/local/opt/gettext/lib
export CPPFLAGS=-I/usr/local/opt/gettext/include
autoreconf -vfi
./configure --config-cache --disable-dependency-tracking
$GNU_MAKE -kj 2
}
function build_cryptopp {
checkout https://github.com/weidai11/cryptopp.git \
"$CRYPTOPP_DIR" \
master \
GNUmakefile
if [[ `uname -o` == Android ]]
then
pkg install libcpufeatures
export CRYPTOPP_CPPFLAGS=-I/data/data/com.termux/files/usr/include/ndk_compat
export CRYPTOPP_LDFLAGS=-lndk_compat
fi
$GNU_MAKE deps
$GNU_MAKE -kj 3
}
function build_openssl {
if [[ -n "$CLEAN_BUILD" ]]
then
pushd "$OPENSSL_DIR"
$GIT config core.eol lf
$GIT config core.autocrlf false
popd
fi
local optsAndURL="--config core.eol=lf --config core.autocrlf=false"
optsAndURL+=" https://github.com/openssl/openssl.git"
checkout "$optsAndURL" "$OPENSSL_DIR" master config
CC=gcc CXX=g++ ./config --prefix=$(pwd) no-async enable-makedepend
$GNU_MAKE update -kj 4
$GNU_MAKE -kj 4
# https://github.com/openssl/openssl/issues/14994#issuecomment-825872628
$GNU_MAKE -kj 4
$GNU_MAKE -kj 4
[[ -d lib ]] || mkdir lib
pushd lib
ln -fs ../libssl.* ../libcrypto.* .
}
function download_scowl_for_hunspell {
url='https://downloads.sourceforge.net/project/wordlist/speller/2017.01.22/'
file='hunspell-en_US-2017.01.22.zip'
wget "$url$file" -O $file || curl -L -o $file "$url$file"
unzip -o -d $HUNSPELL_DIR $file
rm $file
}
set -xe
if [[ $(uname -o) != "Android" ]]
then
git config fetch.parallel 0
git config submodule.fetchJobs 0
fi
build_boost &
build_gtest &
build_hunspell &
build_cryptopp &
build_openssl &
download_scowl_for_hunspell &
while sleep 300
do
echo "Dummy output to prevent termination"
done &
dummy_pid=$(jobs -p %%)
disown
wait
kill $dummy_pid