From 202e6153f54e2a2b0d3a51cd0d69754f1ce60580 Mon Sep 17 00:00:00 2001 From: Jan Ziak <0xe2.0x9a.0x9b@gmail.com> Date: Wed, 5 Mar 2014 14:10:22 -0500 Subject: [PATCH] cmd/dist: respect system CFLAGS/LDFLAGS Update #6882. LGTM=rsc R=golang-codereviews, rsc CC=golang-codereviews https://golang.org/cl/69860055 --- src/cmd/dist/build.c | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/src/cmd/dist/build.c b/src/cmd/dist/build.c index e79b7188e0f..b3ed471b9c5 100644 --- a/src/cmd/dist/build.c +++ b/src/cmd/dist/build.c @@ -27,6 +27,8 @@ char *gochar; char *goversion; char *slash; // / for unix, \ for windows char *defaultcc; +char *defaultcflags; +char *defaultldflags; char *defaultcxxtarget; char *defaultcctarget; bool rebuildall; @@ -169,6 +171,12 @@ init(void) } defaultcc = btake(&b); + xgetenv(&b, "CFLAGS"); + defaultcflags = btake(&b); + + xgetenv(&b, "LDFLAGS"); + defaultldflags = btake(&b); + xgetenv(&b, "CC_FOR_TARGET"); if(b.len == 0) { bprintf(&b, defaultcc); @@ -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 // Fix available at http://patchwork.ozlabs.org/patch/64562/. "-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 "-O2", #endif }; -static Vec gccargs; +static Vec gccargs, ldargs; // deptab lists changes to the default dependencies for a given prefix. // deps ending in /* read the whole directory; deps beginning with - @@ -682,10 +697,14 @@ install(char *dir) // set up gcc command line on first run. if(gccargs.len == 0) { - bprintf(&b, "%s", defaultcc); + bprintf(&b, "%s %s", defaultcc, defaultcflags); splitfields(&gccargs, bstr(&b)); for(i=0; i