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 | b03a5f6 | 2012-03-01 12:12:22 -0500 | [diff] [blame] | 6 | # Environment variables that control make.bash: |
| 7 | # |
| 8 | # GOROOT_FINAL: The expected final Go root, baked into binaries. |
| 9 | # The default is the location of the Go tree during the build. |
| 10 | # |
| 11 | # GOHOSTARCH: The architecture for host tools (compilers and |
| 12 | # binaries). Binaries of this type must be executable on the current |
| 13 | # system, so the only common reason to set this is to set |
| 14 | # GOHOSTARCH=386 on an amd64 machine. |
| 15 | # |
| 16 | # GOARCH: The target architecture for installed packages and tools. |
| 17 | # |
| 18 | # GOOS: The target operating system for installed packages and tools. |
| 19 | # |
Gustavo Niemeyer | 7e19e53 | 2012-03-02 02:45:01 -0300 | [diff] [blame] | 20 | # GO_GCFLAGS: Additional 5g/6g/8g arguments to use when |
Russ Cox | b03a5f6 | 2012-03-01 12:12:22 -0500 | [diff] [blame] | 21 | # building the packages and commands. |
| 22 | # |
Gustavo Niemeyer | 7e19e53 | 2012-03-02 02:45:01 -0300 | [diff] [blame] | 23 | # GO_LDFLAGS: Additional 5l/6l/8l arguments to use when |
David Symonds | fa6d3ab | 2012-03-13 12:52:15 +1100 | [diff] [blame] | 24 | # building the commands. |
Russ Cox | b03a5f6 | 2012-03-01 12:12:22 -0500 | [diff] [blame] | 25 | # |
Alex Brainman | 7fbef93 | 2012-03-20 14:04:20 +1100 | [diff] [blame] | 26 | # CGO_ENABLED: Controls cgo usage during the build. Set it to 1 |
| 27 | # to include all cgo related files, .c and .go file with "cgo" |
| 28 | # build directive, in the build. Set it to 0 to ignore them. |
Russ Cox | b03a5f6 | 2012-03-01 12:12:22 -0500 | [diff] [blame] | 29 | |
Russ Cox | 7603619 | 2008-09-18 15:06:43 -0700 | [diff] [blame] | 30 | set -e |
Russ Cox | 8290536 | 2012-02-04 00:54:08 -0500 | [diff] [blame] | 31 | if [ ! -f run.bash ]; then |
Russ Cox | da392d9 | 2010-08-18 10:08:49 -0400 | [diff] [blame] | 32 | echo 'make.bash must be run from $GOROOT/src' 1>&2 |
| 33 | exit 1 |
| 34 | fi |
Devon H. O'Dell | 857d4cf | 2009-12-11 15:14:09 -0800 | [diff] [blame] | 35 | |
Russ Cox | b5d81e5 | 2012-02-12 23:14:37 -0500 | [diff] [blame] | 36 | # Test for Windows. |
| 37 | case "$(uname)" in |
| 38 | *MINGW* | *WIN32* | *CYGWIN*) |
| 39 | echo 'ERROR: Do not use make.bash to build on Windows.' |
| 40 | echo 'Use make.bat instead.' |
| 41 | echo |
| 42 | exit 1 |
| 43 | ;; |
| 44 | esac |
| 45 | |
Russ Cox | 8290536 | 2012-02-04 00:54:08 -0500 | [diff] [blame] | 46 | # Test for bad ld. |
Christopher Wedgwood | 604bd70 | 2011-10-13 12:25:25 -0400 | [diff] [blame] | 47 | if ld --version 2>&1 | grep 'gold.* 2\.20' >/dev/null; then |
Russ Cox | eedfc44 | 2011-03-18 18:23:00 -0400 | [diff] [blame] | 48 | echo 'ERROR: Your system has gold 2.20 installed.' |
| 49 | echo 'This version is shipped by Ubuntu even though' |
| 50 | echo 'it is known not to work on Ubuntu.' |
| 51 | echo 'Binaries built with this linker are likely to fail in mysterious ways.' |
| 52 | echo |
| 53 | echo 'Run sudo apt-get remove binutils-gold.' |
| 54 | echo |
| 55 | exit 1 |
| 56 | fi |
| 57 | |
Russ Cox | 8290536 | 2012-02-04 00:54:08 -0500 | [diff] [blame] | 58 | # Test for bad SELinux. |
| 59 | # On Fedora 16 the selinux filesystem is mounted at /sys/fs/selinux, |
| 60 | # so loop through the possible selinux mount points. |
Bobby Powers | 90c5070 | 2011-11-11 16:41:37 -0500 | [diff] [blame] | 61 | for se_mount in /selinux /sys/fs/selinux |
| 62 | do |
| 63 | if [ -d $se_mount -a -f $se_mount/booleans/allow_execstack -a -x /usr/sbin/selinuxenabled ] && /usr/sbin/selinuxenabled; then |
| 64 | if ! cat $se_mount/booleans/allow_execstack | grep -c '^1 1$' >> /dev/null ; then |
| 65 | echo "WARNING: the default SELinux policy on, at least, Fedora 12 breaks " |
| 66 | echo "Go. You can enable the features that Go needs via the following " |
| 67 | echo "command (as root):" |
| 68 | echo " # setsebool -P allow_execstack 1" |
| 69 | echo |
| 70 | echo "Note that this affects your system globally! " |
| 71 | echo |
| 72 | echo "The build will continue in five seconds in case we " |
| 73 | echo "misdiagnosed the issue..." |
Adam Langley | 2643f74 | 2009-11-11 15:02:15 -0800 | [diff] [blame] | 74 | |
Bobby Powers | 90c5070 | 2011-11-11 16:41:37 -0500 | [diff] [blame] | 75 | sleep 5 |
| 76 | fi |
Adam Langley | 2643f74 | 2009-11-11 15:02:15 -0800 | [diff] [blame] | 77 | fi |
Bobby Powers | 90c5070 | 2011-11-11 16:41:37 -0500 | [diff] [blame] | 78 | done |
Adam Langley | 2643f74 | 2009-11-11 15:02:15 -0800 | [diff] [blame] | 79 | |
Dave Cheney | 3167c12 | 2012-12-04 08:27:30 +1100 | [diff] [blame^] | 80 | # Test for debian/kFreeBSD. |
| 81 | # cmd/dist will detect kFreeBSD as freebsd/$GOARCH, but we need to |
| 82 | # disable cgo manually. |
| 83 | if [ "$(uname -s)" == "GNU/kFreeBSD" ]; then |
| 84 | export CGO_ENABLED=0 |
| 85 | fi |
| 86 | |
Russ Cox | 318465b | 2012-03-07 11:38:05 -0500 | [diff] [blame] | 87 | # Clean old generated file that will cause problems in the build. |
| 88 | rm -f ./pkg/runtime/runtime_defs.go |
| 89 | |
Russ Cox | 8290536 | 2012-02-04 00:54:08 -0500 | [diff] [blame] | 90 | # Finally! Run the build. |
Russ Cox | 9ff712e | 2009-11-10 19:20:34 -0800 | [diff] [blame] | 91 | |
Russ Cox | 8290536 | 2012-02-04 00:54:08 -0500 | [diff] [blame] | 92 | echo '# Building C bootstrap tool.' |
Russ Cox | b5d81e5 | 2012-02-12 23:14:37 -0500 | [diff] [blame] | 93 | echo cmd/dist |
Gustavo Niemeyer | 54f1e1b | 2012-02-09 20:47:12 -0200 | [diff] [blame] | 94 | export GOROOT="$(cd .. && pwd)" |
| 95 | GOROOT_FINAL="${GOROOT_FINAL:-$GOROOT}" |
| 96 | DEFGOROOT='-DGOROOT_FINAL="'"$GOROOT_FINAL"'"' |
Shenghou Ma | 7280129 | 2012-03-13 03:34:22 +0800 | [diff] [blame] | 97 | |
| 98 | mflag="" |
| 99 | case "$GOHOSTARCH" in |
| 100 | 386) mflag=-m32;; |
| 101 | amd64) mflag=-m64;; |
| 102 | esac |
| 103 | gcc $mflag -O2 -Wall -Werror -ggdb -o cmd/dist/dist -Icmd/dist "$DEFGOROOT" cmd/dist/*.c |
| 104 | |
Russ Cox | 982e6c4 | 2012-02-13 22:46:50 -0500 | [diff] [blame] | 105 | eval $(./cmd/dist/dist env -p) |
Russ Cox | 2050a9e | 2012-01-30 23:43:46 -0500 | [diff] [blame] | 106 | echo |
Russ Cox | 8290536 | 2012-02-04 00:54:08 -0500 | [diff] [blame] | 107 | |
Russ Cox | 1c290fd | 2012-02-06 13:48:43 -0500 | [diff] [blame] | 108 | if [ "$1" = "--dist-tool" ]; then |
| 109 | # Stop after building dist tool. |
Gustavo Niemeyer | 7e19e53 | 2012-03-02 02:45:01 -0300 | [diff] [blame] | 110 | mkdir -p "$GOTOOLDIR" |
David Symonds | 0ab3ea9 | 2012-02-15 09:06:24 +1100 | [diff] [blame] | 111 | if [ "$2" != "" ]; then |
| 112 | cp cmd/dist/dist "$2" |
| 113 | fi |
Gustavo Niemeyer | 7e19e53 | 2012-03-02 02:45:01 -0300 | [diff] [blame] | 114 | mv cmd/dist/dist "$GOTOOLDIR"/dist |
Russ Cox | 1c290fd | 2012-02-06 13:48:43 -0500 | [diff] [blame] | 115 | exit 0 |
| 116 | fi |
| 117 | |
Russ Cox | 7b848c6 | 2012-02-13 22:31:51 -0500 | [diff] [blame] | 118 | echo "# Building compilers and Go bootstrap tool for host, $GOHOSTOS/$GOHOSTARCH." |
Russ Cox | 2506fd4 | 2012-02-15 11:48:17 -0500 | [diff] [blame] | 119 | buildall="-a" |
| 120 | if [ "$1" = "--no-clean" ]; then |
| 121 | buildall="" |
| 122 | fi |
| 123 | ./cmd/dist/dist bootstrap $buildall -v # builds go_bootstrap |
| 124 | # 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] | 125 | mv cmd/dist/dist "$GOTOOLDIR"/dist |
| 126 | "$GOTOOLDIR"/go_bootstrap clean -i std |
Russ Cox | 8290536 | 2012-02-04 00:54:08 -0500 | [diff] [blame] | 127 | echo |
| 128 | |
Russ Cox | 7b848c6 | 2012-02-13 22:31:51 -0500 | [diff] [blame] | 129 | if [ "$GOHOSTARCH" != "$GOARCH" -o "$GOHOSTOS" != "$GOOS" ]; then |
| 130 | echo "# Building packages and commands for host, $GOHOSTOS/$GOHOSTARCH." |
| 131 | GOOS=$GOHOSTOS GOARCH=$GOHOSTARCH \ |
Gustavo Niemeyer | 7e19e53 | 2012-03-02 02:45:01 -0300 | [diff] [blame] | 132 | "$GOTOOLDIR"/go_bootstrap install -gcflags "$GO_GCFLAGS" -ldflags "$GO_LDFLAGS" -v std |
Russ Cox | 7b848c6 | 2012-02-13 22:31:51 -0500 | [diff] [blame] | 133 | echo |
| 134 | fi |
| 135 | |
| 136 | echo "# Building packages and commands for $GOOS/$GOARCH." |
Gustavo Niemeyer | 7e19e53 | 2012-03-02 02:45:01 -0300 | [diff] [blame] | 137 | "$GOTOOLDIR"/go_bootstrap install -gcflags "$GO_GCFLAGS" -ldflags "$GO_LDFLAGS" -v std |
Russ Cox | 8290536 | 2012-02-04 00:54:08 -0500 | [diff] [blame] | 138 | echo |
| 139 | |
Gustavo Niemeyer | 7e19e53 | 2012-03-02 02:45:01 -0300 | [diff] [blame] | 140 | rm -f "$GOTOOLDIR"/go_bootstrap |
Russ Cox | 7b848c6 | 2012-02-13 22:31:51 -0500 | [diff] [blame] | 141 | |
Russ Cox | 8290536 | 2012-02-04 00:54:08 -0500 | [diff] [blame] | 142 | if [ "$1" != "--no-banner" ]; then |
Gustavo Niemeyer | 7e19e53 | 2012-03-02 02:45:01 -0300 | [diff] [blame] | 143 | "$GOTOOLDIR"/dist banner |
Russ Cox | 41a6165 | 2011-12-20 16:50:13 -0500 | [diff] [blame] | 144 | fi |