Text file
src/bootstrap.bash
1 #!/usr/bin/env bash
2 # Copyright 2015 The Go Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style
4 # license that can be found in the LICENSE file.
5
6 # When run as (for example)
7 #
8 # GOOS=linux GOARCH=ppc64 bootstrap.bash
9 #
10 # this script cross-compiles a toolchain for that GOOS/GOARCH
11 # combination, leaving the resulting tree in ../../go-${GOOS}-${GOARCH}-bootstrap.
12 # That tree can be copied to a machine of the given target type
13 # and used as $GOROOT_BOOTSTRAP to bootstrap a local build.
14 #
15 # Only changes that have been committed to Git (at least locally,
16 # not necessary reviewed and submitted to master) are included in the tree.
17 #
18 # See also golang.org/x/build/cmd/genbootstrap, which is used
19 # to generate bootstrap tgz files for builders.
20
21 set -e
22
23 if [ "$GOOS" = "" -o "$GOARCH" = "" ]; then
24 echo "usage: GOOS=os GOARCH=arch ./bootstrap.bash" >&2
25 exit 2
26 fi
27
28 targ="../../go-${GOOS}-${GOARCH}-bootstrap"
29 if [ -e $targ ]; then
30 echo "$targ already exists; remove before continuing"
31 exit 2
32 fi
33
34 unset GOROOT
35 src=$(cd .. && pwd)
36 echo "#### Copying to $targ"
37 cp -Rp "$src" "$targ"
38 cd "$targ"
39 echo
40 echo "#### Cleaning $targ"
41 chmod -R +w .
42 rm -f .gitignore
43 if [ -e .git ]; then
44 git clean -f -d
45 fi
46 echo
47 echo "#### Building $targ"
48 echo
49 cd src
50 ./make.bash --no-banner
51 gohostos="$(../bin/go env GOHOSTOS)"
52 gohostarch="$(../bin/go env GOHOSTARCH)"
53 goos="$(../bin/go env GOOS)"
54 goarch="$(../bin/go env GOARCH)"
55
56 # NOTE: Cannot invoke go command after this point.
57 # We're about to delete all but the cross-compiled binaries.
58 cd ..
59 if [ "$goos" = "$gohostos" -a "$goarch" = "$gohostarch" ]; then
60 # cross-compile for local system. nothing to copy.
61 # useful if you've bootstrapped yourself but want to
62 # prepare a clean toolchain for others.
63 true
64 else
65 rm -f bin/go_${goos}_${goarch}_exec
66 mv bin/*_*/* bin
67 rmdir bin/*_*
68 rm -rf "pkg/${gohostos}_${gohostarch}" "pkg/tool/${gohostos}_${gohostarch}"
69 fi
70
71 rm -rf pkg/bootstrap pkg/obj .git
72
73 echo ----
74 echo Bootstrap toolchain for "$GOOS/$GOARCH" installed in "$(pwd)".
75 echo Building tbz.
76 cd ..
77 tar cf - "go-${GOOS}-${GOARCH}-bootstrap" | bzip2 -9 >"go-${GOOS}-${GOARCH}-bootstrap.tbz"
78 ls -l "$(pwd)/go-${GOOS}-${GOARCH}-bootstrap.tbz"
79 exit 0
80
View as plain text