cgo: interpret $CGOPKGDIR as absolute path if rooted

R=dho
CC=golang-dev
https://golang.org/cl/180099
This commit is contained in:
Russ Cox 2009-12-21 08:31:02 -08:00
parent fa98cf6eef
commit c276d87c6c
3 changed files with 16 additions and 5 deletions

View File

@ -23,7 +23,11 @@ endif
TARG_words=$(subst /, ,$(TARG)) TARG_words=$(subst /, ,$(TARG))
elem=$(word $(words $(TARG_words)),$(TARG_words)) elem=$(word $(words $(TARG_words)),$(TARG_words))
dir=$(patsubst %/$(elem),%,./$(TARG)) ifeq ($(elem),$(TARG))
dir=
else
dir=$(patsubst %/$(elem),%,$(TARG))
endif
# ugly hack to deal with whitespaces in $GOROOT # ugly hack to deal with whitespaces in $GOROOT
nullstring := nullstring :=

View File

@ -126,8 +126,11 @@ func main() {
if nerrors > 0 { if nerrors > 0 {
os.Exit(2) os.Exit(2)
} }
pkg := p.Package
p.PackagePath = os.Getenv("CGOPKGPATH") + "/" + p.Package if dir := os.Getenv("CGOPKGPATH"); dir != "" {
pkg = dir + "/" + pkg
}
p.PackagePath = pkg
p.writeOutput(input) p.writeOutput(input)
} }

View File

@ -24,6 +24,10 @@ func creat(name string) *os.File {
// (The comments here say 6g and 6c but the code applies to the 8 and 5 tools too.) // (The comments here say 6g and 6c but the code applies to the 8 and 5 tools too.)
func (p *Prog) writeDefs() { func (p *Prog) writeDefs() {
pkgroot := os.Getenv("GOROOT") + "/pkg/" + os.Getenv("GOOS") + "_" + os.Getenv("GOARCH") pkgroot := os.Getenv("GOROOT") + "/pkg/" + os.Getenv("GOOS") + "_" + os.Getenv("GOARCH")
path := p.PackagePath
if !strings.HasPrefix(path, "/") {
path = pkgroot + "/" + path
}
fgo2 := creat("_cgo_gotypes.go") fgo2 := creat("_cgo_gotypes.go")
fc := creat("_cgo_defun.c") fc := creat("_cgo_defun.c")
@ -46,7 +50,7 @@ func (p *Prog) writeDefs() {
fmt.Fprintf(fc, cProlog, pkgroot, pkgroot, pkgroot, pkgroot, p.Package, p.Package) fmt.Fprintf(fc, cProlog, pkgroot, pkgroot, pkgroot, pkgroot, p.Package, p.Package)
for name, def := range p.Vardef { for name, def := range p.Vardef {
fmt.Fprintf(fc, "#pragma dynld %s·_C_%s %s \"%s/%s.so\"\n", p.Package, name, name, pkgroot, p.PackagePath) fmt.Fprintf(fc, "#pragma dynld %s·_C_%s %s \"%s.so\"\n", p.Package, name, name, path)
fmt.Fprintf(fgo2, "var _C_%s ", name) fmt.Fprintf(fgo2, "var _C_%s ", name)
printer.Fprint(fgo2, &ast.StarExpr{X: def.Go}) printer.Fprint(fgo2, &ast.StarExpr{X: def.Go})
fmt.Fprintf(fgo2, "\n") fmt.Fprintf(fgo2, "\n")
@ -121,7 +125,7 @@ func (p *Prog) writeDefs() {
// C wrapper calls into gcc, passing a pointer to the argument frame. // C wrapper calls into gcc, passing a pointer to the argument frame.
// Also emit #pragma to get a pointer to the gcc wrapper. // Also emit #pragma to get a pointer to the gcc wrapper.
fmt.Fprintf(fc, "#pragma dynld _cgo_%s _cgo_%s \"%s/%s.so\"\n", name, name, pkgroot, p.PackagePath) fmt.Fprintf(fc, "#pragma dynld _cgo_%s _cgo_%s \"%s.so\"\n", name, name, path)
fmt.Fprintf(fc, "void (*_cgo_%s)(void*);\n", name) fmt.Fprintf(fc, "void (*_cgo_%s)(void*);\n", name)
fmt.Fprintf(fc, "\n") fmt.Fprintf(fc, "\n")
fmt.Fprintf(fc, "void\n") fmt.Fprintf(fc, "void\n")