[Docs] Update Windows build instructions for using WSL and Ubuntu 17.04
[bitcoinplatinum.git] / contrib / gitian-build.sh
blob8fdec21b0e88f19b380480e5341656828c1f998b
1 # Copyright (c) 2016 The Bitcoin Core developers
2 # Distributed under the MIT software license, see the accompanying
3 # file COPYING or http://www.opensource.org/licenses/mit-license.php.
5 # What to do
6 sign=false
7 verify=false
8 build=false
9 setupenv=false
11 # Systems to build
12 linux=true
13 windows=true
14 osx=true
16 # Other Basic variables
17 SIGNER=
18 VERSION=
19 commit=false
20 url=https://github.com/bitcoin/bitcoin
21 proc=2
22 mem=2000
23 lxc=true
24 osslTarUrl=http://downloads.sourceforge.net/project/osslsigncode/osslsigncode/osslsigncode-1.7.1.tar.gz
25 osslPatchUrl=https://bitcoincore.org/cfields/osslsigncode-Backports-to-1.7.1.patch
26 scriptName=$(basename -- "$0")
27 signProg="gpg --detach-sign"
28 commitFiles=true
30 # Help Message
31 read -d '' usage <<- EOF
32 Usage: $scriptName [-c|u|v|b|s|B|o|h|j|m|] signer version
34 Run this script from the directory containing the bitcoin, gitian-builder, gitian.sigs, and bitcoin-detached-sigs.
36 Arguments:
37 signer GPG signer to sign each build assert file
38 version Version number, commit, or branch to build. If building a commit or branch, the -c option must be specified
40 Options:
41 -c|--commit Indicate that the version argument is for a commit or branch
42 -u|--url Specify the URL of the repository. Default is https://github.com/bitcoin/bitcoin
43 -v|--verify Verify the Gitian build
44 -b|--build Do a Gitian build
45 -s|--sign Make signed binaries for Windows and Mac OSX
46 -B|--buildsign Build both signed and unsigned binaries
47 -o|--os Specify which Operating Systems the build is for. Default is lwx. l for linux, w for windows, x for osx
48 -j Number of processes to use. Default 2
49 -m Memory to allocate in MiB. Default 2000
50 --kvm Use KVM instead of LXC
51 --setup Set up the Gitian building environment. Uses KVM. If you want to use lxc, use the --lxc option. Only works on Debian-based systems (Ubuntu, Debian)
52 --detach-sign Create the assert file for detached signing. Will not commit anything.
53 --no-commit Do not commit anything to git
54 -h|--help Print this help message
55 EOF
57 # Get options and arguments
58 while :; do
59 case $1 in
60 # Verify
61 -v|--verify)
62 verify=true
64 # Build
65 -b|--build)
66 build=true
68 # Sign binaries
69 -s|--sign)
70 sign=true
72 # Build then Sign
73 -B|--buildsign)
74 sign=true
75 build=true
77 # PGP Signer
78 -S|--signer)
79 if [ -n "$2" ]
80 then
81 SIGNER=$2
82 shift
83 else
84 echo 'Error: "--signer" requires a non-empty argument.'
85 exit 1
88 # Operating Systems
89 -o|--os)
90 if [ -n "$2" ]
91 then
92 linux=false
93 windows=false
94 osx=false
95 if [[ "$2" = *"l"* ]]
96 then
97 linux=true
99 if [[ "$2" = *"w"* ]]
100 then
101 windows=true
103 if [[ "$2" = *"x"* ]]
104 then
105 osx=true
107 shift
108 else
109 echo 'Error: "--os" requires an argument containing an l (for linux), w (for windows), or x (for Mac OSX)\n'
110 exit 1
113 # Help message
114 -h|--help)
115 echo "$usage"
116 exit 0
118 # Commit or branch
119 -c|--commit)
120 commit=true
122 # Number of Processes
124 if [ -n "$2" ]
125 then
126 proc=$2
127 shift
128 else
129 echo 'Error: "-j" requires an argument'
130 exit 1
133 # Memory to allocate
135 if [ -n "$2" ]
136 then
137 mem=$2
138 shift
139 else
140 echo 'Error: "-m" requires an argument'
141 exit 1
144 # URL
146 if [ -n "$2" ]
147 then
148 url=$2
149 shift
150 else
151 echo 'Error: "-u" requires an argument'
152 exit 1
155 # kvm
156 --kvm)
157 lxc=false
159 # Detach sign
160 --detach-sign)
161 signProg="true"
162 commitFiles=false
164 # Commit files
165 --no-commit)
166 commitFiles=false
168 # Setup
169 --setup)
170 setup=true
172 *) # Default case: If no more options then break out of the loop.
173 break
174 esac
175 shift
176 done
178 # Set up LXC
179 if [[ $lxc = true ]]
180 then
181 export USE_LXC=1
184 # Check for OSX SDK
185 if [[ ! -e "gitian-builder/inputs/MacOSX10.11.sdk.tar.gz" && $osx == true ]]
186 then
187 echo "Cannot build for OSX, SDK does not exist. Will build for other OSes"
188 osx=false
191 # Get signer
192 if [[ -n"$1" ]]
193 then
194 SIGNER=$1
195 shift
198 # Get version
199 if [[ -n "$1" ]]
200 then
201 VERSION=$1
202 COMMIT=$VERSION
203 shift
206 # Check that a signer is specified
207 if [[ $SIGNER == "" ]]
208 then
209 echo "$scriptName: Missing signer."
210 echo "Try $scriptName --help for more information"
211 exit 1
214 # Check that a version is specified
215 if [[ $VERSION == "" ]]
216 then
217 echo "$scriptName: Missing version."
218 echo "Try $scriptName --help for more information"
219 exit 1
222 # Add a "v" if no -c
223 if [[ $commit = false ]]
224 then
225 COMMIT="v${VERSION}"
227 echo ${COMMIT}
229 # Setup build environment
230 if [[ $setup = true ]]
231 then
232 sudo apt-get install ruby apache2 git apt-cacher-ng python-vm-builder qemu-kvm qemu-utils
233 git clone https://github.com/bitcoin-core/gitian.sigs.git
234 git clone https://github.com/bitcoin-core/bitcoin-detached-sigs.git
235 git clone https://github.com/devrandom/gitian-builder.git
236 pushd ./gitian-builder
237 if [[ -n "$USE_LXC" ]]
238 then
239 sudo apt-get install lxc
240 bin/make-base-vm --suite trusty --arch amd64 --lxc
241 else
242 bin/make-base-vm --suite trusty --arch amd64
244 popd
247 # Set up build
248 pushd ./bitcoin
249 git fetch
250 git checkout ${COMMIT}
251 popd
253 # Build
254 if [[ $build = true ]]
255 then
256 # Make output folder
257 mkdir -p ./bitcoin-binaries/${VERSION}
259 # Build Dependencies
260 echo ""
261 echo "Building Dependencies"
262 echo ""
263 pushd ./gitian-builder
264 mkdir -p inputs
265 wget -N -P inputs $osslPatchUrl
266 wget -N -P inputs $osslTarUrl
267 make -C ../bitcoin/depends download SOURCES_PATH=`pwd`/cache/common
269 # Linux
270 if [[ $linux = true ]]
271 then
272 echo ""
273 echo "Compiling ${VERSION} Linux"
274 echo ""
275 ./bin/gbuild -j ${proc} -m ${mem} --commit bitcoin=${COMMIT} --url bitcoin=${url} ../bitcoin/contrib/gitian-descriptors/gitian-linux.yml
276 ./bin/gsign -p $signProg --signer $SIGNER --release ${VERSION}-linux --destination ../gitian.sigs/ ../bitcoin/contrib/gitian-descriptors/gitian-linux.yml
277 mv build/out/bitcoin-*.tar.gz build/out/src/bitcoin-*.tar.gz ../bitcoin-binaries/${VERSION}
279 # Windows
280 if [[ $windows = true ]]
281 then
282 echo ""
283 echo "Compiling ${VERSION} Windows"
284 echo ""
285 ./bin/gbuild -j ${proc} -m ${mem} --commit bitcoin=${COMMIT} --url bitcoin=${url} ../bitcoin/contrib/gitian-descriptors/gitian-win.yml
286 ./bin/gsign -p $signProg --signer $SIGNER --release ${VERSION}-win-unsigned --destination ../gitian.sigs/ ../bitcoin/contrib/gitian-descriptors/gitian-win.yml
287 mv build/out/bitcoin-*-win-unsigned.tar.gz inputs/bitcoin-win-unsigned.tar.gz
288 mv build/out/bitcoin-*.zip build/out/bitcoin-*.exe ../bitcoin-binaries/${VERSION}
290 # Mac OSX
291 if [[ $osx = true ]]
292 then
293 echo ""
294 echo "Compiling ${VERSION} Mac OSX"
295 echo ""
296 ./bin/gbuild -j ${proc} -m ${mem} --commit bitcoin=${COMMIT} --url bitcoin=${url} ../bitcoin/contrib/gitian-descriptors/gitian-osx.yml
297 ./bin/gsign -p $signProg --signer $SIGNER --release ${VERSION}-osx-unsigned --destination ../gitian.sigs/ ../bitcoin/contrib/gitian-descriptors/gitian-osx.yml
298 mv build/out/bitcoin-*-osx-unsigned.tar.gz inputs/bitcoin-osx-unsigned.tar.gz
299 mv build/out/bitcoin-*.tar.gz build/out/bitcoin-*.dmg ../bitcoin-binaries/${VERSION}
301 popd
303 if [[ $commitFiles = true ]]
304 then
305 # Commit to gitian.sigs repo
306 echo ""
307 echo "Committing ${VERSION} Unsigned Sigs"
308 echo ""
309 pushd gitian.sigs
310 git add ${VERSION}-linux/${SIGNER}
311 git add ${VERSION}-win-unsigned/${SIGNER}
312 git add ${VERSION}-osx-unsigned/${SIGNER}
313 git commit -a -m "Add ${VERSION} unsigned sigs for ${SIGNER}"
314 popd
318 # Verify the build
319 if [[ $verify = true ]]
320 then
321 # Linux
322 pushd ./gitian-builder
323 echo ""
324 echo "Verifying v${VERSION} Linux"
325 echo ""
326 ./bin/gverify -v -d ../gitian.sigs/ -r ${VERSION}-linux ../bitcoin/contrib/gitian-descriptors/gitian-linux.yml
327 # Windows
328 echo ""
329 echo "Verifying v${VERSION} Windows"
330 echo ""
331 ./bin/gverify -v -d ../gitian.sigs/ -r ${VERSION}-win-unsigned ../bitcoin/contrib/gitian-descriptors/gitian-win.yml
332 # Mac OSX
333 echo ""
334 echo "Verifying v${VERSION} Mac OSX"
335 echo ""
336 ./bin/gverify -v -d ../gitian.sigs/ -r ${VERSION}-osx-unsigned ../bitcoin/contrib/gitian-descriptors/gitian-osx.yml
337 # Signed Windows
338 echo ""
339 echo "Verifying v${VERSION} Signed Windows"
340 echo ""
341 ./bin/gverify -v -d ../gitian.sigs/ -r ${VERSION}-osx-signed ../bitcoin/contrib/gitian-descriptors/gitian-osx-signer.yml
342 # Signed Mac OSX
343 echo ""
344 echo "Verifying v${VERSION} Signed Mac OSX"
345 echo ""
346 ./bin/gverify -v -d ../gitian.sigs/ -r ${VERSION}-osx-signed ../bitcoin/contrib/gitian-descriptors/gitian-osx-signer.yml
347 popd
350 # Sign binaries
351 if [[ $sign = true ]]
352 then
354 pushd ./gitian-builder
355 # Sign Windows
356 if [[ $windows = true ]]
357 then
358 echo ""
359 echo "Signing ${VERSION} Windows"
360 echo ""
361 ./bin/gbuild -i --commit signature=${COMMIT} ../bitcoin/contrib/gitian-descriptors/gitian-win-signer.yml
362 ./bin/gsign -p $signProg --signer $SIGNER --release ${VERSION}-win-signed --destination ../gitian.sigs/ ../bitcoin/contrib/gitian-descriptors/gitian-win-signer.yml
363 mv build/out/bitcoin-*win64-setup.exe ../bitcoin-binaries/${VERSION}
364 mv build/out/bitcoin-*win32-setup.exe ../bitcoin-binaries/${VERSION}
366 # Sign Mac OSX
367 if [[ $osx = true ]]
368 then
369 echo ""
370 echo "Signing ${VERSION} Mac OSX"
371 echo ""
372 ./bin/gbuild -i --commit signature=${COMMIT} ../bitcoin/contrib/gitian-descriptors/gitian-osx-signer.yml
373 ./bin/gsign -p $signProg --signer $SIGNER --release ${VERSION}-osx-signed --destination ../gitian.sigs/ ../bitcoin/contrib/gitian-descriptors/gitian-osx-signer.yml
374 mv build/out/bitcoin-osx-signed.dmg ../bitcoin-binaries/${VERSION}/bitcoin-${VERSION}-osx.dmg
376 popd
378 if [[ $commitFiles = true ]]
379 then
380 # Commit Sigs
381 pushd gitian.sigs
382 echo ""
383 echo "Committing ${VERSION} Signed Sigs"
384 echo ""
385 git add ${VERSION}-win-signed/${SIGNER}
386 git add ${VERSION}-osx-signed/${SIGNER}
387 git commit -a -m "Add ${VERSION} signed binary sigs for ${SIGNER}"
388 popd