diff options
Diffstat (limited to 'usr.bin/make')
-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 2b3e22b..ca728fd 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 bbc6ab5..b835586 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 e2da28e..e1bfae3 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 3499e2a..42c56c5 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 -- |