forked from constabulary/gb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gc15.go
79 lines (69 loc) · 2.26 KB
/
gc15.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
// +build go1.5
package gb
import (
"fmt"
"os"
"path/filepath"
"runtime"
)
// gc toolchain
func GcToolchain() func(c *Context) error {
return func(c *Context) error {
goroot := runtime.GOROOT()
tooldir := filepath.Join(goroot, "pkg", "tool", c.gohostos+"_"+c.gohostarch)
c.tc = &gcToolchain{
gc: filepath.Join(tooldir, "compile"),
ld: filepath.Join(tooldir, "link"),
as: filepath.Join(tooldir, "asm"),
pack: filepath.Join(tooldir, "pack"),
}
return nil
}
}
func (t *gcToolchain) Gc(pkg *Package, searchpaths []string, importpath, srcdir, outfile string, files []string) error {
args := append(pkg.gcflags, "-p", importpath, "-pack")
args = append(args, "-o", outfile)
for _, d := range searchpaths {
args = append(args, "-I", d)
}
if pkg.Standard && pkg.ImportPath == "runtime" {
// runtime compiles with a special gc flag to emit
// additional reflect type data.
args = append(args, "-+")
}
if pkg.Complete() {
args = append(args, "-complete")
} else {
asmhdr := filepath.Join(filepath.Dir(outfile), pkg.Name, "go_asm.h")
args = append(args, "-asmhdr", asmhdr)
}
args = append(args, files...)
if err := mkdir(filepath.Join(filepath.Dir(outfile), pkg.Name)); err != nil {
return fmt.Errorf("gc:gc: %v", err)
}
return runOut(os.Stdout, srcdir, nil, t.gc, args...)
}
func (t *gcToolchain) Asm(pkg *Package, srcdir, ofile, sfile string) error {
odir := filepath.Join(filepath.Dir(ofile))
includedir := filepath.Join(runtime.GOROOT(), "pkg", "include")
args := []string{"-o", ofile, "-D", "GOOS_" + pkg.gotargetos, "-D", "GOARCH_" + pkg.gotargetarch, "-I", odir, "-I", includedir, sfile}
if err := mkdir(odir); err != nil {
return fmt.Errorf("gc:asm: %v", err)
}
return run(srcdir, nil, t.as, args...)
}
func (t *gcToolchain) Ld(pkg *Package, searchpaths []string, outfile, afile string) error {
args := append(pkg.ldflags, "-o", outfile)
for _, d := range searchpaths {
args = append(args, "-L", d)
}
args = append(args, "-extld="+gcc(), "-buildmode=exe")
args = append(args, afile)
if err := mkdir(filepath.Dir(outfile)); err != nil {
return fmt.Errorf("gc:ld: %v", err)
}
return run(".", nil, t.ld, args...)
}
func (t *gcToolchain) Cc(pkg *Package, ofile, cfile string) error {
return fmt.Errorf("gc15 does not support cc")
}