2009-11-14 16:29:09 -07:00
|
|
|
#!/usr/bin/env bash
|
2008-06-11 14:34:08 -06:00
|
|
|
# Copyright 2009 The Go Authors. All rights reserved.
|
|
|
|
# Use of this source code is governed by a BSD-style
|
|
|
|
# license that can be found in the LICENSE file.
|
|
|
|
|
2015-01-07 09:38:00 -07:00
|
|
|
# See golang.org/s/go15bootstrap for an overview of the build process.
|
|
|
|
|
2012-03-01 10:12:22 -07:00
|
|
|
# Environment variables that control make.bash:
|
|
|
|
#
|
|
|
|
# GOROOT_FINAL: The expected final Go root, baked into binaries.
|
|
|
|
# The default is the location of the Go tree during the build.
|
|
|
|
#
|
|
|
|
# GOHOSTARCH: The architecture for host tools (compilers and
|
|
|
|
# binaries). Binaries of this type must be executable on the current
|
|
|
|
# system, so the only common reason to set this is to set
|
|
|
|
# GOHOSTARCH=386 on an amd64 machine.
|
|
|
|
#
|
|
|
|
# GOARCH: The target architecture for installed packages and tools.
|
|
|
|
#
|
|
|
|
# GOOS: The target operating system for installed packages and tools.
|
|
|
|
#
|
2015-05-28 01:13:23 -06:00
|
|
|
# GO_GCFLAGS: Additional go tool compile arguments to use when
|
2012-03-01 10:12:22 -07:00
|
|
|
# building the packages and commands.
|
|
|
|
#
|
2015-05-28 01:13:23 -06:00
|
|
|
# GO_LDFLAGS: Additional go tool link arguments to use when
|
2012-03-12 19:52:15 -06:00
|
|
|
# building the commands.
|
2012-03-01 10:12:22 -07:00
|
|
|
#
|
2012-03-19 21:04:20 -06:00
|
|
|
# CGO_ENABLED: Controls cgo usage during the build. Set it to 1
|
|
|
|
# to include all cgo related files, .c and .go file with "cgo"
|
|
|
|
# build directive, in the build. Set it to 0 to ignore them.
|
2013-02-15 14:37:43 -07:00
|
|
|
#
|
2013-03-29 17:33:35 -06:00
|
|
|
# GO_EXTLINK_ENABLED: Set to 1 to invoke the host linker when building
|
|
|
|
# packages that use cgo. Set to 0 to do all linking internally. This
|
|
|
|
# controls the default behavior of the linker's -linkmode option. The
|
|
|
|
# default value depends on the system.
|
|
|
|
#
|
2019-02-25 03:32:00 -07:00
|
|
|
# GO_LDSO: Sets the default dynamic linker/loader (ld.so) to be used
|
|
|
|
# by the internal linker.
|
|
|
|
#
|
2014-02-06 10:11:00 -07:00
|
|
|
# CC: Command line to run to compile C code for GOHOSTARCH.
|
2013-02-15 14:37:43 -07:00
|
|
|
# Default is "gcc". Also supported: "clang".
|
2014-02-06 10:11:00 -07:00
|
|
|
#
|
|
|
|
# CC_FOR_TARGET: Command line to run to compile C code for GOARCH.
|
|
|
|
# This is used by cgo. Default is CC.
|
|
|
|
#
|
|
|
|
# CXX_FOR_TARGET: Command line to run to compile C++ code for GOARCH.
|
2018-05-04 02:55:11 -06:00
|
|
|
# This is used by cgo. Default is CXX, or, if that is not set,
|
2014-02-06 10:11:00 -07:00
|
|
|
# "g++" or "clang++".
|
2013-10-01 21:44:20 -06:00
|
|
|
#
|
2016-02-18 03:49:03 -07:00
|
|
|
# FC: Command line to run to compile Fortran code for GOARCH.
|
|
|
|
# This is used by cgo. Default is "gfortran".
|
|
|
|
#
|
2016-06-25 05:51:06 -06:00
|
|
|
# PKG_CONFIG: Path to pkg-config tool. Default is "pkg-config".
|
|
|
|
#
|
2015-12-17 15:01:17 -07:00
|
|
|
# GO_DISTFLAGS: extra flags to provide to "dist bootstrap".
|
2017-10-23 19:57:54 -06:00
|
|
|
# (Or just pass them to the make.bash command line.)
|
2017-10-27 11:07:38 -06:00
|
|
|
#
|
|
|
|
# GOBUILDTIMELOGFILE: If set, make.bash and all.bash write
|
|
|
|
# timing information to this file. Useful for profiling where the
|
|
|
|
# time goes when these scripts run.
|
2017-10-31 23:05:48 -06:00
|
|
|
#
|
|
|
|
# GOROOT_BOOTSTRAP: A working Go tree >= Go 1.4 for bootstrap.
|
|
|
|
# If $GOROOT_BOOTSTRAP/bin/go is missing, $(go env GOROOT) is
|
|
|
|
# tried for all "go" in $PATH. $HOME/go1.4 by default.
|
2012-03-01 10:12:22 -07:00
|
|
|
|
2008-09-18 16:06:43 -06:00
|
|
|
set -e
|
2016-05-19 11:43:04 -06:00
|
|
|
|
|
|
|
unset GOBIN # Issue 14340
|
2018-07-28 23:10:02 -06:00
|
|
|
unset GOFLAGS
|
2018-11-16 10:47:33 -07:00
|
|
|
unset GO111MODULE
|
2016-05-19 11:43:04 -06:00
|
|
|
|
2012-02-03 22:54:08 -07:00
|
|
|
if [ ! -f run.bash ]; then
|
2010-08-18 08:08:49 -06:00
|
|
|
echo 'make.bash must be run from $GOROOT/src' 1>&2
|
|
|
|
exit 1
|
|
|
|
fi
|
2009-12-11 16:14:09 -07:00
|
|
|
|
2017-10-27 11:07:38 -06:00
|
|
|
if [ "$GOBUILDTIMELOGFILE" != "" ]; then
|
2017-11-02 03:22:19 -06:00
|
|
|
echo $(LC_TIME=C date) start make.bash >"$GOBUILDTIMELOGFILE"
|
2017-10-27 11:07:38 -06:00
|
|
|
fi
|
|
|
|
|
2012-02-12 21:14:37 -07:00
|
|
|
# Test for Windows.
|
|
|
|
case "$(uname)" in
|
|
|
|
*MINGW* | *WIN32* | *CYGWIN*)
|
|
|
|
echo 'ERROR: Do not use make.bash to build on Windows.'
|
|
|
|
echo 'Use make.bat instead.'
|
|
|
|
echo
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2012-02-03 22:54:08 -07:00
|
|
|
# Test for bad ld.
|
2011-10-13 10:25:25 -06:00
|
|
|
if ld --version 2>&1 | grep 'gold.* 2\.20' >/dev/null; then
|
2011-03-18 16:23:00 -06:00
|
|
|
echo 'ERROR: Your system has gold 2.20 installed.'
|
|
|
|
echo 'This version is shipped by Ubuntu even though'
|
|
|
|
echo 'it is known not to work on Ubuntu.'
|
|
|
|
echo 'Binaries built with this linker are likely to fail in mysterious ways.'
|
|
|
|
echo
|
|
|
|
echo 'Run sudo apt-get remove binutils-gold.'
|
|
|
|
echo
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2012-02-03 22:54:08 -07:00
|
|
|
# Test for bad SELinux.
|
|
|
|
# On Fedora 16 the selinux filesystem is mounted at /sys/fs/selinux,
|
|
|
|
# so loop through the possible selinux mount points.
|
2011-11-11 14:41:37 -07:00
|
|
|
for se_mount in /selinux /sys/fs/selinux
|
|
|
|
do
|
|
|
|
if [ -d $se_mount -a -f $se_mount/booleans/allow_execstack -a -x /usr/sbin/selinuxenabled ] && /usr/sbin/selinuxenabled; then
|
|
|
|
if ! cat $se_mount/booleans/allow_execstack | grep -c '^1 1$' >> /dev/null ; then
|
|
|
|
echo "WARNING: the default SELinux policy on, at least, Fedora 12 breaks "
|
|
|
|
echo "Go. You can enable the features that Go needs via the following "
|
|
|
|
echo "command (as root):"
|
|
|
|
echo " # setsebool -P allow_execstack 1"
|
|
|
|
echo
|
|
|
|
echo "Note that this affects your system globally! "
|
|
|
|
echo
|
|
|
|
echo "The build will continue in five seconds in case we "
|
|
|
|
echo "misdiagnosed the issue..."
|
2009-11-11 16:02:15 -07:00
|
|
|
|
2011-11-11 14:41:37 -07:00
|
|
|
sleep 5
|
|
|
|
fi
|
2009-11-11 16:02:15 -07:00
|
|
|
fi
|
2011-11-11 14:41:37 -07:00
|
|
|
done
|
2009-11-11 16:02:15 -07:00
|
|
|
|
2012-12-03 14:27:30 -07:00
|
|
|
# Test for debian/kFreeBSD.
|
|
|
|
# cmd/dist will detect kFreeBSD as freebsd/$GOARCH, but we need to
|
|
|
|
# disable cgo manually.
|
2017-03-10 10:15:46 -07:00
|
|
|
if [ "$(uname -s)" = "GNU/kFreeBSD" ]; then
|
2017-03-09 13:50:24 -07:00
|
|
|
export CGO_ENABLED=0
|
2012-12-03 14:27:30 -07:00
|
|
|
fi
|
|
|
|
|
2019-02-25 03:32:00 -07:00
|
|
|
# On Alpine Linux, use the musl dynamic linker/loader
|
|
|
|
if [ -f "/etc/alpine-release" ]; then
|
|
|
|
if type readelf >/dev/null 2>&1; then
|
|
|
|
echo "int main() { return 0; }" | ${CC:-gcc} -o ./test-alpine-ldso -x c -
|
|
|
|
export GO_LDSO=$(readelf -l ./test-alpine-ldso | grep 'interpreter:' | sed -e 's/^.*interpreter: \(.*\)[]]/\1/')
|
|
|
|
rm -f ./test-alpine-ldso
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2012-03-07 09:38:05 -07:00
|
|
|
# Clean old generated file that will cause problems in the build.
|
2014-09-07 22:06:45 -06:00
|
|
|
rm -f ./runtime/runtime_defs.go
|
2012-03-07 09:38:05 -07:00
|
|
|
|
2012-02-03 22:54:08 -07:00
|
|
|
# Finally! Run the build.
|
2011-12-20 14:50:13 -07:00
|
|
|
|
2017-10-28 07:00:35 -06:00
|
|
|
verbose=false
|
|
|
|
vflag=""
|
|
|
|
if [ "$1" = "-v" ]; then
|
|
|
|
verbose=true
|
|
|
|
vflag=-v
|
|
|
|
shift
|
|
|
|
fi
|
|
|
|
|
2017-08-21 23:36:19 -06:00
|
|
|
export GOROOT_BOOTSTRAP=${GOROOT_BOOTSTRAP:-$HOME/go1.4}
|
2017-10-28 07:00:35 -06:00
|
|
|
export GOROOT="$(cd .. && pwd)"
|
2017-10-31 23:05:48 -06:00
|
|
|
IFS=$'\n'; for go_exe in $(type -ap go); do
|
2017-08-21 23:36:19 -06:00
|
|
|
if [ ! -x "$GOROOT_BOOTSTRAP/bin/go" ]; then
|
2018-06-19 22:22:37 -06:00
|
|
|
goroot=$(GOROOT='' GOOS='' GOARCH='' "$go_exe" env GOROOT)
|
2017-08-21 23:36:19 -06:00
|
|
|
if [ "$goroot" != "$GOROOT" ]; then
|
|
|
|
GOROOT_BOOTSTRAP=$goroot
|
|
|
|
fi
|
|
|
|
fi
|
2017-10-31 23:05:48 -06:00
|
|
|
done; unset IFS
|
|
|
|
echo "Building Go cmd/dist using $GOROOT_BOOTSTRAP."
|
|
|
|
if $verbose; then
|
|
|
|
echo cmd/dist
|
|
|
|
fi
|
2015-01-07 09:38:00 -07:00
|
|
|
if [ ! -x "$GOROOT_BOOTSTRAP/bin/go" ]; then
|
|
|
|
echo "ERROR: Cannot find $GOROOT_BOOTSTRAP/bin/go." >&2
|
|
|
|
echo "Set \$GOROOT_BOOTSTRAP to a working Go tree >= Go 1.4." >&2
|
2015-08-19 20:28:51 -06:00
|
|
|
exit 1
|
|
|
|
fi
|
2017-03-10 10:15:46 -07:00
|
|
|
if [ "$GOROOT_BOOTSTRAP" = "$GOROOT" ]; then
|
2015-08-19 20:28:51 -06:00
|
|
|
echo "ERROR: \$GOROOT_BOOTSTRAP must not be set to \$GOROOT" >&2
|
|
|
|
echo "Set \$GOROOT_BOOTSTRAP to a working Go tree >= Go 1.4." >&2
|
|
|
|
exit 1
|
2014-04-28 22:32:16 -06:00
|
|
|
fi
|
2015-01-07 09:38:00 -07:00
|
|
|
rm -f cmd/dist/dist
|
2015-01-14 13:14:54 -07:00
|
|
|
GOROOT="$GOROOT_BOOTSTRAP" GOOS="" GOARCH="" "$GOROOT_BOOTSTRAP/bin/go" build -o cmd/dist/dist ./cmd/dist
|
2012-03-12 13:34:22 -06:00
|
|
|
|
2013-08-18 19:18:43 -06:00
|
|
|
# -e doesn't propagate out of eval, so check success by hand.
|
|
|
|
eval $(./cmd/dist/dist env -p || echo FAIL=true)
|
|
|
|
if [ "$FAIL" = true ]; then
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2017-10-28 07:00:35 -06:00
|
|
|
if $verbose; then
|
|
|
|
echo
|
|
|
|
fi
|
2011-12-19 13:51:13 -07:00
|
|
|
|
2012-02-06 11:48:43 -07:00
|
|
|
if [ "$1" = "--dist-tool" ]; then
|
|
|
|
# Stop after building dist tool.
|
2012-03-01 22:45:01 -07:00
|
|
|
mkdir -p "$GOTOOLDIR"
|
2012-02-14 15:06:24 -07:00
|
|
|
if [ "$2" != "" ]; then
|
|
|
|
cp cmd/dist/dist "$2"
|
|
|
|
fi
|
2012-03-01 22:45:01 -07:00
|
|
|
mv cmd/dist/dist "$GOTOOLDIR"/dist
|
2012-02-06 11:48:43 -07:00
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
2012-02-15 09:48:17 -07:00
|
|
|
buildall="-a"
|
|
|
|
if [ "$1" = "--no-clean" ]; then
|
|
|
|
buildall=""
|
2014-05-20 10:10:19 -06:00
|
|
|
shift
|
2012-02-15 09:48:17 -07:00
|
|
|
fi
|
2016-03-17 12:12:12 -06:00
|
|
|
|
2017-10-23 19:57:54 -06:00
|
|
|
# Run dist bootstrap to complete make.bash.
|
|
|
|
# Bootstrap installs a proper cmd/dist, built with the new toolchain.
|
|
|
|
# Throw ours, built with Go 1.4, away after bootstrap.
|
2017-10-28 07:00:35 -06:00
|
|
|
./cmd/dist/dist bootstrap $buildall $vflag $GO_DISTFLAGS "$@"
|
2017-10-23 19:57:54 -06:00
|
|
|
rm -f ./cmd/dist/dist
|
|
|
|
|
|
|
|
# DO NOT ADD ANY NEW CODE HERE.
|
|
|
|
# The bootstrap+rm above are the final step of make.bash.
|
|
|
|
# If something must be added, add it to cmd/dist's cmdbootstrap,
|
|
|
|
# to avoid needing three copies in three different shell languages
|
|
|
|
# (make.bash, make.bat, make.rc).
|