<p><code>$GOBIN</code>
<p>
-The location where binaries from the main repository will be installed.
-XXX THIS MAY CHANGE TO BE AN OVERRIDE EVEN FOR GOPATH ENTRIES XXX
+The location where Go binaries will be installed.
The default is <code>$GOROOT/bin</code>.
After installing, you will want to arrange to add this
directory to your <code>$PATH</code>, so you can use the tools.
+If <code>$GOBIN</code> is set, the <a href="/cmd/go">go command</a>
+installs all commands there.
</p>
<p><code>$GOARM</code> (arm, default=6)</p>
For more about the build flags, see 'go help build'.
For more about specifying packages, see 'go help packages'.
+For more about where packages and binaries are installed,
+see 'go help gopath'.
See also: go build, go get, go clean.
`,
)
var (
+ gobin = os.Getenv("GOBIN")
goroot = filepath.Clean(runtime.GOROOT())
- gobin = defaultGobin()
gorootSrcPkg = filepath.Join(goroot, "src/pkg")
gorootPkg = filepath.Join(goroot, "pkg")
gorootSrc = filepath.Join(goroot, "src")
)
-func defaultGobin() string {
- if s := os.Getenv("GOBIN"); s != "" {
- return s
- }
- return filepath.Join(goroot, "bin")
-}
-
func (b *builder) init() {
var err error
b.print = fmt.Print
pkg.load(&stk, bp, err)
pkg.localPrefix = dirToImportPath(dir)
pkg.ImportPath = "command-line-arguments"
+ pkg.target = ""
- if *buildO == "" {
- if pkg.Name == "main" {
- _, elem := filepath.Split(gofiles[0])
- *buildO = elem[:len(elem)-len(".go")] + exeSuffix
- } else {
+ if pkg.Name == "main" {
+ _, elem := filepath.Split(gofiles[0])
+ exe := elem[:len(elem)-len(".go")] + exeSuffix
+ if *buildO == "" {
+ *buildO = exe
+ }
+ if gobin != "" {
+ pkg.target = filepath.Join(gobin, exe)
+ }
+ } else {
+ if *buildO == "" {
*buildO = pkg.Name + ".a"
}
}
- pkg.target = ""
- pkg.Target = ""
pkg.Stale = true
+ pkg.Target = pkg.target
computeStale(pkg)
return pkg
return a
}
- if p.local {
+ a.link = p.Name == "main"
+ if p.local && (!a.link || p.target == "") {
// Imported via local path. No permanent target.
mode = modeBuild
}
a.objdir = filepath.Join(b.work, a.p.ImportPath, "_obj") + string(filepath.Separator)
a.objpkg = buildToolchain.pkgpath(b.work, a.p)
- a.link = p.Name == "main"
switch mode {
case modeInstall:
command with source in DIR/src/foo/quux is installed into
DIR/bin/quux, not DIR/bin/foo/quux. The foo/ is stripped
so that you can add DIR/bin to your PATH to get at the
-installed commands.
+installed commands. If the GOBIN environment variable is
+set, commands are installed to the directory it names instead
+of DIR/bin.
Here's an example directory layout:
command with source in DIR/src/foo/quux is installed into
DIR/bin/quux, not DIR/bin/foo/quux. The foo/ is stripped
so that you can add DIR/bin to your PATH to get at the
-installed commands.
+installed commands. If the GOBIN environment variable is
+set, commands are installed to the directory it names instead
+of DIR/bin.
Here's an example directory layout:
// load populates p using information from bp, err, which should
// be the result of calling build.Context.Import.
func (p *Package) load(stk *importStack, bp *build.Package, err error) *Package {
+ if gobin != "" {
+ bp.BinDir = gobin
+ }
p.copyBuild(bp)
// The localPrefix is the path we interpret ./ imports relative to.
bp, err := build.ImportDir(filepath.Join(gorootSrc, arg), 0)
bp.ImportPath = arg
bp.Goroot = true
- bp.BinDir = gobin
bp.Root = goroot
bp.SrcRoot = gorootSrc
p := new(Package)