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 # If set to a Windows-style path convert to an MSYS-Unix
7 # one using the built-in shell commands.
8 if [[ "$GOROOT" == *:* ]]; then
9 GOROOT=$(cd "$GOROOT"; pwd)
10 fi
11
12 if [[ "$GOBIN" == *:* ]]; then
13 GOBIN=$(cd "$GOBIN"; pwd)
14 fi
15
16 export GOROOT=${GOROOT:-$(cd ..; pwd)}
17
18 if ! test -f "$GOROOT"/include/u.h
19 then
20 echo '$GOROOT is not set correctly or not exported: '$GOROOT 1>&2
21 exit 1
22 fi
23
24 # Double-check that we're in $GOROOT, for people with multiple Go trees.
25 # Various aspects of the build cd into $GOROOT-rooted paths,
26 # making it easy to jump to a different tree and get confused.
27 DIR1=$(cd ..; pwd)
28 DIR2=$(cd "$GOROOT"; pwd)
29 if [ "$DIR1" != "$DIR2" ]; then
30 echo 'Suspicious $GOROOT '"$GOROOT"': does not match current directory.' 1>&2
31 exit 1
32 fi
33
34 export GOBIN=${GOBIN:-"$GOROOT/bin"}
35 if [ ! -d "$GOBIN" -a "$GOBIN" != "$GOROOT/bin" ]; then
36 echo '$GOBIN is not a directory or does not exist' 1>&2
37 echo 'create it or set $GOBIN differently' 1>&2
38 exit 1
39 fi
40
41 export OLDPATH=$PATH
42 export PATH="$GOBIN":$PATH
43
44 MAKE=make
45 if ! make --version 2>/dev/null | grep 'GNU Make' >/dev/null; then
46 MAKE=gmake
47 fi
48
49 PROGS="
50 ar
51 awk
52 bash
53 bison
54 chmod
55 cp
56 cut
57 echo
58 egrep
59 gcc
60 grep
61 ls
62 mkdir
63 mv
64 pwd
65 rm
66 sed
67 sort
68 tee
69 touch
70 tr
71 true
72 uname
73 uniq
74 "
75
76 for i in $PROGS; do
77 if ! which $i >/dev/null 2>&1; then
78 echo "Cannot find '$i' on search path." 1>&2
79 echo "See http://golang.org/doc/install.html#ctools" 1>&2
80 exit 1
81 fi
82 done
83
84 if bison --version 2>&1 | grep 'bison++' >/dev/null 2>&1; then
85 echo "Your system's 'bison' is bison++."
86 echo "Go needs the original bison instead." 1>&2
87 echo "See http://golang.org/doc/install.html#ctools" 1>&2
88 exit 1
89 fi
90
91 # Issue 2020: some users configure bash to default to
92 # set -o noclobber
93 # which makes >x fail if x already exists. Restore sanity.
94 set +o noclobber
95
96 # Tried to use . <($MAKE ...) here, but it cannot set environment
97 # variables in the version of bash that ships with OS X. Amazing.
98 eval $($MAKE --no-print-directory -f Make.inc go-env | egrep 'GOARCH|GOOS|GOHOSTARCH|GOHOSTOS|GO_ENV')
99
100 # Shell doesn't tell us whether make succeeded,
101 # so Make.inc generates a fake variable name.
102 if [ "$MAKE_GO_ENV_WORKED" != 1 ]; then
103 echo 'Did not find Go environment variables.' 1>&2
104 exit 1
105 fi
106 unset MAKE_GO_ENV_WORKED