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