summaryrefslogtreecommitdiff
path: root/src/env.bash
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2010-03-31 19:48:33 -0700
committerRuss Cox <rsc@golang.org>2010-03-31 19:48:33 -0700
commit01adb1764725174c72ecf19623761c0ba03ae29b (patch)
tree61a7e9808e8c19bf7a3a6e37db25f98da1eef010 /src/env.bash
parented3cf90f3df0a181f78da077da6935241846c23e (diff)
downloadgolang-01adb1764725174c72ecf19623761c0ba03ae29b.tar.gz
build script tweaks
factor out environment variable checks. infer $GOROOT etc during build if not set. it's still necessary to set them for yourself to use the standard Makefiles. when running all.bash, don't recompile all the go packages in run.bash, since make.bash already did. R=r CC=golang-dev http://codereview.appspot.com/609042
Diffstat (limited to 'src/env.bash')
-rw-r--r--src/env.bash55
1 files changed, 55 insertions, 0 deletions
diff --git a/src/env.bash b/src/env.bash
new file mode 100644
index 000000000..6ab491ae4
--- /dev/null
+++ b/src/env.bash
@@ -0,0 +1,55 @@
+#!/usr/bin/env bash
+# Copyright 2009 The Go Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style
+# license that can be found in the LICENSE file.
+
+if test -z "$GOBIN"; then
+ if ! test -d "$HOME"/bin; then
+ echo '$GOBIN is not set and $HOME/bin is not a directory or does not exist.' 1>&2
+ echo 'mkdir $HOME/bin or set $GOBIN to a directory where binaries should' 1>&2
+ echo 'be installed.' 1>&2
+ exit 1
+ fi
+ GOBIN="$HOME/bin"
+elif ! test -d "$GOBIN"; then
+ echo '$GOBIN is not a directory or does not exist' 1>&2
+ echo 'create it or set $GOBIN differently' 1>&2
+ exit 1
+fi
+
+GOROOT=${GOROOT:-$(cd ..; pwd)}
+if ! test -f "$GOROOT"/include/u.h
+then
+ echo '$GOROOT is not set correctly or not exported' 1>&2
+ exit 1
+fi
+
+# Double-check that we're in $GOROOT, for people with multiple Go trees.
+# Various aspects of the build cd into $GOROOT-rooted paths,
+# making it easy to jump to a different tree and get confused.
+DIR1=$(cd ..; pwd)
+DIR2=$(cd $GOROOT; pwd)
+if [ "$DIR1" != "$DIR2" ]; then
+ echo 'Suspicious $GOROOT: does not match current directory.' 1>&2
+ exit 1
+fi
+
+GOARCH=${GOARCH:-$(uname -m | sed 's/^..86$/386/; s/^.86$/386/; s/x86_64/amd64/')}
+case "$GOARCH" in
+amd64 | 386 | arm)
+ ;;
+*)
+ echo '$GOARCH is set to <'$GOARCH'>, must be amd64, 386, or arm' 1>&2
+ exit 1
+esac
+
+GOOS=${GOOS:-$(uname | tr A-Z a-z)}
+case "$GOOS" in
+darwin | freebsd | linux | mingw | nacl)
+ ;;
+*)
+ echo '$GOOS is set to <'$GOOS'>, must be darwin, freebsd, linux, mingw, or nacl' 1>&2
+ exit 1
+esac
+
+export GOBIN GOROOT GOARCH GOOS