2016-01-13 19:33:33 -07:00
|
|
|
#!/usr/bin/env bash
|
2016-04-10 15:32:26 -06:00
|
|
|
# Copyright 2015 The Go Authors. All rights reserved.
|
2015-03-01 17:44:03 -07:00
|
|
|
# Use of this source code is governed by a BSD-style
|
|
|
|
# license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
# When run as (for example)
|
|
|
|
#
|
|
|
|
# GOOS=linux GOARCH=ppc64 bootstrap.bash
|
|
|
|
#
|
|
|
|
# this script cross-compiles a toolchain for that GOOS/GOARCH
|
|
|
|
# combination, leaving the resulting tree in ../../go-${GOOS}-${GOARCH}-bootstrap.
|
|
|
|
# That tree can be copied to a machine of the given target type
|
|
|
|
# and used as $GOROOT_BOOTSTRAP to bootstrap a local build.
|
|
|
|
#
|
|
|
|
# Only changes that have been committed to Git (at least locally,
|
|
|
|
# not necessary reviewed and submitted to master) are included in the tree.
|
2017-11-29 19:26:51 -07:00
|
|
|
#
|
2022-07-22 10:40:56 -06:00
|
|
|
# See also golang.org/x/build/cmd/genbootstrap, which is used
|
|
|
|
# to generate bootstrap tgz files for builders.
|
2015-03-01 17:44:03 -07:00
|
|
|
|
|
|
|
set -e
|
|
|
|
|
|
|
|
if [ "$GOOS" = "" -o "$GOARCH" = "" ]; then
|
2022-12-19 14:50:24 -07:00
|
|
|
echo "usage: GOOS=os GOARCH=arch ./bootstrap.bash [-force]" >&2
|
2015-03-01 17:44:03 -07:00
|
|
|
exit 2
|
|
|
|
fi
|
|
|
|
|
2022-12-19 14:50:24 -07:00
|
|
|
forceflag=""
|
|
|
|
if [ "$1" = "-force" ]; then
|
|
|
|
forceflag=-force
|
|
|
|
shift
|
|
|
|
fi
|
|
|
|
|
2015-03-01 17:44:03 -07:00
|
|
|
targ="../../go-${GOOS}-${GOARCH}-bootstrap"
|
|
|
|
if [ -e $targ ]; then
|
|
|
|
echo "$targ already exists; remove before continuing"
|
|
|
|
exit 2
|
|
|
|
fi
|
|
|
|
|
|
|
|
unset GOROOT
|
|
|
|
src=$(cd .. && pwd)
|
|
|
|
echo "#### Copying to $targ"
|
2019-04-27 07:16:36 -06:00
|
|
|
cp -Rp "$src" "$targ"
|
2015-03-01 17:44:03 -07:00
|
|
|
cd "$targ"
|
|
|
|
echo
|
|
|
|
echo "#### Cleaning $targ"
|
2019-04-19 10:48:36 -06:00
|
|
|
chmod -R +w .
|
2015-08-20 02:45:51 -06:00
|
|
|
rm -f .gitignore
|
|
|
|
if [ -e .git ]; then
|
|
|
|
git clean -f -d
|
|
|
|
fi
|
2015-03-01 17:44:03 -07:00
|
|
|
echo
|
|
|
|
echo "#### Building $targ"
|
|
|
|
echo
|
|
|
|
cd src
|
2022-12-19 14:50:24 -07:00
|
|
|
./make.bash --no-banner $forceflag
|
2015-03-01 17:44:03 -07:00
|
|
|
gohostos="$(../bin/go env GOHOSTOS)"
|
|
|
|
gohostarch="$(../bin/go env GOHOSTARCH)"
|
|
|
|
goos="$(../bin/go env GOOS)"
|
|
|
|
goarch="$(../bin/go env GOARCH)"
|
|
|
|
|
|
|
|
# NOTE: Cannot invoke go command after this point.
|
|
|
|
# We're about to delete all but the cross-compiled binaries.
|
|
|
|
cd ..
|
|
|
|
if [ "$goos" = "$gohostos" -a "$goarch" = "$gohostarch" ]; then
|
|
|
|
# cross-compile for local system. nothing to copy.
|
|
|
|
# useful if you've bootstrapped yourself but want to
|
|
|
|
# prepare a clean toolchain for others.
|
|
|
|
true
|
|
|
|
else
|
2019-04-12 06:20:21 -06:00
|
|
|
rm -f bin/go_${goos}_${goarch}_exec
|
2015-03-01 17:44:03 -07:00
|
|
|
mv bin/*_*/* bin
|
|
|
|
rmdir bin/*_*
|
|
|
|
rm -rf "pkg/${gohostos}_${gohostarch}" "pkg/tool/${gohostos}_${gohostarch}"
|
|
|
|
fi
|
2017-11-29 19:26:51 -07:00
|
|
|
|
2015-03-01 17:44:03 -07:00
|
|
|
rm -rf pkg/bootstrap pkg/obj .git
|
|
|
|
|
|
|
|
echo ----
|
|
|
|
echo Bootstrap toolchain for "$GOOS/$GOARCH" installed in "$(pwd)".
|
|
|
|
echo Building tbz.
|
|
|
|
cd ..
|
|
|
|
tar cf - "go-${GOOS}-${GOARCH}-bootstrap" | bzip2 -9 >"go-${GOOS}-${GOARCH}-bootstrap.tbz"
|
|
|
|
ls -l "$(pwd)/go-${GOOS}-${GOARCH}-bootstrap.tbz"
|
|
|
|
exit 0
|