1
0
mirror of https://github.com/golang/go synced 2024-11-25 02:27:56 -07:00

cgo: put CFLAGS before filename argument

This means that the -x flag can work, which could enable
support for other languages (e.g. objective-C).

R=iant, rsc
CC=golang-dev
https://golang.org/cl/4476049
This commit is contained in:
Roger Peppe 2011-05-06 13:35:51 -07:00 committed by Ian Lance Taylor
parent be99859dbe
commit 1dc914bc0d

View File

@ -604,7 +604,7 @@ const gccTmp = "_obj/_cgo_.o"
// gccCmd returns the gcc command line to use for compiling // gccCmd returns the gcc command line to use for compiling
// the input. // the input.
func (p *Package) gccCmd() []string { func (p *Package) gccCmd() []string {
return []string{ c := []string{
p.gccName(), p.gccName(),
p.gccMachine(), p.gccMachine(),
"-Wall", // many warnings "-Wall", // many warnings
@ -614,15 +614,17 @@ func (p *Package) gccCmd() []string {
"-fno-eliminate-unused-debug-types", // gets rid of e.g. untyped enum otherwise "-fno-eliminate-unused-debug-types", // gets rid of e.g. untyped enum otherwise
"-c", // do not link "-c", // do not link
"-xc", // input language is C "-xc", // input language is C
"-", // read input from standard input
} }
c = append(c, p.GccOptions...)
c = append(c, "-") //read input from standard input
return c
} }
// gccDebug runs gcc -gdwarf-2 over the C program stdin and // gccDebug runs gcc -gdwarf-2 over the C program stdin and
// returns the corresponding DWARF data and any messages // returns the corresponding DWARF data and any messages
// printed to standard error. // printed to standard error.
func (p *Package) gccDebug(stdin []byte) *dwarf.Data { func (p *Package) gccDebug(stdin []byte) *dwarf.Data {
runGcc(stdin, append(p.gccCmd(), p.GccOptions...)) runGcc(stdin, p.gccCmd())
// Try to parse f as ELF and Mach-O and hope one works. // Try to parse f as ELF and Mach-O and hope one works.
var f interface { var f interface {
@ -649,8 +651,8 @@ func (p *Package) gccDebug(stdin []byte) *dwarf.Data {
// #defines that gcc encountered while processing the input // #defines that gcc encountered while processing the input
// and its included files. // and its included files.
func (p *Package) gccDefines(stdin []byte) string { func (p *Package) gccDefines(stdin []byte) string {
base := []string{p.gccName(), p.gccMachine(), "-E", "-dM", "-xc", "-"} base := []string{p.gccName(), p.gccMachine(), "-E", "-dM", "-xc"}
stdout, _ := runGcc(stdin, append(base, p.GccOptions...)) stdout, _ := runGcc(stdin, append(append(base, p.GccOptions...), "-"))
return stdout return stdout
} }
@ -659,7 +661,7 @@ func (p *Package) gccDefines(stdin []byte) string {
// gcc to fail. // gcc to fail.
func (p *Package) gccErrors(stdin []byte) string { func (p *Package) gccErrors(stdin []byte) string {
// TODO(rsc): require failure // TODO(rsc): require failure
args := append(p.gccCmd(), p.GccOptions...) args := p.gccCmd()
if *debugGcc { if *debugGcc {
fmt.Fprintf(os.Stderr, "$ %s <<EOF\n", strings.Join(args, " ")) fmt.Fprintf(os.Stderr, "$ %s <<EOF\n", strings.Join(args, " "))
os.Stderr.Write(stdin) os.Stderr.Write(stdin)