]> Cypherpunks repositories - gostls13.git/commitdiff
goinstall: handle .c files with gc when cgo isn't used
authorGustavo Niemeyer <gustavo@niemeyer.net>
Mon, 7 Mar 2011 17:53:39 +0000 (12:53 -0500)
committerRuss Cox <rsc@golang.org>
Mon, 7 Mar 2011 17:53:39 +0000 (12:53 -0500)
As a data point, this enables goinstall to handle the standard
syscall package almost unchanged (there's one file with the _bsd
extension, and a .c file which isn't supposed to be compiled in).

R=rsc
CC=golang-dev
https://golang.org/cl/4259057

src/cmd/goinstall/make.go

index 5e3523767a38391f7d23b7feb804e478e54d38e8..ceb119e5a4734aba85abbc75e453589d9fda7def 100644 (file)
@@ -52,12 +52,6 @@ func makeMakefile(dir, pkg string) ([]byte, os.Error) {
                return nil, err
        }
 
-       if len(dirInfo.cgoFiles) == 0 && len(dirInfo.cFiles) > 0 {
-               // When using cgo, .c files are compiled with gcc.  Without cgo,
-               // they may be intended for 6c.  Just error out for now.
-               return nil, os.ErrorString("C files found in non-cgo package")
-       }
-
        cgoFiles := dirInfo.cgoFiles
        isCgo := make(map[string]bool, len(cgoFiles))
        for _, file := range cgoFiles {
@@ -67,25 +61,31 @@ func makeMakefile(dir, pkg string) ([]byte, os.Error) {
                isCgo[file] = true
        }
 
-       cgoOFiles := make([]string, 0, len(dirInfo.cFiles))
-       for _, file := range dirInfo.cFiles {
+       goFiles := make([]string, 0, len(dirInfo.goFiles))
+       for _, file := range dirInfo.goFiles {
                if !safeName(file) {
                        return nil, os.ErrorString("unsafe name: " + file)
                }
-               cgoOFiles = append(cgoOFiles, file[:len(file)-2]+".o")
+               if !isCgo[file] {
+                       goFiles = append(goFiles, file)
+               }
        }
 
-       goFiles := make([]string, 0, len(dirInfo.goFiles))
-       for _, file := range dirInfo.goFiles {
+       oFiles := make([]string, 0, len(dirInfo.cFiles)+len(dirInfo.sFiles))
+       cgoOFiles := make([]string, 0, len(dirInfo.cFiles))
+       for _, file := range dirInfo.cFiles {
                if !safeName(file) {
                        return nil, os.ErrorString("unsafe name: " + file)
                }
-               if !isCgo[file] {
-                       goFiles = append(goFiles, file)
+               // When cgo is in use, C files are compiled with gcc,
+               // otherwise they're compiled with gc.
+               if len(cgoFiles) > 0 {
+                       cgoOFiles = append(cgoOFiles, file[:len(file)-2]+".o")
+               } else {
+                       oFiles = append(oFiles, file[:len(file)-2]+".$O")
                }
        }
 
-       oFiles := make([]string, 0, len(dirInfo.sFiles))
        for _, file := range dirInfo.sFiles {
                if !safeName(file) {
                        return nil, os.ErrorString("unsafe name: " + file)