standards/57295: [patch] make does not include cmd line
variables in MAKEFLAGS
James E. Flemer
jflemer at alum.rpi.edu
Sun Sep 28 14:50:21 PDT 2003
The following reply was made to PR standards/57295; it has been noted by GNATS.
From: "James E. Flemer" <jflemer at alum.rpi.edu>
To: FreeBSD-gnats-submit at freebsd.org
Cc:
Subject: Re: standards/57295: [patch] make does not include cmd line variables in MAKEFLAGS
Date: Sun, 28 Sep 2003 17:42:45 -0400 (EDT)
The patch I submitted does not do necessary quoting when values
contain spaces etc. It turns out that OpenBSD has a fix for the
MAKEFLAGS issue that fits into FreeBSD make with a few modifications.
Here is a patch based on the OpenBSD solution. Some changes were
needed to match our data structures, but the functionality is
directly from the OpenBSD commit.
Obtained From: OpenBSD
$OpenBSD: var.c,v 1.46 2000/07/18 20:17:20 espie Exp $
$OpenBSD: main.c,v 1.39 2000/07/18 20:17:20 espie Exp $
--- make.diff begins here ---
Index: main.c
===================================================================
RCS file: /home/ncvs/src/usr.bin/make/main.c,v
retrieving revision 1.84
diff -u -r1.84 main.c
--- main.c 14 Sep 2003 12:31:33 -0000 1.84
+++ main.c 28 Sep 2003 21:17:09 -0000
@@ -616,6 +616,10 @@
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
Index: nonints.h
===================================================================
RCS file: /home/ncvs/src/usr.bin/make/nonints.h,v
retrieving revision 1.19
diff -u -r1.19 nonints.h
--- nonints.h 28 Oct 2002 23:33:57 -0000 1.19
+++ nonints.h 28 Sep 2003 21:17:09 -0000
@@ -135,6 +135,7 @@
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 *);
Index: var.c
===================================================================
RCS file: /home/ncvs/src/usr.bin/make/var.c,v
retrieving revision 1.43
diff -u -r1.43 var.c
--- var.c 18 Sep 2003 03:15:57 -0000 1.43
+++ var.c 28 Sep 2003 21:17:09 -0000
@@ -832,6 +832,42 @@
}
+#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;
+ unsigned int i;
+ Buffer buf;
+ static const char quotable[] = " \t\n\\'\"";
+ char *s;
+
+ buf = Buf_Init (MAKE_BSIZE);
+
+ for (ln = Lst_First(VAR_CMD->context); ln != NULL;
+ ln = Lst_Succ(ln)) {
+ /* 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);
+ }
+ Buf_AddByte(buf, ' ');
+ }
+ Var_Append(name, Buf_GetAll(buf, (int *)NULL), VAR_GLOBAL);
+ Buf_Destroy(buf, 1);
+}
+#endif
+
/*-
*-----------------------------------------------------------------------
* Var_Parse --
--- make.diff ends here ---
More information about the freebsd-standards
mailing list