summaryrefslogtreecommitdiff
path: root/src/cmd/cgo/main.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/cmd/cgo/main.go')
-rw-r--r--src/cmd/cgo/main.go29
1 files changed, 16 insertions, 13 deletions
diff --git a/src/cmd/cgo/main.go b/src/cmd/cgo/main.go
index 7adc795de..9bd326e1d 100644
--- a/src/cmd/cgo/main.go
+++ b/src/cmd/cgo/main.go
@@ -33,7 +33,7 @@ type Package struct {
PtrSize int64
IntSize int64
GccOptions []string
- CgoFlags map[string]string // #cgo flags (CFLAGS, LDFLAGS)
+ CgoFlags map[string][]string // #cgo flags (CFLAGS, LDFLAGS)
Written map[string]bool
Name map[string]*Name // accumulated Name from Files
ExpFunc []*ExpFunc // accumulated ExpFunc from Files
@@ -208,6 +208,15 @@ func main() {
p := newPackage(args[:i])
+ // Record CGO_LDFLAGS from the environment for external linking.
+ if ldflags := os.Getenv("CGO_LDFLAGS"); ldflags != "" {
+ args, err := splitQuoted(ldflags)
+ if err != nil {
+ fatalf("bad CGO_LDFLAGS: %q (%s)", ldflags, err)
+ }
+ p.addToFlag("LDFLAGS", args)
+ }
+
// Need a unique prefix for the global C symbols that
// we use to coordinate between gcc and ourselves.
// We already put _cgo_ at the beginning, so the main
@@ -226,10 +235,9 @@ func main() {
fs := make([]*File, len(goFiles))
for i, input := range goFiles {
- // Parse flags for all files before translating due to CFLAGS.
f := new(File)
f.ReadGo(input)
- p.ParseFlags(f, input)
+ f.DiscardCgoDirectives()
fs[i] = f
}
@@ -282,11 +290,6 @@ func main() {
// newPackage returns a new Package that will invoke
// gcc with the additional arguments specified in args.
func newPackage(args []string) *Package {
- // Copy the gcc options to a new slice so the list
- // can grow without overwriting the slice that args is in.
- gccOptions := make([]string, len(args))
- copy(gccOptions, args)
-
goarch = runtime.GOARCH
if s := os.Getenv("GOARCH"); s != "" {
goarch = s
@@ -309,12 +312,12 @@ func newPackage(args []string) *Package {
os.Setenv("LC_ALL", "C")
p := &Package{
- PtrSize: ptrSize,
- IntSize: intSize,
- GccOptions: gccOptions,
- CgoFlags: make(map[string]string),
- Written: make(map[string]bool),
+ PtrSize: ptrSize,
+ IntSize: intSize,
+ CgoFlags: make(map[string][]string),
+ Written: make(map[string]bool),
}
+ p.addToFlag("CFLAGS", args)
return p
}