From b575a98121a60f2c74782130d639fa636d41e98a Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Fri, 20 Jul 2012 16:58:08 -0700 Subject: [PATCH] cgo: add -gccgopkgpath option to match gccgo -fgo-pkgpath R=golang-dev, r, iant CC=golang-dev https://golang.org/cl/6416056 --- src/cmd/cgo/main.go | 3 ++- src/cmd/cgo/out.go | 18 ++++++++++++++++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/cmd/cgo/main.go b/src/cmd/cgo/main.go index 60165961a1..05389bb696 100644 --- a/src/cmd/cgo/main.go +++ b/src/cmd/cgo/main.go @@ -144,7 +144,8 @@ var cdefs = flag.Bool("cdefs", false, "for bootstrap: write C definitions for C var objDir = flag.String("objdir", "", "object directory") var gccgo = flag.Bool("gccgo", false, "generate files for use with gccgo") -var gccgoprefix = flag.String("gccgoprefix", "go", "prefix of symbols generated by gccgo") +var gccgoprefix = flag.String("gccgoprefix", "", "-fgo-prefix option used with gccgo") +var gccgopkgpath = flag.String("gccgopkgpath", "", "-fgo-pkgpath option used with gccgo") var importRuntimeCgo = flag.Bool("import_runtime_cgo", true, "import runtime/cgo in generated code") var goarch, goos string diff --git a/src/cmd/cgo/out.go b/src/cmd/cgo/out.go index ae572d6dc6..993a23ae46 100644 --- a/src/cmd/cgo/out.go +++ b/src/cmd/cgo/out.go @@ -669,7 +669,21 @@ func (p *Package) writeGccgoExports(fgo2, fc, fm *os.File) { } return '_' } - gccgoSymbolPrefix := strings.Map(clean, *gccgoprefix) + + var gccgoSymbolPrefix string + if *gccgopkgpath != "" { + gccgoSymbolPrefix = strings.Map(clean, *gccgopkgpath) + } else { + if *gccgoprefix == "" && p.PackageName == "main" { + gccgoSymbolPrefix = "main" + } else { + prefix := strings.Map(clean, *gccgoprefix) + if prefix == "" { + prefix = "go" + } + gccgoSymbolPrefix = prefix + "." + p.PackageName + } + } for _, exp := range p.ExpFunc { // TODO: support functions with receivers. @@ -707,7 +721,7 @@ func (p *Package) writeGccgoExports(fgo2, fc, fm *os.File) { // The function name. fmt.Fprintf(cdeclBuf, " "+exp.ExpName) - gccgoSymbol := fmt.Sprintf("%s.%s.%s", gccgoSymbolPrefix, p.PackageName, exp.Func.Name) + gccgoSymbol := fmt.Sprintf("%s.%s", gccgoSymbolPrefix, exp.Func.Name) fmt.Fprintf(cdeclBuf, " (") // Function parameters. forFieldList(fntype.Params,