install(p, pkg)
}
}
- if dirInfo.pkgName == "main" {
- if !errors {
- fmt.Fprintf(os.Stderr, "%s: %s's dependencies are installed.\n", argv0, pkg)
- }
- errors = true
- visit[pkg] = done
- return
- }
// Install this package.
if !errors {
- if err := domake(dir, pkg, local); err != nil {
+ isCmd := dirInfo.pkgName == "main"
+ if err := domake(dir, pkg, local, isCmd); err != nil {
fmt.Fprintf(os.Stderr, "%s: installing %s: %s\n", argv0, pkg, err)
errors = true
} else if !local && *logPkgs {
import (
"bytes"
"os"
+ "path/filepath"
"template"
)
// For non-local packages or packages without Makefiles,
// domake generates a standard Makefile and passes it
// to make on standard input.
-func domake(dir, pkg string, local bool) (err os.Error) {
+func domake(dir, pkg string, local, isCmd bool) (err os.Error) {
needMakefile := true
if local {
_, err := os.Stat(dir + "/Makefile")
cmd := []string{"gomake"}
var makefile []byte
if needMakefile {
- if makefile, err = makeMakefile(dir, pkg); err != nil {
+ if makefile, err = makeMakefile(dir, pkg, isCmd); err != nil {
return err
}
cmd = append(cmd, "-f-")
// makeMakefile computes the standard Makefile for the directory dir
// installing as package pkg. It includes all *.go files in the directory
// except those in package main and those ending in _test.go.
-func makeMakefile(dir, pkg string) ([]byte, os.Error) {
- if !safeName(pkg) {
+func makeMakefile(dir, pkg string, isCmd bool) ([]byte, os.Error) {
+ targ := pkg
+ if isCmd {
+ // use the last part of the package name only
+ _, targ = filepath.Split(pkg)
+ // if building the working dir use the directory name
+ if targ == "." {
+ d, err := filepath.Abs(dir)
+ if err != nil {
+ return nil, os.NewError("finding path: " + err.String())
+ }
+ _, targ = filepath.Split(d)
+ }
+ }
+ if !safeName(targ) {
return nil, os.ErrorString("unsafe name: " + pkg)
}
- dirInfo, err := scanDir(dir, false)
+ dirInfo, err := scanDir(dir, isCmd)
if err != nil {
return nil, err
}
}
var buf bytes.Buffer
- md := makedata{pkg, goFiles, oFiles, cgoFiles, cgoOFiles}
+ md := makedata{targ, "pkg", goFiles, oFiles, cgoFiles, cgoOFiles}
+ if isCmd {
+ md.Type = "cmd"
+ }
if err := makefileTemplate.Execute(&buf, &md); err != nil {
return nil, err
}
var safeBytes = []byte("+-./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz")
func safeName(s string) bool {
+ if len(s) == 0 {
+ return false
+ }
for i := 0; i < len(s); i++ {
if c := s[i]; c < 0x80 && bytes.IndexByte(safeBytes, c) < 0 {
return false
// makedata is the data type for the makefileTemplate.
type makedata struct {
- Pkg string // package import path
+ Targ string // build target
+ Type string // build type: "pkg" or "cmd"
GoFiles []string // list of non-cgo .go files
OFiles []string // list of .$O files
CgoFiles []string // list of cgo .go files
var makefileTemplate = template.MustParse(`
include $(GOROOT)/src/Make.inc
-TARG={Pkg}
+TARG={Targ}
{.section GoFiles}
GOFILES=\
{.end}
{.end}
-include $(GOROOT)/src/Make.pkg
+include $(GOROOT)/src/Make.{Type}
`,
nil)