mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
cgo: define CGO_CFLAGS and CGO_LDFLAGS in Go files
R=rsc, binet CC=golang-dev https://golang.org/cl/3921043
This commit is contained in:
parent
0e47460915
commit
4fd867b283
5 changed files with 150 additions and 10 deletions
|
|
@ -29,6 +29,7 @@ type Package struct {
|
|||
PackagePath string
|
||||
PtrSize int64
|
||||
GccOptions []string
|
||||
CgoFlags map[string]string // #cgo flags (CFLAGS, LDFLAGS)
|
||||
Written map[string]bool
|
||||
Name map[string]*Name // accumulated Name from Files
|
||||
Typedef map[string]ast.Expr // accumulated Typedef from Files
|
||||
|
|
@ -161,7 +162,12 @@ func main() {
|
|||
if i == len(args) {
|
||||
usage()
|
||||
}
|
||||
gccOptions, goFiles := args[0:i], args[i:]
|
||||
|
||||
// Copy it to a new slice so it can grow.
|
||||
gccOptions := make([]string, i)
|
||||
copy(gccOptions, args[0:i])
|
||||
|
||||
goFiles := args[i:]
|
||||
|
||||
arch := os.Getenv("GOARCH")
|
||||
if arch == "" {
|
||||
|
|
@ -180,6 +186,7 @@ func main() {
|
|||
p := &Package{
|
||||
PtrSize: ptrSize,
|
||||
GccOptions: gccOptions,
|
||||
CgoFlags: make(map[string]string),
|
||||
Written: make(map[string]bool),
|
||||
}
|
||||
|
||||
|
|
@ -199,11 +206,17 @@ func main() {
|
|||
}
|
||||
cPrefix = fmt.Sprintf("_%x", h.Sum()[0:6])
|
||||
|
||||
for _, input := range goFiles {
|
||||
fs := make([]*File, len(goFiles))
|
||||
for i, input := range goFiles {
|
||||
// Parse flags for all files before translating due to CFLAGS.
|
||||
f := new(File)
|
||||
// Reset f.Preamble so that we don't end up with conflicting headers / defines
|
||||
f.Preamble = ""
|
||||
f.ReadGo(input)
|
||||
p.ParseFlags(f, input)
|
||||
fs[i] = f
|
||||
}
|
||||
|
||||
for i, input := range goFiles {
|
||||
f := fs[i]
|
||||
p.Translate(f)
|
||||
for _, cref := range f.Ref {
|
||||
switch cref.Context {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue