Commit 7616c949 authored by Shenghou Ma's avatar Shenghou Ma

cmd/dist, cmd/go: embed default C++ compiler into cmd/go

Fixes #6426.

R=golang-dev, dave, rsc
CC=golang-dev
https://golang.org/cl/13704044
parent b80ef1ab
...@@ -75,6 +75,7 @@ extern char *goroot_final; ...@@ -75,6 +75,7 @@ extern char *goroot_final;
extern char *goextlinkenabled; extern char *goextlinkenabled;
extern char *goversion; extern char *goversion;
extern char *defaultcc; extern char *defaultcc;
extern char *defaultcxx;
extern char *workdir; extern char *workdir;
extern char *tooldir; extern char *tooldir;
extern char *slash; extern char *slash;
......
...@@ -27,6 +27,7 @@ char *gochar; ...@@ -27,6 +27,7 @@ char *gochar;
char *goversion; char *goversion;
char *slash; // / for unix, \ for windows char *slash; // / for unix, \ for windows
char *defaultcc; char *defaultcc;
char *defaultcxx;
bool rebuildall; bool rebuildall;
bool defaultclang; bool defaultclang;
...@@ -163,6 +164,15 @@ init(void) ...@@ -163,6 +164,15 @@ init(void)
} }
defaultcc = btake(&b); defaultcc = btake(&b);
xgetenv(&b, "CXX");
if(b.len == 0) {
if(defaultclang)
bprintf(&b, "clang++");
else
bprintf(&b, "g++");
}
defaultcxx = btake(&b);
xsetenv("GOROOT", goroot); xsetenv("GOROOT", goroot);
xsetenv("GOARCH", goarch); xsetenv("GOARCH", goarch);
xsetenv("GOOS", goos); xsetenv("GOOS", goos);
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
// //
// package main // package main
// const defaultCC = <defaultcc> // const defaultCC = <defaultcc>
// const defaultCXX = <defaultcxx>
// //
// It is invoked to write cmd/go/zdefaultcc.go // It is invoked to write cmd/go/zdefaultcc.go
// but we also write cmd/cgo/zdefaultcc.go. // but we also write cmd/cgo/zdefaultcc.go.
...@@ -28,8 +29,9 @@ mkzdefaultcc(char *dir, char *file) ...@@ -28,8 +29,9 @@ mkzdefaultcc(char *dir, char *file)
"\n" "\n"
"package main\n" "package main\n"
"\n" "\n"
"const defaultCC = `%s`\n", "const defaultCC = `%s`\n"
defaultcc); "const defaultCXX = `%s`\n",
defaultcc, defaultcxx);
writefile(&out, file, 0); writefile(&out, file, 0);
......
...@@ -1837,8 +1837,9 @@ func (b *builder) gccCmd(objdir string) []string { ...@@ -1837,8 +1837,9 @@ func (b *builder) gccCmd(objdir string) []string {
} }
// gxxCmd returns a g++ command line prefix // gxxCmd returns a g++ command line prefix
// defaultCXX is defined in zdefaultcc.go, written by cmd/dist.
func (b *builder) gxxCmd(objdir string) []string { func (b *builder) gxxCmd(objdir string) []string {
return b.ccompilerCmd("CXX", "g++", objdir) return b.ccompilerCmd("CXX", defaultCXX, objdir)
} }
// ccompilerCmd returns a command line prefix for the given environment // ccompilerCmd returns a command line prefix for the given environment
......
...@@ -54,6 +54,8 @@ func mkEnv() []envVar { ...@@ -54,6 +54,8 @@ func mkEnv() []envVar {
cmd := b.gccCmd(".") cmd := b.gccCmd(".")
env = append(env, envVar{"CC", cmd[0]}) env = append(env, envVar{"CC", cmd[0]})
env = append(env, envVar{"GOGCCFLAGS", strings.Join(cmd[3:], " ")}) env = append(env, envVar{"GOGCCFLAGS", strings.Join(cmd[3:], " ")})
cmd = b.gxxCmd(".")
env = append(env, envVar{"CXX", cmd[0]})
} }
if buildContext.CgoEnabled { if buildContext.CgoEnabled {
......
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