diff options
author | Hartmut Brandt <harti@FreeBSD.org> | 2004-08-03 18:56:31 +0000 |
---|---|---|
committer | Hartmut Brandt <harti@FreeBSD.org> | 2004-08-03 18:56:31 +0000 |
commit | d98bc4ce72bb0f874f5cb999c9f67f01e6cc860c (patch) | |
tree | c5ef8ec3263a3b61b02de03c0b5591c884c7ca46 /usr.bin | |
parent | 9f1b87f106100470dafeeab83abfa98ab86be3f7 (diff) | |
download | src-d98bc4ce72bb0f874f5cb999c9f67f01e6cc860c.tar.gz src-d98bc4ce72bb0f874f5cb999c9f67f01e6cc860c.zip |
Put variable assignments from the command line into the MAKEFLAGS
variable as required by POSIX. This causes such variables to be
pushed into all sub-makes called by the make (except when the MAKEFLAGS
variable is explicitely changed in the sub-make's environment).
This makes them also mostly un-overrideable in sub-makes except on the
sub-make's command line. Therefor specifying 'make CC=icc' will cause
icc to be used as C compiler in all sub-makes no matter what the Makefiles
itself try to do to the CC variable.
This patch also corrects the handling of the MFLAGS variable. MFLAGS
contains all the command line flags but not the command line variable
assignments. The evaluation of the .MFLAGS or .MAKEFLAGS target now
changes both MFLAGS and MAKEFLAGS (they used to change MAKEFLAGS only).
Makefiles can use MFLAGS for their own purposes given that they do not
except MFLAGS to be undefined at the beginning and that they don't evaluate
.MFLAGS or .MAKEFLAGS. MFLAGS should be removed for POSIX compliance,
but it is unfortunately heavily used by the X makefiles.
This has been extensively tested by port builds (thanks to portmgr), new
worlds and kernels.
PR: standards/57295 (1st part above)
Submitted by: James E. Flemer <jflemer@alum.rpi.edu>
Approved by: portmgr
Obtained from: NetBSD (1st part above)
MFC after: 4 weeks
Notes
Notes:
svn path=/head/; revision=133085
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/make/Makefile | 2 | ||||
-rw-r--r-- | usr.bin/make/main.c | 70 | ||||
-rw-r--r-- | usr.bin/make/nonints.h | 1 | ||||
-rw-r--r-- | usr.bin/make/var.c | 38 |
4 files changed, 79 insertions, 32 deletions
diff --git a/usr.bin/make/Makefile b/usr.bin/make/Makefile index 2b3e22becb63..ca728fdaa47f 100644 --- a/usr.bin/make/Makefile +++ b/usr.bin/make/Makefile @@ -15,7 +15,7 @@ SRCS+= lstAppend.c lstAtEnd.c lstAtFront.c lstClose.c lstConcat.c \ NOSHARED?= YES -CFLAGS+=-DMAKE_VERSION=\"5200407290\" +CFLAGS+=-DMAKE_VERSION=\"5200408030\" .if defined(_UPGRADING) CFLAGS+=-D__FBSDID=__RCSID .endif diff --git a/usr.bin/make/main.c b/usr.bin/make/main.c index bbc6ab5b2455..b835586e00ca 100644 --- a/usr.bin/make/main.c +++ b/usr.bin/make/main.c @@ -132,6 +132,21 @@ static void usage(void); static char *curdir; /* startup directory */ static char *objdir; /* where we chdir'ed to */ +/* + * Append a flag with an optional argument to MAKEFLAGS and MFLAGS + */ +static void +MFLAGS_append(char *flag, char *arg) +{ + Var_Append(MAKEFLAGS, flag, VAR_GLOBAL); + if (arg != NULL) + Var_Append(MAKEFLAGS, arg, VAR_GLOBAL); + + Var_Append("MFLAGS", flag, VAR_GLOBAL); + if (arg != NULL) + Var_Append("MFLAGS", arg, VAR_GLOBAL); +} + /*- * MainParseArgs -- * Parse a given argument vector. Called from main() and from @@ -166,25 +181,22 @@ rearg: while((c = getopt(argc, argv, OPTFLAGS)) != -1) { break; case 'D': Var_Set(optarg, "1", VAR_GLOBAL); - Var_Append(MAKEFLAGS, "-D", VAR_GLOBAL); - Var_Append(MAKEFLAGS, optarg, VAR_GLOBAL); + MFLAGS_append("-D", optarg); break; case 'I': Parse_AddIncludeDir(optarg); - Var_Append(MAKEFLAGS, "-I", VAR_GLOBAL); - Var_Append(MAKEFLAGS, optarg, VAR_GLOBAL); + MFLAGS_append("-I", optarg); break; case 'V': (void)Lst_AtEnd(variables, (void *)optarg); - Var_Append(MAKEFLAGS, "-V", VAR_GLOBAL); - Var_Append(MAKEFLAGS, optarg, VAR_GLOBAL); + MFLAGS_append("-V", optarg); break; case 'X': expandVars = FALSE; break; case 'B': compatMake = TRUE; - Var_Append(MAKEFLAGS, "-B", VAR_GLOBAL); + MFLAGS_append("-B", NULL); break; #ifdef REMOTE case 'L': { @@ -196,18 +208,17 @@ rearg: while((c = getopt(argc, argv, OPTFLAGS)) != -1) { optarg); usage(); } - Var_Append(MAKEFLAGS, "-L", VAR_GLOBAL); - Var_Append(MAKEFLAGS, optarg, VAR_GLOBAL); + MFLAGS_append("-L", optarg); break; } #endif case 'P': usePipes = FALSE; - Var_Append(MAKEFLAGS, "-P", VAR_GLOBAL); + MFLAGS_append("-P", NULL); break; case 'S': keepgoing = FALSE; - Var_Append(MAKEFLAGS, "-S", VAR_GLOBAL); + MFLAGS_append("-S", NULL); break; case 'd': { char *modules = optarg; @@ -261,27 +272,25 @@ rearg: while((c = getopt(argc, argv, OPTFLAGS)) != -1) { warnx("illegal argument to d option -- %c", *modules); usage(); } - Var_Append(MAKEFLAGS, "-d", VAR_GLOBAL); - Var_Append(MAKEFLAGS, optarg, VAR_GLOBAL); + MFLAGS_append("-d", optarg); break; } case 'E': p = emalloc(strlen(optarg) + 1); (void)strcpy(p, optarg); (void)Lst_AtEnd(envFirstVars, (void *)p); - Var_Append(MAKEFLAGS, "-E", VAR_GLOBAL); - Var_Append(MAKEFLAGS, optarg, VAR_GLOBAL); + MFLAGS_append("-E", optarg); break; case 'e': checkEnvFirst = TRUE; - Var_Append(MAKEFLAGS, "-e", VAR_GLOBAL); + MFLAGS_append("-e", NULL); break; case 'f': (void)Lst_AtEnd(makefiles, (void *)optarg); break; case 'i': ignoreErrors = TRUE; - Var_Append(MAKEFLAGS, "-i", VAR_GLOBAL); + MFLAGS_append("-i", NULL); break; case 'j': { char *endptr; @@ -296,43 +305,41 @@ rearg: while((c = getopt(argc, argv, OPTFLAGS)) != -1) { #ifndef REMOTE maxLocal = maxJobs; #endif - Var_Append(MAKEFLAGS, "-j", VAR_GLOBAL); - Var_Append(MAKEFLAGS, optarg, VAR_GLOBAL); + MFLAGS_append("-j", optarg); break; } case 'k': keepgoing = TRUE; - Var_Append(MAKEFLAGS, "-k", VAR_GLOBAL); + MFLAGS_append("-k", NULL); break; case 'm': Dir_AddDir(sysIncPath, optarg); - Var_Append(MAKEFLAGS, "-m", VAR_GLOBAL); - Var_Append(MAKEFLAGS, optarg, VAR_GLOBAL); + MFLAGS_append("-m", optarg); break; case 'n': noExecute = TRUE; - Var_Append(MAKEFLAGS, "-n", VAR_GLOBAL); + MFLAGS_append("-n", NULL); break; case 'q': queryFlag = TRUE; /* Kind of nonsensical, wot? */ - Var_Append(MAKEFLAGS, "-q", VAR_GLOBAL); + MFLAGS_append("-q", NULL); break; case 'r': noBuiltins = TRUE; - Var_Append(MAKEFLAGS, "-r", VAR_GLOBAL); + MFLAGS_append("-r", NULL); break; case 's': beSilent = TRUE; - Var_Append(MAKEFLAGS, "-s", VAR_GLOBAL); + MFLAGS_append("-s", NULL); break; case 't': touchFlag = TRUE; - Var_Append(MAKEFLAGS, "-t", VAR_GLOBAL); + MFLAGS_append("-t", NULL); break; case 'v': beVerbose = TRUE; - Var_Append(MAKEFLAGS, "-v", VAR_GLOBAL); + MFLAGS_append("-v", NULL); break; default: case '?': @@ -638,6 +645,10 @@ main(int argc, char **argv) MainParseArgs(argc, argv); +#ifdef POSIX + Var_AddCmdLine(MAKEFLAGS); +#endif + /* * Find where we are... * All this code is so that we know where we are when we start up @@ -780,9 +791,6 @@ main(int argc, char **argv) (void)ReadMakefile(".depend", NULL); - Var_Append("MFLAGS", Var_Value(MAKEFLAGS, VAR_GLOBAL, &p1), VAR_GLOBAL); - free(p1); - /* Install all the flags into the MAKE envariable. */ if (((p = Var_Value(MAKEFLAGS, VAR_GLOBAL, &p1)) != NULL) && *p) #ifdef POSIX diff --git a/usr.bin/make/nonints.h b/usr.bin/make/nonints.h index e2da28ed84a9..e1bfae329441 100644 --- a/usr.bin/make/nonints.h +++ b/usr.bin/make/nonints.h @@ -136,6 +136,7 @@ void Var_Set(char *, char *, GNode *); void Var_Append(char *, char *, GNode *); Boolean Var_Exists(char *, GNode *); char *Var_Value(char *, GNode *, char **); +void Var_AddCmdLine(char *); char *Var_Parse(char *, GNode *, Boolean, int *, Boolean *); char *Var_Subst(char *, char *, GNode *, Boolean); char *Var_GetTail(char *); diff --git a/usr.bin/make/var.c b/usr.bin/make/var.c index 3499e2a7ff3c..42c56c5ec8d8 100644 --- a/usr.bin/make/var.c +++ b/usr.bin/make/var.c @@ -832,6 +832,44 @@ VarREError(int err, regex_t *pat, const char *str) } +#ifdef POSIX + + +/* In POSIX mode, variable assignments passed on the command line are + * propagated to sub makes through MAKEFLAGS. + */ +void +Var_AddCmdLine(char *name) +{ + const Var *v; + LstNode ln; + Buffer buf; + static const char quotable[] = " \t\n\\'\""; + char *s; + int first = 1; + + buf = Buf_Init (MAKE_BSIZE); + + for (ln = Lst_First(VAR_CMD->context); ln != NULL; + ln = Lst_Succ(ln)) { + if (!first) + Buf_AddByte(buf, ' '); + first = 0; + /* We assume variable names don't need quoting */ + v = (Var *)Lst_Datum(ln); + Buf_AddBytes(buf, strlen(v->name), v->name); + Buf_AddByte(buf, '='); + for (s = Buf_GetAll(v->val, (int *)NULL); *s != '\0'; s++) { + if (strchr(quotable, *s)) + Buf_AddByte(buf, '\\'); + Buf_AddByte(buf, *s); + } + } + Var_Append(name, Buf_GetAll(buf, (int *)NULL), VAR_GLOBAL); + Buf_Destroy(buf, 1); +} +#endif + /*- *----------------------------------------------------------------------- * Var_Parse -- |