From d2e0d34c9ce1adfc8d83003dd201b7537ecd0bf4 Mon Sep 17 00:00:00 2001 From: Joerg Sonnenberger Date: Wed, 1 Dec 2004 01:10:17 +0000 Subject: [PATCH] Makefile: 1.31->1.32 main.c: 1.89->1.90 nonints.h: 1.21->1.22 var.c: 1.46->1.47 Author: harti Log: 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 Approved by: portmgr Obtained from: NetBSD (1st part above) MFC after: 4 weeks make.1: 1.75->1.76 Author: harti Log: Correct the description of the MFLAGS and .MAKEFLAGS variables. Add the MFLAGS target. Document that variable assignments from the MAKEFLAGS environment variable and the .MAKEFLAGS and .MFLAGS target have the same precedence as command line variable assignments. make.1: 1.76->1.77 Author: harti Log: Correct the .Dd date. Pluralize 'assignment' in one place. Requested by: ru --- usr.bin/make/Makefile | 4 +-- usr.bin/make/main.c | 72 +++++++++++++++++++++++------------------- usr.bin/make/make.1 | 26 ++++++++++----- usr.bin/make/nonints.h | 3 +- usr.bin/make/var.c | 40 ++++++++++++++++++++++- 5 files changed, 101 insertions(+), 44 deletions(-) diff --git a/usr.bin/make/Makefile b/usr.bin/make/Makefile index a295006e90..3ca38974e9 100644 --- a/usr.bin/make/Makefile +++ b/usr.bin/make/Makefile @@ -1,6 +1,6 @@ # @(#)Makefile 5.2 (Berkeley) 12/28/90 # $FreeBSD: src/usr.bin/make/Makefile,v 1.13.2.1 2001/05/25 08:33:40 sobomax Exp $ -# $DragonFly: src/usr.bin/make/Makefile,v 1.7 2004/11/24 07:24:17 dillon Exp $ +# $DragonFly: src/usr.bin/make/Makefile,v 1.8 2004/12/01 01:10:17 joerg Exp $ PROG= make CFLAGS+=-I${.CURDIR} @@ -15,7 +15,7 @@ SRCS+= lstAppend.c lstAtEnd.c lstAtFront.c lstClose.c lstConcat.c \ NOSHARED?= YES -CFLAGS+=-DMAKE_VERSION=\"5200208240\" +CFLAGS+=-DMAKE_VERSION=\"5200408030\" # XXX: kernel currently broken # CFLAGS+=-DUSE_KQUEUE diff --git a/usr.bin/make/main.c b/usr.bin/make/main.c index 31037f1dfb..4c8b9290f6 100644 --- a/usr.bin/make/main.c +++ b/usr.bin/make/main.c @@ -38,7 +38,7 @@ * @(#) Copyright (c) 1988, 1989, 1990, 1993 The Regents of the University of California. All rights reserved. * @(#)main.c 8.3 (Berkeley) 3/19/94 * $FreeBSD: src/usr.bin/make/main.c,v 1.35.2.10 2003/12/16 08:34:11 des Exp $ - * $DragonFly: src/usr.bin/make/main.c,v 1.21 2004/11/30 15:52:57 joerg Exp $ + * $DragonFly: src/usr.bin/make/main.c,v 1.22 2004/12/01 01:10:17 joerg Exp $ */ /*- @@ -127,6 +127,21 @@ 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 @@ -161,25 +176,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': { @@ -191,18 +203,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; @@ -256,27 +267,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; @@ -291,43 +300,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 '?': @@ -622,6 +629,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 @@ -765,9 +776,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/make.1 b/usr.bin/make/make.1 index 50e25fa5cf..71c7f1e42c 100644 --- a/usr.bin/make/make.1 +++ b/usr.bin/make/make.1 @@ -31,9 +31,9 @@ .\" .\" from: @(#)make.1 8.4 (Berkeley) 3/19/94 .\" $FreeBSD: src/usr.bin/make/make.1,v 1.29.2.15 2002/12/17 19:01:18 seanc Exp $ -.\" $DragonFly: src/usr.bin/make/make.1,v 1.12 2004/11/30 19:12:57 joerg Exp $ +.\" $DragonFly: src/usr.bin/make/make.1,v 1.13 2004/12/01 01:10:17 joerg Exp $ .\" -.Dd July 29, 2004 +.Dd August 4, 2004 .Dt MAKE 1 .Os .Sh NAME @@ -396,7 +396,12 @@ environment. .It Global variables Variables defined in the makefile or in included makefiles. .It Command line variables -Variables defined as part of the command line. +Variables defined as part of the command line and variables +obtained from the +.Ev MAKEFLAGS +environment variable or the +.Ic .MAKEFLAGS +target. .It Local variables Variables that are defined specific to a certain target. The seven local variables are as follows: @@ -559,9 +564,9 @@ Its contents are stored in .Nm Ns 's .Va .MAKEFLAGS variable. -Anything specified on +All options and variable assignments specified on .Nm Ns 's -command line is appended to the +command line are appended to the .Va .MAKEFLAGS variable which is then entered into the environment as @@ -570,9 +575,12 @@ for all programs which .Nm executes. .It Va MFLAGS -A synonym for -.Va .MAKEFLAGS -provided for backward compatibility. +is provided for backward compatibility and +contains all the options from the +.Ev MAKEFLAGS +environment variable plus any options specified on +.Nm Ns 's +command line. .It Va .TARGETS List of targets .Nm @@ -1132,6 +1140,8 @@ The flags are as if typed to the shell, though the .Fl f option will have no effect. +.It Ic .MFLAGS +Same as above, for backward compatibility. .\" XXX: NOT YET!!!! .\" .It Ic .NOTPARALLEL .\" The named targets are executed in non parallel mode. If no targets are diff --git a/usr.bin/make/nonints.h b/usr.bin/make/nonints.h index 3749523c77..a1cee14111 100644 --- a/usr.bin/make/nonints.h +++ b/usr.bin/make/nonints.h @@ -37,7 +37,7 @@ * * from: @(#)nonints.h 8.3 (Berkeley) 3/19/94 * $FreeBSD: src/usr.bin/make/nonints.h,v 1.8 1999/08/28 01:03:35 peter Exp $ - * $DragonFly: src/usr.bin/make/Attic/nonints.h,v 1.16 2004/11/30 19:12:57 joerg Exp $ + * $DragonFly: src/usr.bin/make/Attic/nonints.h,v 1.17 2004/12/01 01:10:17 joerg Exp $ */ /* arch.c */ @@ -138,6 +138,7 @@ void Var_SetEnv(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 97de6a3182..9b9cf9d0eb 100644 --- a/usr.bin/make/var.c +++ b/usr.bin/make/var.c @@ -37,7 +37,7 @@ * * @(#)var.c 8.3 (Berkeley) 3/19/94 * $FreeBSD: src/usr.bin/make/var.c,v 1.16.2.3 2002/02/27 14:18:57 cjc Exp $ - * $DragonFly: src/usr.bin/make/var.c,v 1.15 2004/11/30 15:52:57 joerg Exp $ + * $DragonFly: src/usr.bin/make/var.c,v 1.16 2004/12/01 01:10:17 joerg Exp $ */ /*- @@ -772,6 +772,44 @@ VarGetPattern(GNode *ctxt, int err, char **tstr, int delim, int *flags, } +#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 + /*- *----------------------------------------------------------------------- * VarQuote -- -- 2.41.0