github.com/MangoDowner/go-gm@v0.0.0-20180818020936-8baa2bd4408c/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 # See golang.org/s/go15bootstrap for an overview of the build process. 7 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 # 22 # GO_GCFLAGS: Additional go tool compile arguments to use when 23 # building the packages and commands. 24 # 25 # GO_LDFLAGS: Additional go tool link arguments to use when 26 # building the commands. 27 # 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. 31 # 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 # 37 # CC: Command line to run to compile C code for GOHOSTARCH. 38 # Default is "gcc". Also supported: "clang". 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++". 46 # 47 # FC: Command line to run to compile Fortran code for GOARCH. 48 # This is used by cgo. Default is "gfortran". 49 # 50 # PKG_CONFIG: Path to pkg-config tool. Default is "pkg-config". 51 # 52 # GO_DISTFLAGS: extra flags to provide to "dist bootstrap". 53 54 set -e 55 56 unset GOBIN # Issue 14340 57 58 if [ ! -f run.bash ]; then 59 echo 'make.bash must be run from $GOROOT/src' 1>&2 60 exit 1 61 fi 62 63 # Test for Windows. 64 case "$(uname)" in 65 *MINGW* | *WIN32* | *CYGWIN*) 66 echo 'ERROR: Do not use make.bash to build on Windows.' 67 echo 'Use make.bat instead.' 68 echo 69 exit 1 70 ;; 71 esac 72 73 # Test for bad ld. 74 if ld --version 2>&1 | grep 'gold.* 2\.20' >/dev/null; then 75 echo 'ERROR: Your system has gold 2.20 installed.' 76 echo 'This version is shipped by Ubuntu even though' 77 echo 'it is known not to work on Ubuntu.' 78 echo 'Binaries built with this linker are likely to fail in mysterious ways.' 79 echo 80 echo 'Run sudo apt-get remove binutils-gold.' 81 echo 82 exit 1 83 fi 84 85 # Test for bad SELinux. 86 # On Fedora 16 the selinux filesystem is mounted at /sys/fs/selinux, 87 # so loop through the possible selinux mount points. 88 for se_mount in /selinux /sys/fs/selinux 89 do 90 if [ -d $se_mount -a -f $se_mount/booleans/allow_execstack -a -x /usr/sbin/selinuxenabled ] && /usr/sbin/selinuxenabled; then 91 if ! cat $se_mount/booleans/allow_execstack | grep -c '^1 1$' >> /dev/null ; then 92 echo "WARNING: the default SELinux policy on, at least, Fedora 12 breaks " 93 echo "Go. You can enable the features that Go needs via the following " 94 echo "command (as root):" 95 echo " # setsebool -P allow_execstack 1" 96 echo 97 echo "Note that this affects your system globally! " 98 echo 99 echo "The build will continue in five seconds in case we " 100 echo "misdiagnosed the issue..." 101 102 sleep 5 103 fi 104 fi 105 done 106 107 # Test for debian/kFreeBSD. 108 # cmd/dist will detect kFreeBSD as freebsd/$GOARCH, but we need to 109 # disable cgo manually. 110 if [ "$(uname -s)" = "GNU/kFreeBSD" ]; then 111 export CGO_ENABLED=0 112 fi 113 114 # Clean old generated file that will cause problems in the build. 115 rm -f ./runtime/runtime_defs.go 116 117 # Finally! Run the build. 118 119 echo '##### Building Go bootstrap tool.' 120 echo cmd/dist 121 export GOROOT="$(cd .. && pwd)" 122 GOROOT_BOOTSTRAP=${GOROOT_BOOTSTRAP:-$HOME/go1.4} 123 if [ ! -x "$GOROOT_BOOTSTRAP/bin/go" ]; then 124 echo "ERROR: Cannot find $GOROOT_BOOTSTRAP/bin/go." >&2 125 echo "Set \$GOROOT_BOOTSTRAP to a working Go tree >= Go 1.4." >&2 126 exit 1 127 fi 128 if [ "$GOROOT_BOOTSTRAP" = "$GOROOT" ]; then 129 echo "ERROR: \$GOROOT_BOOTSTRAP must not be set to \$GOROOT" >&2 130 echo "Set \$GOROOT_BOOTSTRAP to a working Go tree >= Go 1.4." >&2 131 exit 1 132 fi 133 rm -f cmd/dist/dist 134 GOROOT="$GOROOT_BOOTSTRAP" GOOS="" GOARCH="" "$GOROOT_BOOTSTRAP/bin/go" build -o cmd/dist/dist ./cmd/dist 135 136 # -e doesn't propagate out of eval, so check success by hand. 137 eval $(./cmd/dist/dist env -p || echo FAIL=true) 138 if [ "$FAIL" = true ]; then 139 exit 1 140 fi 141 142 echo 143 144 if [ "$1" = "--dist-tool" ]; then 145 # Stop after building dist tool. 146 mkdir -p "$GOTOOLDIR" 147 if [ "$2" != "" ]; then 148 cp cmd/dist/dist "$2" 149 fi 150 mv cmd/dist/dist "$GOTOOLDIR"/dist 151 exit 0 152 fi 153 154 buildall="-a" 155 if [ "$1" = "--no-clean" ]; then 156 buildall="" 157 shift 158 fi 159 ./cmd/dist/dist bootstrap $buildall $GO_DISTFLAGS -v # builds go_bootstrap 160 161 # Delay move of dist tool to now, because bootstrap may clear tool directory. 162 mv cmd/dist/dist "$GOTOOLDIR"/dist 163 echo 164 165 if [ "$GOHOSTARCH" != "$GOARCH" -o "$GOHOSTOS" != "$GOOS" ]; then 166 echo "##### Building packages and commands for host, $GOHOSTOS/$GOHOSTARCH." 167 # CC_FOR_TARGET is recorded as the default compiler for the go tool. When building for the host, however, 168 # use the host compiler, CC, from `cmd/dist/dist env` instead. 169 CC=$CC GOOS=$GOHOSTOS GOARCH=$GOHOSTARCH \ 170 "$GOTOOLDIR"/go_bootstrap install -gcflags "$GO_GCFLAGS" -ldflags "$GO_LDFLAGS" -v std cmd 171 echo 172 fi 173 174 echo "##### Building packages and commands for $GOOS/$GOARCH." 175 176 old_bin_files=$(cd $GOROOT/bin && echo *) 177 178 CC=$CC_FOR_TARGET "$GOTOOLDIR"/go_bootstrap install $GO_FLAGS -gcflags "$GO_GCFLAGS" -ldflags "$GO_LDFLAGS" -v std cmd 179 180 # Check that there are no new files in $GOROOT/bin other than go and gofmt 181 # and $GOOS_$GOARCH (a directory used when cross-compiling). 182 (cd $GOROOT/bin && for f in *; do 183 if ! expr " $old_bin_files go gofmt ${GOOS}_${GOARCH} " : ".* $f " >/dev/null 2>/dev/null; then 184 echo 1>&2 "ERROR: unexpected new file in $GOROOT/bin: $f" 185 exit 1 186 fi 187 done) 188 189 echo 190 191 rm -f "$GOTOOLDIR"/go_bootstrap 192 193 if [ "$1" != "--no-banner" ]; then 194 "$GOTOOLDIR"/dist banner 195 fi