blob: 1190b93ffaee03acf7cf9f653232f8996027f651 [file] [log] [blame]
Devon H. O'Dell553be842009-11-14 15:29:09 -08001#!/usr/bin/env bash
Rob Pikedf28e142008-06-11 13:34:08 -07002# 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 Coxb03a5f62012-03-01 12:12:22 -05006# 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 Niemeyer7e19e532012-03-02 02:45:01 -030020# GO_GCFLAGS: Additional 5g/6g/8g arguments to use when
Russ Coxb03a5f62012-03-01 12:12:22 -050021# building the packages and commands.
22#
Gustavo Niemeyer7e19e532012-03-02 02:45:01 -030023# GO_LDFLAGS: Additional 5l/6l/8l arguments to use when
David Symondsfa6d3ab2012-03-13 12:52:15 +110024# building the commands.
Russ Coxb03a5f62012-03-01 12:12:22 -050025#
Alex Brainman7fbef932012-03-20 14:04:20 +110026# 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 Coxb03a5f62012-03-01 12:12:22 -050029
Russ Cox76036192008-09-18 15:06:43 -070030set -e
Russ Cox82905362012-02-04 00:54:08 -050031if [ ! -f run.bash ]; then
Russ Coxda392d92010-08-18 10:08:49 -040032 echo 'make.bash must be run from $GOROOT/src' 1>&2
33 exit 1
34fi
Devon H. O'Dell857d4cf2009-12-11 15:14:09 -080035
Russ Coxb5d81e52012-02-12 23:14:37 -050036# Test for Windows.
37case "$(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 ;;
44esac
45
Russ Cox82905362012-02-04 00:54:08 -050046# Test for bad ld.
Christopher Wedgwood604bd702011-10-13 12:25:25 -040047if ld --version 2>&1 | grep 'gold.* 2\.20' >/dev/null; then
Russ Coxeedfc442011-03-18 18:23:00 -040048 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
56fi
57
Russ Cox82905362012-02-04 00:54:08 -050058# 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 Powers90c50702011-11-11 16:41:37 -050061for se_mount in /selinux /sys/fs/selinux
62do
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 Langley2643f742009-11-11 15:02:15 -080074
Bobby Powers90c50702011-11-11 16:41:37 -050075 sleep 5
76 fi
Adam Langley2643f742009-11-11 15:02:15 -080077 fi
Bobby Powers90c50702011-11-11 16:41:37 -050078done
Adam Langley2643f742009-11-11 15:02:15 -080079
Dave Cheney3167c122012-12-04 08:27:30 +110080# Test for debian/kFreeBSD.
81# cmd/dist will detect kFreeBSD as freebsd/$GOARCH, but we need to
82# disable cgo manually.
83if [ "$(uname -s)" == "GNU/kFreeBSD" ]; then
84 export CGO_ENABLED=0
85fi
86
Russ Cox318465b2012-03-07 11:38:05 -050087# Clean old generated file that will cause problems in the build.
88rm -f ./pkg/runtime/runtime_defs.go
89
Russ Cox82905362012-02-04 00:54:08 -050090# Finally! Run the build.
Russ Cox9ff712e2009-11-10 19:20:34 -080091
Russ Cox82905362012-02-04 00:54:08 -050092echo '# Building C bootstrap tool.'
Russ Coxb5d81e52012-02-12 23:14:37 -050093echo cmd/dist
Gustavo Niemeyer54f1e1b2012-02-09 20:47:12 -020094export GOROOT="$(cd .. && pwd)"
95GOROOT_FINAL="${GOROOT_FINAL:-$GOROOT}"
96DEFGOROOT='-DGOROOT_FINAL="'"$GOROOT_FINAL"'"'
Shenghou Ma72801292012-03-13 03:34:22 +080097
98mflag=""
99case "$GOHOSTARCH" in
100386) mflag=-m32;;
101amd64) mflag=-m64;;
102esac
103gcc $mflag -O2 -Wall -Werror -ggdb -o cmd/dist/dist -Icmd/dist "$DEFGOROOT" cmd/dist/*.c
104
Russ Cox982e6c42012-02-13 22:46:50 -0500105eval $(./cmd/dist/dist env -p)
Russ Cox2050a9e2012-01-30 23:43:46 -0500106echo
Russ Cox82905362012-02-04 00:54:08 -0500107
Russ Cox1c290fd2012-02-06 13:48:43 -0500108if [ "$1" = "--dist-tool" ]; then
109 # Stop after building dist tool.
Gustavo Niemeyer7e19e532012-03-02 02:45:01 -0300110 mkdir -p "$GOTOOLDIR"
David Symonds0ab3ea92012-02-15 09:06:24 +1100111 if [ "$2" != "" ]; then
112 cp cmd/dist/dist "$2"
113 fi
Gustavo Niemeyer7e19e532012-03-02 02:45:01 -0300114 mv cmd/dist/dist "$GOTOOLDIR"/dist
Russ Cox1c290fd2012-02-06 13:48:43 -0500115 exit 0
116fi
117
Russ Cox7b848c62012-02-13 22:31:51 -0500118echo "# Building compilers and Go bootstrap tool for host, $GOHOSTOS/$GOHOSTARCH."
Russ Cox2506fd42012-02-15 11:48:17 -0500119buildall="-a"
120if [ "$1" = "--no-clean" ]; then
121 buildall=""
122fi
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 Niemeyer7e19e532012-03-02 02:45:01 -0300125mv cmd/dist/dist "$GOTOOLDIR"/dist
126"$GOTOOLDIR"/go_bootstrap clean -i std
Russ Cox82905362012-02-04 00:54:08 -0500127echo
128
Russ Cox7b848c62012-02-13 22:31:51 -0500129if [ "$GOHOSTARCH" != "$GOARCH" -o "$GOHOSTOS" != "$GOOS" ]; then
130 echo "# Building packages and commands for host, $GOHOSTOS/$GOHOSTARCH."
131 GOOS=$GOHOSTOS GOARCH=$GOHOSTARCH \
Gustavo Niemeyer7e19e532012-03-02 02:45:01 -0300132 "$GOTOOLDIR"/go_bootstrap install -gcflags "$GO_GCFLAGS" -ldflags "$GO_LDFLAGS" -v std
Russ Cox7b848c62012-02-13 22:31:51 -0500133 echo
134fi
135
136echo "# Building packages and commands for $GOOS/$GOARCH."
Gustavo Niemeyer7e19e532012-03-02 02:45:01 -0300137"$GOTOOLDIR"/go_bootstrap install -gcflags "$GO_GCFLAGS" -ldflags "$GO_LDFLAGS" -v std
Russ Cox82905362012-02-04 00:54:08 -0500138echo
139
Gustavo Niemeyer7e19e532012-03-02 02:45:01 -0300140rm -f "$GOTOOLDIR"/go_bootstrap
Russ Cox7b848c62012-02-13 22:31:51 -0500141
Russ Cox82905362012-02-04 00:54:08 -0500142if [ "$1" != "--no-banner" ]; then
Gustavo Niemeyer7e19e532012-03-02 02:45:01 -0300143 "$GOTOOLDIR"/dist banner
Russ Cox41a61652011-12-20 16:50:13 -0500144fi