blob: 1b5ba7c536cd63b3fba0763cbb973c3bf1ecc414 [file] [log] [blame]
Russ Coxdeff22d2015-03-01 19:44:03 -05001#!/bin/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
18set -e
19
20if [ "$GOOS" = "" -o "$GOARCH" = "" ]; then
21 echo "usage: GOOS=os GOARCH=arch ./bootstrap.bash" >&2
22 exit 2
23fi
24
25targ="../../go-${GOOS}-${GOARCH}-bootstrap"
26if [ -e $targ ]; then
27 echo "$targ already exists; remove before continuing"
28 exit 2
29fi
30
31unset GOROOT
32src=$(cd .. && pwd)
33echo "#### Copying to $targ"
34cp -R "$src" "$targ"
35cd "$targ"
36echo
37echo "#### Cleaning $targ"
Fabian Wickborn1ac84d42015-08-20 10:45:51 +020038rm -f .gitignore
39if [ -e .git ]; then
40 git clean -f -d
41fi
Russ Coxdeff22d2015-03-01 19:44:03 -050042echo
43echo "#### Building $targ"
44echo
45cd src
46./make.bash --no-banner
47gohostos="$(../bin/go env GOHOSTOS)"
48gohostarch="$(../bin/go env GOHOSTARCH)"
49goos="$(../bin/go env GOOS)"
50goarch="$(../bin/go env GOARCH)"
51
52# NOTE: Cannot invoke go command after this point.
53# We're about to delete all but the cross-compiled binaries.
54cd ..
55if [ "$goos" = "$gohostos" -a "$goarch" = "$gohostarch" ]; then
56 # cross-compile for local system. nothing to copy.
57 # useful if you've bootstrapped yourself but want to
58 # prepare a clean toolchain for others.
59 true
60else
61 mv bin/*_*/* bin
62 rmdir bin/*_*
63 rm -rf "pkg/${gohostos}_${gohostarch}" "pkg/tool/${gohostos}_${gohostarch}"
64fi
65rm -rf pkg/bootstrap pkg/obj .git
66
67echo ----
68echo Bootstrap toolchain for "$GOOS/$GOARCH" installed in "$(pwd)".
69echo Building tbz.
70cd ..
71tar cf - "go-${GOOS}-${GOARCH}-bootstrap" | bzip2 -9 >"go-${GOOS}-${GOARCH}-bootstrap.tbz"
72ls -l "$(pwd)/go-${GOOS}-${GOARCH}-bootstrap.tbz"
73exit 0