Russ Cox | 69fd2a4 | 2010-03-31 19:48:33 -0700 | [diff] [blame] | 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 | |
Russ Cox | da392d9 | 2010-08-18 10:08:49 -0400 | [diff] [blame] | 6 | export GOROOT=${GOROOT:-$(cd ..; pwd)} |
| 7 | |
Russ Cox | 69fd2a4 | 2010-03-31 19:48:33 -0700 | [diff] [blame] | 8 | if ! test -f "$GOROOT"/include/u.h |
| 9 | then |
Russ Cox | da392d9 | 2010-08-18 10:08:49 -0400 | [diff] [blame] | 10 | echo '$GOROOT is not set correctly or not exported: '$GOROOT 1>&2 |
Russ Cox | 69fd2a4 | 2010-03-31 19:48:33 -0700 | [diff] [blame] | 11 | exit 1 |
| 12 | fi |
| 13 | |
| 14 | # Double-check that we're in $GOROOT, for people with multiple Go trees. |
| 15 | # Various aspects of the build cd into $GOROOT-rooted paths, |
| 16 | # making it easy to jump to a different tree and get confused. |
| 17 | DIR1=$(cd ..; pwd) |
Alex Brainman | a33ad24 | 2010-09-21 16:43:31 +1000 | [diff] [blame] | 18 | DIR2=$(cd "$GOROOT"; pwd) |
Russ Cox | 69fd2a4 | 2010-03-31 19:48:33 -0700 | [diff] [blame] | 19 | if [ "$DIR1" != "$DIR2" ]; then |
Russ Cox | 9e1ee8f | 2010-11-05 23:04:08 -0400 | [diff] [blame] | 20 | echo 'Suspicious $GOROOT '"$GOROOT"': does not match current directory.' 1>&2 |
Russ Cox | 69fd2a4 | 2010-03-31 19:48:33 -0700 | [diff] [blame] | 21 | exit 1 |
| 22 | fi |
| 23 | |
Russ Cox | aafe474e | 2010-08-24 20:00:33 -0400 | [diff] [blame] | 24 | export GOBIN=${GOBIN:-"$GOROOT/bin"} |
Russ Cox | 5bf658c | 2010-09-02 14:20:02 -0400 | [diff] [blame] | 25 | if [ ! -d "$GOBIN" -a "$GOBIN" != "$GOROOT/bin" ]; then |
Russ Cox | aafe474e | 2010-08-24 20:00:33 -0400 | [diff] [blame] | 26 | echo '$GOBIN is not a directory or does not exist' 1>&2 |
| 27 | echo 'create it or set $GOBIN differently' 1>&2 |
| 28 | exit 1 |
| 29 | fi |
| 30 | |
| 31 | export OLDPATH=$PATH |
Russ Cox | 9e1ee8f | 2010-11-05 23:04:08 -0400 | [diff] [blame] | 32 | export PATH=/bin:/usr/bin:"$GOBIN":$PATH |
Russ Cox | aafe474e | 2010-08-24 20:00:33 -0400 | [diff] [blame] | 33 | |
Russ Cox | da392d9 | 2010-08-18 10:08:49 -0400 | [diff] [blame] | 34 | MAKE=make |
| 35 | if ! make --version 2>/dev/null | grep 'GNU Make' >/dev/null; then |
| 36 | MAKE=gmake |
| 37 | fi |
Russ Cox | 69fd2a4 | 2010-03-31 19:48:33 -0700 | [diff] [blame] | 38 | |
Russ Cox | da392d9 | 2010-08-18 10:08:49 -0400 | [diff] [blame] | 39 | # Tried to use . <($MAKE ...) here, but it cannot set environment |
| 40 | # variables in the version of bash that ships with OS X. Amazing. |
Alex Brainman | 642c774 | 2011-02-09 12:37:08 +1100 | [diff] [blame] | 41 | eval $($MAKE --no-print-directory -f Make.inc go-env | egrep 'GOARCH|GOOS|GOHOSTARCH|GOHOSTOS|GO_ENV') |
Russ Cox | 69fd2a4 | 2010-03-31 19:48:33 -0700 | [diff] [blame] | 42 | |
Russ Cox | da392d9 | 2010-08-18 10:08:49 -0400 | [diff] [blame] | 43 | # Shell doesn't tell us whether make succeeded, |
| 44 | # so Make.inc generates a fake variable name. |
| 45 | if [ "$MAKE_GO_ENV_WORKED" != 1 ]; then |
| 46 | echo 'Did not find Go environment variables.' 1>&2 |
| 47 | exit 1 |
| 48 | fi |
| 49 | unset MAKE_GO_ENV_WORKED |