github.com/varialus/godfly@v0.0.0-20130904042352-1934f9f095ab/src/make.bash (about) 1 #!/usr/bin/env bash 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 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 # 20 # GO_GCFLAGS: Additional 5g/6g/8g arguments to use when 21 # building the packages and commands. 22 # 23 # GO_LDFLAGS: Additional 5l/6l/8l arguments to use when 24 # building the commands. 25 # 26 # GO_CCFLAGS: Additional 5c/6c/8c arguments to use when 27 # building. 28 # 29 # CGO_ENABLED: Controls cgo usage during the build. Set it to 1 30 # to include all cgo related files, .c and .go file with "cgo" 31 # build directive, in the build. Set it to 0 to ignore them. 32 # 33 # GO_EXTLINK_ENABLED: Set to 1 to invoke the host linker when building 34 # packages that use cgo. Set to 0 to do all linking internally. This 35 # controls the default behavior of the linker's -linkmode option. The 36 # default value depends on the system. 37 # 38 # CC: Command line to run to get at host C compiler. 39 # Default is "gcc". Also supported: "clang". 40 41 set -e 42 if [ ! -f run.bash ]; then 43 echo 'make.bash must be run from $GOROOT/src' 1>&2 44 exit 1 45 fi 46 47 # Test for Windows. 48 case "$(uname)" in 49 *MINGW* | *WIN32* | *CYGWIN*) 50 echo 'ERROR: Do not use make.bash to build on Windows.' 51 echo 'Use make.bat instead.' 52 echo 53 exit 1 54 ;; 55 esac 56 57 # Test for bad ld. 58 if ld --version 2>&1 | grep 'gold.* 2\.20' >/dev/null; then 59 echo 'ERROR: Your system has gold 2.20 installed.' 60 echo 'This version is shipped by Ubuntu even though' 61 echo 'it is known not to work on Ubuntu.' 62 echo 'Binaries built with this linker are likely to fail in mysterious ways.' 63 echo 64 echo 'Run sudo apt-get remove binutils-gold.' 65 echo 66 exit 1 67 fi 68 69 # Test for bad SELinux. 70 # On Fedora 16 the selinux filesystem is mounted at /sys/fs/selinux, 71 # so loop through the possible selinux mount points. 72 for se_mount in /selinux /sys/fs/selinux 73 do 74 if [ -d $se_mount -a -f $se_mount/booleans/allow_execstack -a -x /usr/sbin/selinuxenabled ] && /usr/sbin/selinuxenabled; then 75 if ! cat $se_mount/booleans/allow_execstack | grep -c '^1 1$' >> /dev/null ; then 76 echo "WARNING: the default SELinux policy on, at least, Fedora 12 breaks " 77 echo "Go. You can enable the features that Go needs via the following " 78 echo "command (as root):" 79 echo " # setsebool -P allow_execstack 1" 80 echo 81 echo "Note that this affects your system globally! " 82 echo 83 echo "The build will continue in five seconds in case we " 84 echo "misdiagnosed the issue..." 85 86 sleep 5 87 fi 88 fi 89 done 90 91 # Test for debian/kFreeBSD. 92 # cmd/dist will detect kFreeBSD as freebsd/$GOARCH, but we need to 93 # disable cgo manually. 94 if [ "$(uname -s)" == "GNU/kFreeBSD" ]; then 95 export CGO_ENABLED=0 96 fi 97 98 # Clean old generated file that will cause problems in the build. 99 rm -f ./pkg/runtime/runtime_defs.go 100 101 # Finally! Run the build. 102 103 echo '# Building C bootstrap tool.' 104 echo cmd/dist 105 export GOROOT="$(cd .. && pwd)" 106 GOROOT_FINAL="${GOROOT_FINAL:-$GOROOT}" 107 DEFGOROOT='-DGOROOT_FINAL="'"$GOROOT_FINAL"'"' 108 109 mflag="" 110 case "$GOHOSTARCH" in 111 386) mflag=-m32;; 112 amd64) mflag=-m64;; 113 esac 114 if [ "$(uname)" == "Darwin" ]; then 115 # golang.org/issue/5261 116 mflag="$mflag -mmacosx-version-min=10.6" 117 fi 118 ${CC:-gcc} $mflag -O2 -Wall -Werror -o cmd/dist/dist -Icmd/dist "$DEFGOROOT" cmd/dist/*.c 119 120 # -e doesn't propagate out of eval, so check success by hand. 121 eval $(./cmd/dist/dist env -p || echo FAIL=true) 122 if [ "$FAIL" = true ]; then 123 exit 1 124 fi 125 126 echo 127 128 if [ "$1" = "--dist-tool" ]; then 129 # Stop after building dist tool. 130 mkdir -p "$GOTOOLDIR" 131 if [ "$2" != "" ]; then 132 cp cmd/dist/dist "$2" 133 fi 134 mv cmd/dist/dist "$GOTOOLDIR"/dist 135 exit 0 136 fi 137 138 echo "# Building compilers and Go bootstrap tool for host, $GOHOSTOS/$GOHOSTARCH." 139 buildall="-a" 140 if [ "$1" = "--no-clean" ]; then 141 buildall="" 142 fi 143 ./cmd/dist/dist bootstrap $buildall -v # builds go_bootstrap 144 # Delay move of dist tool to now, because bootstrap may clear tool directory. 145 mv cmd/dist/dist "$GOTOOLDIR"/dist 146 "$GOTOOLDIR"/go_bootstrap clean -i std 147 echo 148 149 if [ "$GOHOSTARCH" != "$GOARCH" -o "$GOHOSTOS" != "$GOOS" ]; then 150 echo "# Building packages and commands for host, $GOHOSTOS/$GOHOSTARCH." 151 GOOS=$GOHOSTOS GOARCH=$GOHOSTARCH \ 152 "$GOTOOLDIR"/go_bootstrap install -ccflags "$GO_CCFLAGS" -gcflags "$GO_GCFLAGS" -ldflags "$GO_LDFLAGS" -v std 153 echo 154 fi 155 156 echo "# Building packages and commands for $GOOS/$GOARCH." 157 "$GOTOOLDIR"/go_bootstrap install $GO_FLAGS -ccflags "$GO_CCFLAGS" -gcflags "$GO_GCFLAGS" -ldflags "$GO_LDFLAGS" -v std 158 echo 159 160 rm -f "$GOTOOLDIR"/go_bootstrap 161 162 if [ "$1" != "--no-banner" ]; then 163 "$GOTOOLDIR"/dist banner 164 fi