Devon H. O'Dell | 553be84 | 2009-11-14 15:29:09 -0800 | [diff] [blame] | 1 | #!/usr/bin/env bash |
Rob Pike | df28e14 | 2008-06-11 13:34:08 -0700 | [diff] [blame] | 2 | # Copyright 2009 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 | |
Russ Cox | 20a10e7 | 2015-01-07 11:38:00 -0500 | [diff] [blame] | 6 | # See golang.org/s/go15bootstrap for an overview of the build process. |
| 7 | |
Russ Cox | b03a5f6 | 2012-03-01 12:12:22 -0500 | [diff] [blame] | 8 | # Environment variables that control make.bash: |
| 9 | # |
| 10 | # GOROOT_FINAL: The expected final Go root, baked into binaries. |
| 11 | # The default is the location of the Go tree during the build. |
| 12 | # |
| 13 | # GOHOSTARCH: The architecture for host tools (compilers and |
| 14 | # binaries). Binaries of this type must be executable on the current |
| 15 | # system, so the only common reason to set this is to set |
| 16 | # GOHOSTARCH=386 on an amd64 machine. |
| 17 | # |
| 18 | # GOARCH: The target architecture for installed packages and tools. |
| 19 | # |
| 20 | # GOOS: The target operating system for installed packages and tools. |
| 21 | # |
Jeremy Jackins | 7354978 | 2015-05-28 16:13:23 +0900 | [diff] [blame] | 22 | # GO_GCFLAGS: Additional go tool compile arguments to use when |
Russ Cox | b03a5f6 | 2012-03-01 12:12:22 -0500 | [diff] [blame] | 23 | # building the packages and commands. |
| 24 | # |
Jeremy Jackins | 7354978 | 2015-05-28 16:13:23 +0900 | [diff] [blame] | 25 | # GO_LDFLAGS: Additional go tool link arguments to use when |
David Symonds | fa6d3ab | 2012-03-13 12:52:15 +1100 | [diff] [blame] | 26 | # building the commands. |
Russ Cox | b03a5f6 | 2012-03-01 12:12:22 -0500 | [diff] [blame] | 27 | # |
Alex Brainman | 7fbef93 | 2012-03-20 14:04:20 +1100 | [diff] [blame] | 28 | # CGO_ENABLED: Controls cgo usage during the build. Set it to 1 |
| 29 | # to include all cgo related files, .c and .go file with "cgo" |
| 30 | # build directive, in the build. Set it to 0 to ignore them. |
Russ Cox | 6d888f1 | 2013-02-15 13:37:43 -0800 | [diff] [blame] | 31 | # |
Ian Lance Taylor | 3197be4 | 2013-03-29 16:33:35 -0700 | [diff] [blame] | 32 | # GO_EXTLINK_ENABLED: Set to 1 to invoke the host linker when building |
| 33 | # packages that use cgo. Set to 0 to do all linking internally. This |
| 34 | # controls the default behavior of the linker's -linkmode option. The |
| 35 | # default value depends on the system. |
| 36 | # |
Elias Naur | 2dc759d | 2014-02-06 09:11:00 -0800 | [diff] [blame] | 37 | # CC: Command line to run to compile C code for GOHOSTARCH. |
Russ Cox | 6d888f1 | 2013-02-15 13:37:43 -0800 | [diff] [blame] | 38 | # Default is "gcc". Also supported: "clang". |
Elias Naur | 2dc759d | 2014-02-06 09:11:00 -0800 | [diff] [blame] | 39 | # |
| 40 | # CC_FOR_TARGET: Command line to run to compile C code for GOARCH. |
| 41 | # This is used by cgo. Default is CC. |
| 42 | # |
| 43 | # CXX_FOR_TARGET: Command line to run to compile C++ code for GOARCH. |
| 44 | # This is used by cgo. Default is CXX, or, if that is not set, |
| 45 | # "g++" or "clang++". |
Shenghou Ma | 6b188ef | 2013-10-01 23:44:20 -0400 | [diff] [blame] | 46 | # |
| 47 | # GO_DISTFLAGS: extra flags to provide to "dist bootstrap". Use "-s" |
| 48 | # to build a statically linked toolchain. |
Russ Cox | b03a5f6 | 2012-03-01 12:12:22 -0500 | [diff] [blame] | 49 | |
Russ Cox | 7603619 | 2008-09-18 15:06:43 -0700 | [diff] [blame] | 50 | set -e |
Russ Cox | 8290536 | 2012-02-04 00:54:08 -0500 | [diff] [blame] | 51 | if [ ! -f run.bash ]; then |
Russ Cox | da392d9 | 2010-08-18 10:08:49 -0400 | [diff] [blame] | 52 | echo 'make.bash must be run from $GOROOT/src' 1>&2 |
| 53 | exit 1 |
| 54 | fi |
Devon H. O'Dell | 857d4cf | 2009-12-11 15:14:09 -0800 | [diff] [blame] | 55 | |
Russ Cox | b5d81e5 | 2012-02-12 23:14:37 -0500 | [diff] [blame] | 56 | # Test for Windows. |
| 57 | case "$(uname)" in |
| 58 | *MINGW* | *WIN32* | *CYGWIN*) |
| 59 | echo 'ERROR: Do not use make.bash to build on Windows.' |
| 60 | echo 'Use make.bat instead.' |
| 61 | echo |
| 62 | exit 1 |
| 63 | ;; |
| 64 | esac |
| 65 | |
Russ Cox | 8290536 | 2012-02-04 00:54:08 -0500 | [diff] [blame] | 66 | # Test for bad ld. |
Christopher Wedgwood | 604bd70 | 2011-10-13 12:25:25 -0400 | [diff] [blame] | 67 | if ld --version 2>&1 | grep 'gold.* 2\.20' >/dev/null; then |
Russ Cox | eedfc44 | 2011-03-18 18:23:00 -0400 | [diff] [blame] | 68 | echo 'ERROR: Your system has gold 2.20 installed.' |
| 69 | echo 'This version is shipped by Ubuntu even though' |
| 70 | echo 'it is known not to work on Ubuntu.' |
| 71 | echo 'Binaries built with this linker are likely to fail in mysterious ways.' |
| 72 | echo |
| 73 | echo 'Run sudo apt-get remove binutils-gold.' |
| 74 | echo |
| 75 | exit 1 |
| 76 | fi |
| 77 | |
Russ Cox | 8290536 | 2012-02-04 00:54:08 -0500 | [diff] [blame] | 78 | # Test for bad SELinux. |
| 79 | # On Fedora 16 the selinux filesystem is mounted at /sys/fs/selinux, |
| 80 | # so loop through the possible selinux mount points. |
Bobby Powers | 90c5070 | 2011-11-11 16:41:37 -0500 | [diff] [blame] | 81 | for se_mount in /selinux /sys/fs/selinux |
| 82 | do |
| 83 | if [ -d $se_mount -a -f $se_mount/booleans/allow_execstack -a -x /usr/sbin/selinuxenabled ] && /usr/sbin/selinuxenabled; then |
| 84 | if ! cat $se_mount/booleans/allow_execstack | grep -c '^1 1$' >> /dev/null ; then |
| 85 | echo "WARNING: the default SELinux policy on, at least, Fedora 12 breaks " |
| 86 | echo "Go. You can enable the features that Go needs via the following " |
| 87 | echo "command (as root):" |
| 88 | echo " # setsebool -P allow_execstack 1" |
| 89 | echo |
| 90 | echo "Note that this affects your system globally! " |
| 91 | echo |
| 92 | echo "The build will continue in five seconds in case we " |
| 93 | echo "misdiagnosed the issue..." |
Adam Langley | 2643f74 | 2009-11-11 15:02:15 -0800 | [diff] [blame] | 94 | |
Bobby Powers | 90c5070 | 2011-11-11 16:41:37 -0500 | [diff] [blame] | 95 | sleep 5 |
| 96 | fi |
Adam Langley | 2643f74 | 2009-11-11 15:02:15 -0800 | [diff] [blame] | 97 | fi |
Bobby Powers | 90c5070 | 2011-11-11 16:41:37 -0500 | [diff] [blame] | 98 | done |
Adam Langley | 2643f74 | 2009-11-11 15:02:15 -0800 | [diff] [blame] | 99 | |
Dave Cheney | 3167c12 | 2012-12-04 08:27:30 +1100 | [diff] [blame] | 100 | # Test for debian/kFreeBSD. |
| 101 | # cmd/dist will detect kFreeBSD as freebsd/$GOARCH, but we need to |
| 102 | # disable cgo manually. |
| 103 | if [ "$(uname -s)" == "GNU/kFreeBSD" ]; then |
| 104 | export CGO_ENABLED=0 |
| 105 | fi |
| 106 | |
Russ Cox | 318465b | 2012-03-07 11:38:05 -0500 | [diff] [blame] | 107 | # Clean old generated file that will cause problems in the build. |
Russ Cox | 220a6de | 2014-09-08 00:06:45 -0400 | [diff] [blame] | 108 | rm -f ./runtime/runtime_defs.go |
Russ Cox | 318465b | 2012-03-07 11:38:05 -0500 | [diff] [blame] | 109 | |
Russ Cox | 8290536 | 2012-02-04 00:54:08 -0500 | [diff] [blame] | 110 | # Finally! Run the build. |
Russ Cox | 9ff712e | 2009-11-10 19:20:34 -0800 | [diff] [blame] | 111 | |
Russ Cox | 20a10e7 | 2015-01-07 11:38:00 -0500 | [diff] [blame] | 112 | echo '##### Building Go bootstrap tool.' |
Russ Cox | b5d81e5 | 2012-02-12 23:14:37 -0500 | [diff] [blame] | 113 | echo cmd/dist |
Gustavo Niemeyer | 54f1e1b | 2012-02-09 20:47:12 -0200 | [diff] [blame] | 114 | export GOROOT="$(cd .. && pwd)" |
Russ Cox | 20a10e7 | 2015-01-07 11:38:00 -0500 | [diff] [blame] | 115 | GOROOT_BOOTSTRAP=${GOROOT_BOOTSTRAP:-$HOME/go1.4} |
| 116 | if [ ! -x "$GOROOT_BOOTSTRAP/bin/go" ]; then |
| 117 | echo "ERROR: Cannot find $GOROOT_BOOTSTRAP/bin/go." >&2 |
| 118 | echo "Set \$GOROOT_BOOTSTRAP to a working Go tree >= Go 1.4." >&2 |
Shenghou Ma | a5fe79e | 2013-04-16 13:30:52 -0700 | [diff] [blame] | 119 | fi |
Russ Cox | 20a10e7 | 2015-01-07 11:38:00 -0500 | [diff] [blame] | 120 | rm -f cmd/dist/dist |
Russ Cox | 1fac6d1 | 2015-01-14 15:14:54 -0500 | [diff] [blame] | 121 | GOROOT="$GOROOT_BOOTSTRAP" GOOS="" GOARCH="" "$GOROOT_BOOTSTRAP/bin/go" build -o cmd/dist/dist ./cmd/dist |
Shenghou Ma | 7280129 | 2012-03-13 03:34:22 +0800 | [diff] [blame] | 122 | |
Rob Pike | e8140bd | 2013-08-19 11:18:43 +1000 | [diff] [blame] | 123 | # -e doesn't propagate out of eval, so check success by hand. |
| 124 | eval $(./cmd/dist/dist env -p || echo FAIL=true) |
| 125 | if [ "$FAIL" = true ]; then |
| 126 | exit 1 |
| 127 | fi |
| 128 | |
Russ Cox | 2050a9e | 2012-01-30 23:43:46 -0500 | [diff] [blame] | 129 | echo |
Russ Cox | 8290536 | 2012-02-04 00:54:08 -0500 | [diff] [blame] | 130 | |
Russ Cox | 1c290fd | 2012-02-06 13:48:43 -0500 | [diff] [blame] | 131 | if [ "$1" = "--dist-tool" ]; then |
| 132 | # Stop after building dist tool. |
Gustavo Niemeyer | 7e19e53 | 2012-03-02 02:45:01 -0300 | [diff] [blame] | 133 | mkdir -p "$GOTOOLDIR" |
David Symonds | 0ab3ea9 | 2012-02-15 09:06:24 +1100 | [diff] [blame] | 134 | if [ "$2" != "" ]; then |
| 135 | cp cmd/dist/dist "$2" |
| 136 | fi |
Gustavo Niemeyer | 7e19e53 | 2012-03-02 02:45:01 -0300 | [diff] [blame] | 137 | mv cmd/dist/dist "$GOTOOLDIR"/dist |
Russ Cox | 1c290fd | 2012-02-06 13:48:43 -0500 | [diff] [blame] | 138 | exit 0 |
| 139 | fi |
| 140 | |
Russ Cox | 2506fd4 | 2012-02-15 11:48:17 -0500 | [diff] [blame] | 141 | buildall="-a" |
| 142 | if [ "$1" = "--no-clean" ]; then |
| 143 | buildall="" |
Russ Cox | 0c2a727 | 2014-05-20 12:10:19 -0400 | [diff] [blame] | 144 | shift |
Russ Cox | 2506fd4 | 2012-02-15 11:48:17 -0500 | [diff] [blame] | 145 | fi |
Shenghou Ma | 6b188ef | 2013-10-01 23:44:20 -0400 | [diff] [blame] | 146 | ./cmd/dist/dist bootstrap $buildall $GO_DISTFLAGS -v # builds go_bootstrap |
Russ Cox | 2506fd4 | 2012-02-15 11:48:17 -0500 | [diff] [blame] | 147 | # Delay move of dist tool to now, because bootstrap may clear tool directory. |
Gustavo Niemeyer | 7e19e53 | 2012-03-02 02:45:01 -0300 | [diff] [blame] | 148 | mv cmd/dist/dist "$GOTOOLDIR"/dist |
Russ Cox | 8290536 | 2012-02-04 00:54:08 -0500 | [diff] [blame] | 149 | echo |
| 150 | |
Russ Cox | 7b848c6 | 2012-02-13 22:31:51 -0500 | [diff] [blame] | 151 | if [ "$GOHOSTARCH" != "$GOARCH" -o "$GOHOSTOS" != "$GOOS" ]; then |
Russ Cox | d160d1b | 2014-12-10 10:45:59 -0500 | [diff] [blame] | 152 | echo "##### Building packages and commands for host, $GOHOSTOS/$GOHOSTARCH." |
Elias Naur | 2dc759d | 2014-02-06 09:11:00 -0800 | [diff] [blame] | 153 | # CC_FOR_TARGET is recorded as the default compiler for the go tool. When building for the host, however, |
| 154 | # use the host compiler, CC, from `cmd/dist/dist env` instead. |
| 155 | CC=$CC GOOS=$GOHOSTOS GOARCH=$GOHOSTARCH \ |
Russ Cox | 096b294 | 2015-02-22 12:41:32 -0500 | [diff] [blame] | 156 | "$GOTOOLDIR"/go_bootstrap install -gcflags "$GO_GCFLAGS" -ldflags "$GO_LDFLAGS" -v std cmd |
Russ Cox | 7b848c6 | 2012-02-13 22:31:51 -0500 | [diff] [blame] | 157 | echo |
| 158 | fi |
| 159 | |
Russ Cox | d160d1b | 2014-12-10 10:45:59 -0500 | [diff] [blame] | 160 | echo "##### Building packages and commands for $GOOS/$GOARCH." |
Russ Cox | 096b294 | 2015-02-22 12:41:32 -0500 | [diff] [blame] | 161 | CC=$CC_FOR_TARGET "$GOTOOLDIR"/go_bootstrap install $GO_FLAGS -gcflags "$GO_GCFLAGS" -ldflags "$GO_LDFLAGS" -v std cmd |
Russ Cox | 8290536 | 2012-02-04 00:54:08 -0500 | [diff] [blame] | 162 | echo |
| 163 | |
Gustavo Niemeyer | 7e19e53 | 2012-03-02 02:45:01 -0300 | [diff] [blame] | 164 | rm -f "$GOTOOLDIR"/go_bootstrap |
Russ Cox | 7b848c6 | 2012-02-13 22:31:51 -0500 | [diff] [blame] | 165 | |
Russ Cox | 8290536 | 2012-02-04 00:54:08 -0500 | [diff] [blame] | 166 | if [ "$1" != "--no-banner" ]; then |
Gustavo Niemeyer | 7e19e53 | 2012-03-02 02:45:01 -0300 | [diff] [blame] | 167 | "$GOTOOLDIR"/dist banner |
Russ Cox | 41a6165 | 2011-12-20 16:50:13 -0500 | [diff] [blame] | 168 | fi |