summaryrefslogtreecommitdiffstats
path: root/usr.bin/make
diff options
context:
space:
mode:
authorharti <harti@FreeBSD.org>2004-08-03 18:56:31 +0000
committerharti <harti@FreeBSD.org>2004-08-03 18:56:31 +0000
commitfbcc82e0b7d364f7f6be5779662e55171ad40c32 (patch)
treec5ef8ec3263a3b61b02de03c0b5591c884c7ca46 /usr.bin/make
parent35780dc21adda12f4e93177415556e6698e017e4 (diff)
downloadFreeBSD-src-fbcc82e0b7d364f7f6be5779662e55171ad40c32.zip
FreeBSD-src-fbcc82e0b7d364f7f6be5779662e55171ad40c32.tar.gz
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
Diffstat (limited to 'usr.bin/make')
-rw-r--r--usr.bin/make/Makefile2
-rw-r--r--usr.bin/make/main.c70
-rw-r--r--usr.bin/make/nonints.h1
-rw-r--r--usr.bin/make/var.c38
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 --
OpenPOWER on IntegriCloud