Commit 0f8678a7 authored by Alex Brainman's avatar Alex Brainman

go/build: include processing of .c files for cgo packages

R=golang-dev, adg
CC=golang-dev
https://golang.org/cl/4696041
parent 851ded96
...@@ -61,7 +61,9 @@ func Build(tree *Tree, pkg string, info *DirInfo) (*Script, os.Error) { ...@@ -61,7 +61,9 @@ func Build(tree *Tree, pkg string, info *DirInfo) (*Script, os.Error) {
if len(info.CgoFiles) > 0 { if len(info.CgoFiles) > 0 {
cgoFiles := b.abss(info.CgoFiles...) cgoFiles := b.abss(info.CgoFiles...)
s.addInput(cgoFiles...) s.addInput(cgoFiles...)
outGo, outObj := b.cgo(cgoFiles) cgoCFiles := b.abss(info.CFiles...)
s.addInput(cgoCFiles...)
outGo, outObj := b.cgo(cgoFiles, cgoCFiles)
gofiles = append(gofiles, outGo...) gofiles = append(gofiles, outGo...)
ofiles = append(ofiles, outObj...) ofiles = append(ofiles, outObj...)
s.addIntermediate(outGo...) s.addIntermediate(outGo...)
...@@ -370,7 +372,7 @@ func (b *build) gccArgs(args ...string) []string { ...@@ -370,7 +372,7 @@ func (b *build) gccArgs(args ...string) []string {
var cgoRe = regexp.MustCompile(`[/\\:]`) var cgoRe = regexp.MustCompile(`[/\\:]`)
func (b *build) cgo(cgofiles []string) (outGo, outObj []string) { func (b *build) cgo(cgofiles, cgocfiles []string) (outGo, outObj []string) {
// cgo // cgo
// TODO(adg): CGOPKGPATH // TODO(adg): CGOPKGPATH
// TODO(adg): CGO_FLAGS // TODO(adg): CGO_FLAGS
...@@ -413,6 +415,12 @@ func (b *build) cgo(cgofiles []string) (outGo, outObj []string) { ...@@ -413,6 +415,12 @@ func (b *build) cgo(cgofiles []string) (outGo, outObj []string) {
b.script.addIntermediate(ofile) b.script.addIntermediate(ofile)
} }
} }
for _, cfile := range cgocfiles {
ofile := b.obj + cgoRe.ReplaceAllString(cfile[:len(cfile)-1], "_") + "o"
b.gccCompile(ofile, cfile)
linkobj = append(linkobj, ofile)
outObj = append(outObj, ofile)
}
dynObj := b.obj + "_cgo_.o" dynObj := b.obj + "_cgo_.o"
b.gccLink(dynObj, linkobj...) b.gccLink(dynObj, linkobj...)
b.script.addIntermediate(dynObj) b.script.addIntermediate(dynObj)
......
// Copyright 2011 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
int
Add(int x, int y, int *sum)
{
sum = x+y;
}
...@@ -7,6 +7,13 @@ package cgotest ...@@ -7,6 +7,13 @@ package cgotest
/* /*
char* greeting = "hello, world"; char* greeting = "hello, world";
*/ */
// #include "cgotest.h"
import "C" import "C"
import "unsafe"
var Greeting = C.GoString(C.greeting) var Greeting = C.GoString(C.greeting)
func DoAdd(x, y int) (sum int) {
C.Add(C.int(x), C.int(y), (*C.int)(unsafe.Pointer(&sum)))
return
}
// Copyright 2011 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
extern int Add(int, int, int *);
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment