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