_cgo_export.c # for gcc
_cgo_export.h # for gcc
_cgo_main.c # for gcc
- _cgo_flags # for alternative build tools
+ _cgo_flags # for build tool (if -gccgo)
The file x.cgo1.go is a copy of x.go with the import "C" removed and
references to C.xxx replaced with names like _Cfunc_xxx or _Ctype_xxx.
f.Preamble = strings.Join(linesOut, "\n")
}
-// addToFlag appends args to flag. All flags are later written out onto the
-// _cgo_flags file for the build system to use.
+// addToFlag appends args to flag.
func (p *Package) addToFlag(flag string, args []string) {
- p.CgoFlags[flag] = append(p.CgoFlags[flag], args...)
if flag == "CFLAGS" {
// We'll also need these when preprocessing for dwarf information.
// However, discard any -g options: we need to be able
}
}
}
+ if flag == "LDFLAGS" {
+ p.LdFlags = append(p.LdFlags, args...)
+ }
}
// splitQuoted splits the string s around each instance of one or more consecutive
IntSize int64
GccOptions []string
GccIsClang bool
- CgoFlags map[string][]string // #cgo flags (CFLAGS, LDFLAGS)
+ LdFlags []string // #cgo LDFLAGS
Written map[string]bool
Name map[string]*Name // accumulated Name from Files
ExpFunc []*ExpFunc // accumulated ExpFunc from Files
p := &Package{
PtrSize: ptrSize,
IntSize: intSize,
- CgoFlags: make(map[string][]string),
Written: make(map[string]bool),
noCallbacks: make(map[string]bool),
noEscapes: make(map[string]bool),
var gccgoInit strings.Builder
- fflg := creat(*objDir + "_cgo_flags")
- for k, v := range p.CgoFlags {
- for _, arg := range v {
- fmt.Fprintf(fflg, "_CGO_%s=%s\n", k, arg)
- }
- if k == "LDFLAGS" && !*gccgo {
- for _, arg := range v {
- fmt.Fprintf(fgo2, "//go:cgo_ldflag %q\n", arg)
- }
+ if !*gccgo {
+ for _, arg := range p.LdFlags {
+ fmt.Fprintf(fgo2, "//go:cgo_ldflag %q\n", arg)
+ }
+ } else {
+ fflg := creat(*objDir + "_cgo_flags")
+ for _, arg := range p.LdFlags {
+ fmt.Fprintf(fflg, "_CGO_LDFLAGS=%s\n", arg)
}
+ fflg.Close()
}
- fflg.Close()
// Write C main file for using gcc to resolve imports.
fmt.Fprintf(fm, "#include <stddef.h>\n") // For size_t below.