</dt>
<dd>
The location where binaries will be installed.
- If you set <code>$GOBIN</code>, you need to ensure that it
- is in your <code>$PATH</code> so that newly built Go-specific
- command such as the compiler can be found during the build.
- The default, <code>$HOME/bin</code>, may already be in your <code>$PATH</code>.
+ The default is <code>$HOME/bin</code>.
+ After installing, you will want to arrange to add this
+ directory to your <code>$PATH</code>, so you can use the tools.
</dd>
</dl>
</p>
<p>
-To build the Go distribution, make sure <code>$GOBIN</code>
-(or <code>$HOME/bin</code> if <code>$GOBIN</code> is not set)
-is in your <code>$PATH</code> and then run
+To build the Go distribution, run
</p>
<pre>
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.
+GOBIN="${GOBIN:-$HOME/bin}"
+
. "$GOROOT"/src/Make.$GOARCH
if [ -z "$O" ]; then
; do
BASE=$(basename $i .go)
- $GC $i
+ "$GOBIN"/$GC $i
done
function testit {
- $LD $1.$O
+ "$GOBIN"/$LD $1.$O
x=$(echo $(./$O.out $2 2>&1)) # extra echo canonicalizes
if [ "$x" != "$3" ]
then
}
function testitpipe {
- $LD $1.$O
+ "$GOBIN"/$LD $1.$O
x=$(echo $(./$O.out | $2 2>&1)) # extra echo canonicalizes
if [ "$x" != "$3" ]
then
testitpipe sieve "sed 10q" "2 3 5 7 11 13 17 19 23 29"
# server hangs; don't run it, just compile it
-$GC server.go
+"$GOBIN"/$GC server.go
testit server1 "" ""
rm -f $O.out *.$O
include ../../../src/Make.pkg
%: install %.go
- $(GC) $*.go
- $(LD) -o $@ $*.$O
+ $(QUOTED_GOBIN)/$(GC) $*.go
+ $(QUOTED_GOBIN)/$(LD) -o $@ $*.$O
# license that can be found in the LICENSE file.
set -e
-gomake hello fib chain
+GOBIN="${GOBIN:-$HOME/bin}"
+"$GOBIN"/gomake hello fib chain
echo '*' hello >run.out
./hello >>run.out
echo '*' fib >>run.out
echo '*' chain >>run.out
./chain >>run.out
diff run.out golden.out
-gomake clean
+"$GOBIN"/gomake clean
all: $(TARG)
$(TARG): _go_.$O $(OFILES)
- $(LD) -o $@ _go_.$O $(OFILES)
+ $(QUOTED_GOBIN)/$(LD) -o $@ _go_.$O $(OFILES)
_go_.$O: $(GOFILES)
- $(GC) -o $@ $(GOFILES)
+ $(QUOTED_GOBIN)/$(GC) -o $@ $(GOFILES)
install: $(QUOTED_GOBIN)/$(TARG)
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.
-CC=quietgcc
-LD=quietgcc
CFLAGS=-ggdb -I"$(GOROOT)"/include -O2 -fno-inline
O=o
YFLAGS=-d
space := $(nullstring) # a space at the end
QUOTED_HOME=$(subst $(space),\ ,$(HOME))
GOBIN=$(QUOTED_HOME)/bin
+QUOTED_GOBIN=$(subst $(space),\ ,$(GOBIN))
+else
+nullstring :=
+space := $(nullstring) # a space at the end
+QUOTED_GOBIN=$(subst $(space),\ ,$(GOBIN))
endif
+
+CC=$(QUOTED_GOBIN)/quietgcc
+LD=$(QUOTED_GOBIN)/quietgcc
PWD=$(shell pwd)
%.$O: %.c
package: _obj/$(TARG).a
testpackage: _test/$(TARG).a
+ifndef GOBIN
+nullstring :=
+space := $(nullstring) # a space at the end
+QUOTED_HOME=$(subst $(space),\ ,$(HOME))
+GOBIN=$(QUOTED_HOME)/bin
+QUOTED_GOBIN=$(subst $(space),\ ,$(GOBIN))
+else
+nullstring :=
+space := $(nullstring) # a space at the end
+QUOTED_GOBIN=$(subst $(space),\ ,$(GOBIN))
+endif
+
# GNU Make 3.80 has a bug in lastword
# elem=$(lastword $(subst /, ,$(TARG)))
TARG_words=$(subst /, ,$(TARG))
PREREQ+=$(patsubst %,%.make,$(DEPS))
coverage:
- gotest
- 6cov -g $(shell pwd) $O.out | grep -v '_test\.go:'
+ $(QUOTED_GOBIN)/gotest
+ $(QUOTED_GOBIN)/6cov -g $(shell pwd) $O.out | grep -v '_test\.go:'
clean:
rm -rf *.[$(OS)o] *.a [$(OS)].out *.cgo[12].go *.cgo[34].c *.so _obj _test _testmain.go $(CLEANFILES)
test:
- gotest
+ $(QUOTED_GOBIN)/gotest
nuke: clean
rm -f $(pkgdir)/$(TARG).a
cp _obj/$(TARG).a "$@"
_go_.$O: $(GOFILES) $(PREREQ)
- $(GC) -o $@ $(GOFILES)
+ $(QUOTED_GOBIN)/$(GC) -o $@ $(GOFILES)
_gotest_.$O: $(GOFILES) $(GOTESTFILES) $(PREREQ)
- $(GC) -o $@ $(GOFILES) $(GOTESTFILES)
+ $(QUOTED_GOBIN)/$(GC) -o $@ $(GOFILES) $(GOTESTFILES)
_obj/$(TARG).a: _go_.$O $(OFILES)
@mkdir -p _obj/$(dir)
rm -f _obj/$(TARG).a
- gopack grc $@ _go_.$O $(OFILES)
+ $(QUOTED_GOBIN)/gopack grc $@ _go_.$O $(OFILES)
_test/$(TARG).a: _gotest_.$O $(OFILES)
@mkdir -p _test/$(dir)
rm -f _test/$(TARG).a
- gopack grc $@ _gotest_.$O $(OFILES)
+ $(QUOTED_GOBIN)/gopack grc $@ _gotest_.$O $(OFILES)
importpath:
@echo $(TARG)
@echo $(dir)
%.make:
- (cd $* && gomake)
+ (cd $* && $(QUOTED_GOBIN)/gomake)
# To use cgo in a Go package, add a line
#
# x.cgo4.c - C implementations compiled with gcc to create dynamic library
#
%.cgo1.go %.cgo2.go %.cgo3.c %.cgo4.c: %.go
- CGOPKGPATH=$(dir) cgo $(CGO_CFLAGS) $*.go
+ CGOPKGPATH=$(dir) $(QUOTED_GOBIN)/cgo $(CGO_CFLAGS) $*.go
# The rules above added x.cgo1.go and x.cgo2.go to $(GOFILES),
# added x.cgo3.$O to $OFILES, and added the installed copy of
RUNTIME_CFLAGS_amd64=-D_64BIT
RUNTIME_CFLAGS=-I"$(GOROOT)/src/pkg/runtime" $(RUNTIME_CFLAGS_$(GOARCH))
%.cgo3.$O: %.cgo3.c
- $(CC) $(CFLAGS) $(RUNTIME_CFLAGS) $*.cgo3.c
+ $(QUOTED_GOBIN)/$(CC) $(CFLAGS) $(RUNTIME_CFLAGS) $*.cgo3.c
# Have to run gcc with the right size argument on hybrid 32/64 machines.
_CGO_CFLAGS_386=-m32
# These come last so that the rules above can override them
# for more specific file names.
%.$O: %.c
- $(CC) $(CFLAGS) $*.c
+ $(QUOTED_GOBIN)/$(CC) $(CFLAGS) $*.c
%.$O: %.s
- $(AS) $*.s
+ $(QUOTED_GOBIN)/$(AS) $*.s
%.$O: $(HFILES)
+# GNU Make syntax:
+nullstring :=
+space := $(nullstring) # a space at the end
+QUOTED_GOROOT=$(subst $(space),\ ,$(GOROOT))
+
all: build run
build:
- bash $(GOROOT)/src/make.bash
+ bash $(QUOTED_GOROOT)/src/make.bash
run:
- bash $(GOROOT)/src/run.bash
+ bash $(QUOTED_GOROOT)/src/run.bash
clean:
- bash $(GOROOT)/src/clean.bash
+ bash $(QUOTED_GOROOT)/src/clean.bash
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.
+GOBIN="${GOBIN:-$HOME/bin}"
+
rm -rf "$GOROOT"/pkg/${GOOS}_$GOARCH
rm -f "$GOROOT"/lib/*.a
for i in lib9 libbio libcgo libmach cmd pkg \
../misc/cgo/gmp ../misc/cgo/stdio \
../test/bench
do(
- cd $i || exit 1
+ cd "$GOROOT"/src/$i || exit 1
if test -f clean.bash; then
bash clean.bash
else
- gomake clean
+ "$GOBIN"/gomake clean
fi
)done
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.
+GOBIN="${GOBIN:-$HOME/bin}"
+
for i in cc 6l 6a 6c 8l 8a 8c 8g 5l 5a 5c 5g gc 6g gopack nm cgo cov ebnflint godefs godoc gofmt gotest goyacc hgpatch prof
do
cd $i
- gomake clean
+ "$GOBIN"/gomake clean
cd ..
done
include ../../Make.cmd
test: $(TARG)
- $(TARG) -start="SourceFile" "$(GOROOT)"/doc/go_spec.html
+ $(QUOTED_GOBIN)/$(TARG) -start="SourceFile" "$(GOROOT)"/doc/go_spec.html
set -e
+GOBIN="${GOBIN:-$HOME/bin}"
+
. "$GOROOT"/src/Make.$GOARCH
if [ -z "$GC" ]; then
echo 'missing $GC - maybe no Make.$GOARCH?' 1>&2
rm -f _builtin.c
for i in runtime unsafe
do
- $GC -A $i.go
+ "$GOBIN"/$GC -A $i.go
O=$O ./mkbuiltin1 $i >>_builtin.c
done
export LC_ALL=C
export LC_CTYPE=C
+GOBIN="${GOBIN:-$HOME/bin}"
+
_GC=$GC # Make.$GOARCH will overwrite this
if [ ! -f [Mm]akefile ]; then
set -e
-gomake testpackage-clean
-gomake testpackage "GOTESTFILES=$gofiles"
+"$GOBIN"/gomake testpackage-clean
+"$GOBIN"/gomake testpackage "GOTESTFILES=$gofiles"
if $havex; then
- $GC -o $xofile $xgofiles
+ "$GOBIN"/$GC -o $xofile $xgofiles
fi
# They all compile; now generate the code to call them.
MAKEFLAGS=
MAKELEVEL=
-importpath=$(gomake -s importpath)
+importpath=$("$GOBIN"/gomake -s importpath)
{
# test functions are named TestFoo
# the grep -v eliminates methods and other special names
# that have multiple dots.
pattern='Test([^a-z].*)?'
- tests=$(6nm -s _test/$importpath.a $xofile | egrep ' T .*·'$pattern'$' | grep -v '·.*[.·]' | sed 's/.* //; s/·/./')
+ tests=$("$GOBIN"/6nm -s _test/$importpath.a $xofile | egrep ' T .*·'$pattern'$' | grep -v '·.*[.·]' | sed 's/.* //; s/·/./')
if [ "x$tests" = x ]; then
echo 'gotest: error: no tests matching '$pattern in _test/$importpath.a $xofile 1>&2
exit 2
fi
# benchmarks are named BenchmarkFoo.
pattern='Benchmark([^a-z].*)?'
- benchmarks=$(6nm -s _test/$importpath.a $xofile | egrep ' T .*·'$pattern'$' | grep -v '·.*[.·]' | sed 's/.* //; s/·/./')
+ benchmarks=$("$GOBIN"/6nm -s _test/$importpath.a $xofile | egrep ' T .*·'$pattern'$' | grep -v '·.*[.·]' | sed 's/.* //; s/·/./')
# package spec
echo 'package main'
echo '}'
}>_testmain.go
-$GC _testmain.go
-$GL _testmain.$O
+"$GOBIN"/$GC _testmain.go
+"$GOBIN"/$GL _testmain.$O
$E ./$O.out "$@"
bash clean.bash
+GOBIN="${GOBIN:-$HOME/bin}"
+
. "$GOROOT"/src/Make.$GOARCH
if [ -z "$O" ]; then
echo 'missing $O - maybe no Make.$GOARCH?' 1>&2
cd ${O}l
bash mkenam
-gomake enam.o
+"$GOBIN"/gomake enam.o
cd ..
for i in cc ${O}l ${O}a ${O}c gc ${O}g gopack nm cov godefs prof gotest
do
echo; echo; echo %%%% making $i %%%%; echo
cd $i
- gomake install
+ "$GOBIN"/gomake install
cd ..
done
# license that can be found in the LICENSE file.
set -e
+
+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
+
GOBIN="${GOBIN:-$HOME/bin}"
export MAKEFLAGS=-j4
exit 1
fi
-if ! 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
-
case "$GOARCH" in
arm)
;;
bash clean.bash
-rm -f $GOBIN/quietgcc
-cp quietgcc.bash $GOBIN/quietgcc
-chmod +x $GOBIN/quietgcc
+rm -f "$GOBIN"/quietgcc
+cp quietgcc.bash "$GOBIN"/quietgcc
+chmod +x "$GOBIN"/quietgcc
-rm -f $GOBIN/gomake
+rm -f "$GOBIN"/gomake
MAKE=make
if ! make --version 2>/dev/null | grep 'GNU Make' >/dev/null; then
MAKE=gmake
fi
-(echo '#!/bin/sh'; echo 'exec '$MAKE' "$@"') >$GOBIN/gomake
-chmod +x $GOBIN/gomake
+(echo '#!/bin/sh'; echo 'exec '$MAKE' "$@"') >"$GOBIN"/gomake
+chmod +x "$GOBIN"/gomake
bash clean.bash
# license that can be found in the LICENSE file.
set -e
+
+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
+
GOBIN="${GOBIN:-$HOME/bin}"
export MAKEFLAGS=-j4
exit 1
fi
-if ! 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
-
case "$GOARCH" in
amd64 | 386 | arm)
;;
rm -f "$GOBIN"/quietgcc
CC=${CC:-gcc}
-sed -e "s|@CC@|$CC|" < quietgcc.bash > "$GOBIN"/quietgcc
+sed -e "s|@CC@|$CC|" < "$GOROOT"/src/quietgcc.bash > "$GOBIN"/quietgcc
chmod +x "$GOBIN"/quietgcc
rm -f "$GOBIN"/gomake
(echo '#!/bin/sh'; echo 'exec '$MAKE' "$@"') >"$GOBIN"/gomake
chmod +x "$GOBIN"/gomake
-if ! (cd lib9 && which quietgcc) >/dev/null 2>&1; then
- echo "installed quietgcc as $GOBIN/quietgcc but 'which quietgcc' fails" 1>&2
- echo "double-check that $GOBIN is in your "'$PATH' 1>&2
- exit 1
-fi
-
if [ -d /selinux -a -f /selinux/booleans/allow_execstack ] ; then
if ! cat /selinux/booleans/allow_execstack | grep -c '^1 1$' >> /dev/null ; then
echo "WARNING: the default SELinux policy on, at least, Fedora 12 breaks "
fi
(
- cd pkg;
+ cd "$GOROOT"/src/pkg;
bash deps.bash # do this here so clean.bash will work in the pkg directory
)
-bash clean.bash
+bash "$GOROOT"/src/clean.bash
for i in lib9 libbio libmach cmd pkg libcgo cmd/cgo cmd/ebnflint cmd/godoc cmd/gofmt cmd/goyacc cmd/hgpatch
do
# test the exit status.
(
echo; echo; echo %%%% making $i %%%%; echo
- cd $i
+ cd "$GOROOT"/src/$i
case $i in
cmd)
bash make.bash
;;
pkg)
- gomake install
+ "$GOBIN"/gomake install
;;
*)
- gomake install
+ "$GOBIN"/gomake install
esac
) || exit 1
esac
# line and do not contain imports.
set -e
-make
-6g main.go && 6l main.6
+
+GOBIN="${GOBIN:-$HOME/bin}"
+
+"$GOBIN"/gomake
+"$GOBIN"/6g main.go && "$GOBIN"/6l main.6
(
for i in $(egrep -l '// \$G (\$D/)?\$F\.go \&\& \$L \$F\.\$A && \./\$A\.out' "$GOROOT"/test/*.go "$GOROOT"/test/*/*.go)
do
include ../../../Make.pkg
main.$O: main.go package
- $(GC) -I_obj $<
+ $(QUOTED_GOBIN)/$(GC) -I_obj $<
ogle: main.$O
- $(LD) -L_obj -o $@ $<
+ $(QUOTED_GOBIN)/$(LD) -L_obj -o $@ $<
mv -f $@.x $@
cgo2c: cgo2c.c
- quietgcc -o $@ $<
+ $(QUOTED_GOBIN)/quietgcc -o $@ $<
%.c: %.cgo cgo2c
./cgo2c $< > $@.tmp
mv -f $@.tmp $@
%.$O: $(GOARCH)/%.c
- $(CC) $(CFLAGS) $<
+ $(QUOTED_GOBIN)/$(CC) $(CFLAGS) $<
%.$O: $(GOOS)/%.c
- $(CC) $(CFLAGS) $<
+ $(QUOTED_GOBIN)/$(CC) $(CFLAGS) $<
%.$O: $(GOOS)/$(GOARCH)/%.c
- $(CC) $(CFLAGS) $<
+ $(QUOTED_GOBIN)/$(CC) $(CFLAGS) $<
%.$O: $(GOARCH)/%.s $(GOARCH)/asm.h
- $(AS) $<
+ $(QUOTED_GOBIN)/$(AS) $<
%.$O: $(GOOS)/$(GOARCH)/%.s $(GOARCH)/asm.h
- $(AS) $<
+ $(QUOTED_GOBIN)/$(AS) $<
# for discovering offsets inside structs when debugging
runtime.acid.$(GOARCH): runtime.h proc.c
- $(CC) -a proc.c >$@
+ $(QUOTED_GOBIN)/$(CC) -a proc.c >$@
set -e
+GOBIN="${GOBIN:-$HOME/bin}"
+
# no core files, please
ulimit -c 0
xcd() {
echo
echo --- cd $1
- builtin cd $1
+ builtin cd "$GOROOT"/src/$1
}
maketest() {
do
(
xcd $i
- gomake clean
- time gomake
- gomake install
- gomake test
+ "$GOBIN"/gomake clean
+ time "$GOBIN"/gomake
+ "$GOBIN"/gomake install
+ "$GOBIN"/gomake test
) || exit $?
done
}
# from what maketest does.
(xcd pkg/sync;
-gomake clean;
-time gomake
-GOMAXPROCS=10 gomake test
+"$GOBIN"/gomake clean;
+time "$GOBIN"/gomake
+GOMAXPROCS=10 "$GOBIN"/gomake test
) || exit $?
(xcd cmd/gofmt
-gomake clean
-time gomake
-time gomake smoketest
+"$GOBIN"/gomake clean
+time "$GOBIN"/gomake
+time "$GOBIN"/gomake smoketest
) || exit $?
(xcd cmd/ebnflint
-gomake clean
-time gomake
-time gomake test
+"$GOBIN"/gomake clean
+time "$GOBIN"/gomake
+time "$GOBIN"/gomake test
) || exit $?
(xcd ../misc/cgo/stdio
-gomake clean
+"$GOBIN"/gomake clean
./test.bash
) || exit $?
(xcd pkg/exp/ogle
-gomake clean
-time gomake ogle
+"$GOBIN"/gomake clean
+time "$GOBIN"/gomake ogle
) || exit $?
(xcd ../doc/progs
# license that can be found in the LICENSE file.
set -e
+
+GOBIN="${GOBIN:-$HOME/bin}"
+
. "$GOROOT"/src/Make.$GOARCH
PATH=.:$PATH
esac
gc() {
- $GC $1.go; $LD $1.$O
+ "$GOBIN"/$GC $1.go; "$GOBIN"/$LD $1.$O
}
gc_B() {
- $GC -B $1.go; $LD $1.$O
+ "$GOBIN"/$GC -B $1.go; "$GOBIN"/$LD $1.$O
}
runonly() {