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