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