Commit 202e6153 authored by Jan Ziak's avatar Jan Ziak Committed by Russ Cox

cmd/dist: respect system CFLAGS/LDFLAGS

Update #6882.

LGTM=rsc
R=golang-codereviews, rsc
CC=golang-codereviews
https://golang.org/cl/69860055
parent 1249d3a5
...@@ -27,6 +27,8 @@ char *gochar; ...@@ -27,6 +27,8 @@ char *gochar;
char *goversion; char *goversion;
char *slash; // / for unix, \ for windows char *slash; // / for unix, \ for windows
char *defaultcc; char *defaultcc;
char *defaultcflags;
char *defaultldflags;
char *defaultcxxtarget; char *defaultcxxtarget;
char *defaultcctarget; char *defaultcctarget;
bool rebuildall; bool rebuildall;
...@@ -169,6 +171,12 @@ init(void) ...@@ -169,6 +171,12 @@ init(void)
} }
defaultcc = btake(&b); defaultcc = btake(&b);
xgetenv(&b, "CFLAGS");
defaultcflags = btake(&b);
xgetenv(&b, "LDFLAGS");
defaultldflags = btake(&b);
xgetenv(&b, "CC_FOR_TARGET"); xgetenv(&b, "CC_FOR_TARGET");
if(b.len == 0) { if(b.len == 0) {
bprintf(&b, defaultcc); bprintf(&b, defaultcc);
...@@ -465,12 +473,19 @@ static char *proto_gccargs[] = { ...@@ -465,12 +473,19 @@ static char *proto_gccargs[] = {
// GCC 4.5.4 (NetBSD nb1 20120916) on ARM is known to mis-optimize gc/mparith3.c // GCC 4.5.4 (NetBSD nb1 20120916) on ARM is known to mis-optimize gc/mparith3.c
// Fix available at http://patchwork.ozlabs.org/patch/64562/. // Fix available at http://patchwork.ozlabs.org/patch/64562/.
"-O1", "-O1",
#endif
};
// gccargs2 is the second part of gccargs.
// it is used if the environment isn't defining CFLAGS.
static char *proto_gccargs2[] = {
#if defined(__NetBSD__) && defined(__arm__)
#else #else
"-O2", "-O2",
#endif #endif
}; };
static Vec gccargs; static Vec gccargs, ldargs;
// deptab lists changes to the default dependencies for a given prefix. // deptab lists changes to the default dependencies for a given prefix.
// deps ending in /* read the whole directory; deps beginning with - // deps ending in /* read the whole directory; deps beginning with -
...@@ -682,10 +697,14 @@ install(char *dir) ...@@ -682,10 +697,14 @@ install(char *dir)
// set up gcc command line on first run. // set up gcc command line on first run.
if(gccargs.len == 0) { if(gccargs.len == 0) {
bprintf(&b, "%s", defaultcc); bprintf(&b, "%s %s", defaultcc, defaultcflags);
splitfields(&gccargs, bstr(&b)); splitfields(&gccargs, bstr(&b));
for(i=0; i<nelem(proto_gccargs); i++) for(i=0; i<nelem(proto_gccargs); i++)
vadd(&gccargs, proto_gccargs[i]); vadd(&gccargs, proto_gccargs[i]);
if(defaultcflags[0] == '\0') {
for(i=0; i<nelem(proto_gccargs2); i++)
vadd(&gccargs, proto_gccargs2[i]);
}
if(contains(gccargs.p[0], "clang")) { if(contains(gccargs.p[0], "clang")) {
// disable ASCII art in clang errors, if possible // disable ASCII art in clang errors, if possible
vadd(&gccargs, "-fno-caret-diagnostics"); vadd(&gccargs, "-fno-caret-diagnostics");
...@@ -699,6 +718,10 @@ install(char *dir) ...@@ -699,6 +718,10 @@ install(char *dir)
vadd(&gccargs, "-mmacosx-version-min=10.6"); vadd(&gccargs, "-mmacosx-version-min=10.6");
} }
} }
if(ldargs.len == 0 && defaultldflags[0] != '\0') {
bprintf(&b, "%s", defaultldflags);
splitfields(&ldargs, bstr(&b));
}
islib = hasprefix(dir, "lib") || streq(dir, "cmd/cc") || streq(dir, "cmd/gc"); islib = hasprefix(dir, "lib") || streq(dir, "cmd/cc") || streq(dir, "cmd/gc");
ispkg = hasprefix(dir, "pkg"); ispkg = hasprefix(dir, "pkg");
...@@ -742,7 +765,7 @@ install(char *dir) ...@@ -742,7 +765,7 @@ install(char *dir)
targ = link.len; targ = link.len;
vadd(&link, bpathf(&b, "%s/%s%s", tooldir, elem, exe)); vadd(&link, bpathf(&b, "%s/%s%s", tooldir, elem, exe));
} else { } else {
// C command. Use gccargs. // C command. Use gccargs and ldargs.
if(streq(gohostos, "plan9")) { if(streq(gohostos, "plan9")) {
vadd(&link, bprintf(&b, "%sl", gohostchar)); vadd(&link, bprintf(&b, "%sl", gohostchar));
vadd(&link, "-o"); vadd(&link, "-o");
...@@ -750,6 +773,7 @@ install(char *dir) ...@@ -750,6 +773,7 @@ install(char *dir)
vadd(&link, bpathf(&b, "%s/%s", tooldir, name)); vadd(&link, bpathf(&b, "%s/%s", tooldir, name));
} else { } else {
vcopy(&link, gccargs.p, gccargs.len); vcopy(&link, gccargs.p, gccargs.len);
vcopy(&link, ldargs.p, ldargs.len);
if(sflag) if(sflag)
vadd(&link, "-static"); vadd(&link, "-static");
vadd(&link, "-o"); vadd(&link, "-o");
......
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