blob: 4fc762821ec6d66a438b9a78f4c329ee824f4914 [file] [log] [blame]
Russ Cox69fd2a42010-03-31 19:48:33 -07001#!/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 Coxda392d92010-08-18 10:08:49 -04006export GOROOT=${GOROOT:-$(cd ..; pwd)}
7
Russ Cox69fd2a42010-03-31 19:48:33 -07008if ! test -f "$GOROOT"/include/u.h
9then
Russ Coxda392d92010-08-18 10:08:49 -040010 echo '$GOROOT is not set correctly or not exported: '$GOROOT 1>&2
Russ Cox69fd2a42010-03-31 19:48:33 -070011 exit 1
12fi
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.
17DIR1=$(cd ..; pwd)
Alex Brainmana33ad242010-09-21 16:43:31 +100018DIR2=$(cd "$GOROOT"; pwd)
Russ Cox69fd2a42010-03-31 19:48:33 -070019if [ "$DIR1" != "$DIR2" ]; then
Russ Cox9e1ee8f2010-11-05 23:04:08 -040020 echo 'Suspicious $GOROOT '"$GOROOT"': does not match current directory.' 1>&2
Russ Cox69fd2a42010-03-31 19:48:33 -070021 exit 1
22fi
23
Russ Coxaafe474e2010-08-24 20:00:33 -040024export GOBIN=${GOBIN:-"$GOROOT/bin"}
Russ Cox5bf658c2010-09-02 14:20:02 -040025if [ ! -d "$GOBIN" -a "$GOBIN" != "$GOROOT/bin" ]; then
Russ Coxaafe474e2010-08-24 20:00:33 -040026 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
29fi
30
31export OLDPATH=$PATH
Russ Cox9e1ee8f2010-11-05 23:04:08 -040032export PATH=/bin:/usr/bin:"$GOBIN":$PATH
Russ Coxaafe474e2010-08-24 20:00:33 -040033
Russ Coxda392d92010-08-18 10:08:49 -040034MAKE=make
35if ! make --version 2>/dev/null | grep 'GNU Make' >/dev/null; then
36 MAKE=gmake
37fi
Russ Cox69fd2a42010-03-31 19:48:33 -070038
Russ Coxda392d92010-08-18 10:08:49 -040039# Tried to use . <($MAKE ...) here, but it cannot set environment
40# variables in the version of bash that ships with OS X. Amazing.
Alex Brainman642c7742011-02-09 12:37:08 +110041eval $($MAKE --no-print-directory -f Make.inc go-env | egrep 'GOARCH|GOOS|GOHOSTARCH|GOHOSTOS|GO_ENV')
Russ Cox69fd2a42010-03-31 19:48:33 -070042
Russ Coxda392d92010-08-18 10:08:49 -040043# Shell doesn't tell us whether make succeeded,
44# so Make.inc generates a fake variable name.
45if [ "$MAKE_GO_ENV_WORKED" != 1 ]; then
46 echo 'Did not find Go environment variables.' 1>&2
47 exit 1
48fi
49unset MAKE_GO_ENV_WORKED