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