github.com/megatontech/mynoteforgo@v0.0.0-20200507084910-5d0c6ea6e890/源码/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  # (Or just pass them to the make.bash command line.)
    54  #
    55  # GOBUILDTIMELOGFILE: If set, make.bash and all.bash write
    56  # timing information to this file. Useful for profiling where the
    57  # time goes when these scripts run.
    58  #
    59  # GOROOT_BOOTSTRAP: A working Go tree >= Go 1.4 for bootstrap.
    60  # If $GOROOT_BOOTSTRAP/bin/go is missing, $(go env GOROOT) is
    61  # tried for all "go" in $PATH. $HOME/go1.4 by default.
    62  
    63  set -e
    64  
    65  unset GOBIN # Issue 14340
    66  unset GOFLAGS
    67  unset GO111MODULE
    68  
    69  if [ ! -f run.bash ]; then
    70  	echo 'make.bash must be run from $GOROOT/src' 1>&2
    71  	exit 1
    72  fi
    73  
    74  if [ "$GOBUILDTIMELOGFILE" != "" ]; then
    75  	echo $(LC_TIME=C date) start make.bash >"$GOBUILDTIMELOGFILE"
    76  fi
    77  
    78  # Test for Windows.
    79  case "$(uname)" in
    80  *MINGW* | *WIN32* | *CYGWIN*)
    81  	echo 'ERROR: Do not use make.bash to build on Windows.'
    82  	echo 'Use make.bat instead.'
    83  	echo
    84  	exit 1
    85  	;;
    86  esac
    87  
    88  # Test for bad ld.
    89  if ld --version 2>&1 | grep 'gold.* 2\.20' >/dev/null; then
    90  	echo 'ERROR: Your system has gold 2.20 installed.'
    91  	echo 'This version is shipped by Ubuntu even though'
    92  	echo 'it is known not to work on Ubuntu.'
    93  	echo 'Binaries built with this linker are likely to fail in mysterious ways.'
    94  	echo
    95  	echo 'Run sudo apt-get remove binutils-gold.'
    96  	echo
    97  	exit 1
    98  fi
    99  
   100  # Test for bad SELinux.
   101  # On Fedora 16 the selinux filesystem is mounted at /sys/fs/selinux,
   102  # so loop through the possible selinux mount points.
   103  for se_mount in /selinux /sys/fs/selinux
   104  do
   105  	if [ -d $se_mount -a -f $se_mount/booleans/allow_execstack -a -x /usr/sbin/selinuxenabled ] && /usr/sbin/selinuxenabled; then
   106  		if ! cat $se_mount/booleans/allow_execstack | grep -c '^1 1$' >> /dev/null ; then
   107  			echo "WARNING: the default SELinux policy on, at least, Fedora 12 breaks "
   108  			echo "Go. You can enable the features that Go needs via the following "
   109  			echo "command (as root):"
   110  			echo "  # setsebool -P allow_execstack 1"
   111  			echo
   112  			echo "Note that this affects your system globally! "
   113  			echo
   114  			echo "The build will continue in five seconds in case we "
   115  			echo "misdiagnosed the issue..."
   116  
   117  			sleep 5
   118  		fi
   119  	fi
   120  done
   121  
   122  # Test for debian/kFreeBSD.
   123  # cmd/dist will detect kFreeBSD as freebsd/$GOARCH, but we need to
   124  # disable cgo manually.
   125  if [ "$(uname -s)" = "GNU/kFreeBSD" ]; then
   126  	export CGO_ENABLED=0
   127  fi
   128  
   129  # Clean old generated file that will cause problems in the build.
   130  rm -f ./runtime/runtime_defs.go
   131  
   132  # Finally!  Run the build.
   133  
   134  verbose=false
   135  vflag=""
   136  if [ "$1" = "-v" ]; then
   137  	verbose=true
   138  	vflag=-v
   139  	shift
   140  fi
   141  
   142  export GOROOT_BOOTSTRAP=${GOROOT_BOOTSTRAP:-$HOME/go1.4}
   143  export GOROOT="$(cd .. && pwd)"
   144  IFS=$'\n'; for go_exe in $(type -ap go); do
   145  	if [ ! -x "$GOROOT_BOOTSTRAP/bin/go" ]; then
   146  		goroot=$(GOROOT='' GOOS='' GOARCH='' "$go_exe" env GOROOT)
   147  		if [ "$goroot" != "$GOROOT" ]; then
   148  			GOROOT_BOOTSTRAP=$goroot
   149  		fi
   150  	fi
   151  done; unset IFS
   152  echo "Building Go cmd/dist using $GOROOT_BOOTSTRAP."
   153  if $verbose; then
   154  	echo cmd/dist
   155  fi
   156  if [ ! -x "$GOROOT_BOOTSTRAP/bin/go" ]; then
   157  	echo "ERROR: Cannot find $GOROOT_BOOTSTRAP/bin/go." >&2
   158  	echo "Set \$GOROOT_BOOTSTRAP to a working Go tree >= Go 1.4." >&2
   159  	exit 1
   160  fi
   161  if [ "$GOROOT_BOOTSTRAP" = "$GOROOT" ]; then
   162  	echo "ERROR: \$GOROOT_BOOTSTRAP must not be set to \$GOROOT" >&2
   163  	echo "Set \$GOROOT_BOOTSTRAP to a working Go tree >= Go 1.4." >&2
   164  	exit 1
   165  fi
   166  rm -f cmd/dist/dist
   167  GOROOT="$GOROOT_BOOTSTRAP" GOOS="" GOARCH="" "$GOROOT_BOOTSTRAP/bin/go" build -o cmd/dist/dist ./cmd/dist
   168  
   169  # -e doesn't propagate out of eval, so check success by hand.
   170  eval $(./cmd/dist/dist env -p || echo FAIL=true)
   171  if [ "$FAIL" = true ]; then
   172  	exit 1
   173  fi
   174  
   175  if $verbose; then
   176  	echo
   177  fi
   178  
   179  if [ "$1" = "--dist-tool" ]; then
   180  	# Stop after building dist tool.
   181  	mkdir -p "$GOTOOLDIR"
   182  	if [ "$2" != "" ]; then
   183  		cp cmd/dist/dist "$2"
   184  	fi
   185  	mv cmd/dist/dist "$GOTOOLDIR"/dist
   186  	exit 0
   187  fi
   188  
   189  buildall="-a"
   190  if [ "$1" = "--no-clean" ]; then
   191  	buildall=""
   192  	shift
   193  fi
   194  
   195  # Run dist bootstrap to complete make.bash.
   196  # Bootstrap installs a proper cmd/dist, built with the new toolchain.
   197  # Throw ours, built with Go 1.4, away after bootstrap.
   198  ./cmd/dist/dist bootstrap $buildall $vflag $GO_DISTFLAGS "$@"
   199  rm -f ./cmd/dist/dist
   200  
   201  # DO NOT ADD ANY NEW CODE HERE.
   202  # The bootstrap+rm above are the final step of make.bash.
   203  # If something must be added, add it to cmd/dist's cmdbootstrap,
   204  # to avoid needing three copies in three different shell languages
   205  # (make.bash, make.bat, make.rc).