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