DragonFly BSD
DragonFly submit List (threaded) for 2005-04
[Date Prev][Date Next]  [Thread Prev][Thread Next]  [Date Index][Thread Index]

.makeenv to .MAKEENV


To: Harti Brandt <harti@xxxxxxxxxxx>
From: Max Okumoto <okumoto@xxxxxxxx>
Date: Thu, 07 Apr 2005 04:05:56 -0700

Matt,

If we change the ".makeenv" directive to the special target
".MAKEENV:" like harti requested, would it make sense to
change the name to something like ".EXPORT:" ?  Will we
ever require unexporting variables from make?  We can
accomplish this ether by adding a ".UNEXPORT:" target, or
we can require the user to use ".undef" directive.  Which
would be similar to what /bin/sh does for export.

patch-7.172
	o add .MAKEENV: as a special target. It only takes one value
	  argument.

Harti,
	The patch-1.1 and patch 7.172 should add just the
	".MAKEENV:" special target work.

Any comments?
				Max
diff -ru  fbsd-src/make/parse.c dfly-src/make/parse.c
--- fbsd-src/make/parse.c	Thu Apr  7 00:57:37 2005
+++ dfly-src/make/parse.c	Thu Apr  7 03:29:25 2005
@@ -165,6 +165,7 @@
 	Libs,		/* .LIBS */
 	MFlags,		/* .MFLAGS or .MAKEFLAGS */
 	Main,		/* .MAIN and we don't have anyth. user-spec. to make */
+	MakeEnv,	/* .MAKEENV */
 	NoExport,	/* .NOEXPORT */
 	Not,		/* Not special */
 	NotParallel,	/* .NOTPARALELL */
@@ -217,6 +218,7 @@
 	{ ".MAIN",		Main,		0 },
 	{ ".MAKE",		Attribute,	OP_MAKE },
 	{ ".MAKEFLAGS",		MFlags,		0 },
+	{ ".MAKEENV",		MakeEnv,	0 },
 	{ ".MFLAGS",		MFlags,		0 },
 	{ ".NOTMAIN",		Attribute,	OP_NOTMAIN },
 	{ ".NOTPARALLEL",	NotParallel,	0 },
@@ -1147,6 +1149,9 @@
 			line = cp;
 		}
 		Lst_Destroy(&paths, NOFREE);
+
+	} else if (specType == MakeEnv) {
+		Var_SetEnv(line, VAR_GLOBAL);
 
 	} else {
 		/* list of sources in order */
---------------------
PatchSet 28
Date: 2003/11/18 23:49:54
Date: 2004/01/29 22:40:36
Author: dillon
Log:

o Add a .makeenv directive to make, which allows variables to be
  exported to the environment.  This will be used to support certain
  ports hacks but it will also be generally useful in the future.

o Set a variable indicating that we support .makeenv, so we can
  conditionalize its use.

Members: 
	make.1:1.2->1.3 
	nonints.h:1.3->1.4 
	parse.c:1.3->1.4 
	var.c:1.3->1.4 
	main.c:1.4->1.5 


diff -ru  fbsd-src/make/main.c dfly-src/make/main.c
--- fbsd-src/make/main.c	Sat Mar 19 17:24:36 2005
+++ dfly-src/make/main.c	Sat Mar 19 17:24:38 2005
@@ -672,6 +672,7 @@
 	Dir_InitDot();		/* Initialize the "." directory */
 	if (objdir != curdir)
 		Path_AddDir(&dirSearchPath, curdir);
+	Var_Set(".DIRECTIVE_MAKEENV", "YES", VAR_GLOBAL);
 	Var_Set(".CURDIR", curdir, VAR_GLOBAL);
 	Var_Set(".OBJDIR", objdir, VAR_GLOBAL);
 
diff -ru  fbsd-src/make/make.1 dfly-src/make/make.1
--- fbsd-src/make/make.1	Sat Mar 19 17:24:31 2005
+++ dfly-src/make/make.1	Sat Mar 19 17:24:38 2005
@@ -810,6 +810,9 @@
 .It Ic .undef Ar variable
 Un-define the specified global variable.
 Only global variables may be un-defined.
+.It Ic \&.makeenv Ar variable
+Set the environment flag for a preexisting global variable.  The current
+and future contents of the variable will be exported to the environment.
 .It Ic .error Ar message
 Terminate processing of the makefile immediately.
 The filename of the
diff -ru  fbsd-src/make/parse.c dfly-src/make/parse.c
--- fbsd-src/make/parse.c	Sat Mar 19 17:24:36 2005
+++ dfly-src/make/parse.c	Sat Mar 19 17:24:38 2005
@@ -547,6 +547,20 @@
     }
 }
 
+static char *
+stripvarname(char *cp)
+{
+	char   *cp2;
+
+	while (isspace((unsigned char)*cp))
+		++cp;
+	cp2 = cp;
+	while (*cp2 && !isspace((unsigned char)*cp2))
+		++cp2;
+	*cp2 = 0;
+	return (cp);
+}
+
 
 /*-
  *---------------------------------------------------------------------
@@ -2306,26 +2320,12 @@
 					ParseDoWarning(cp + 7);
 					goto nextLine;
 				} else if (strncmp(cp, "undef", 5) == 0) {
-					char *cp2;
-					for (cp += 5;
-					    isspace((unsigned char)*cp);
-					    cp++) {
-						continue;
-					}
-
-					for (cp2 = cp;
-					    !isspace((unsigned char)*cp2) &&
-					   *cp2 != '\0'; cp2++) {
-						continue;
-					}
-
-					*cp2 = '\0';
-
+					cp = stripvarname(cp + 5);
 					buf = Var_Subst(NULL, cp, VAR_CMD,
 					    FALSE);
 					cp = Buf_Peel(buf);
 
 					Var_Delete(cp, VAR_GLOBAL);
					goto nextLine;
 				}
 			}
diff -ru  fbsd-src/make/var.c dfly-src/make/var.c
--- fbsd-src/make/var.c	Sat Mar 19 17:24:36 2005
+++ dfly-src/make/var.c	Sat Mar 19 17:24:41 2005
@@ -445,10 +445,30 @@
 	 * Any variables given on the command line are automatically exported
 	 * to the environment (as per POSIX standard)
 	 */
-	if (ctxt == VAR_CMD) {
+	if (ctxt == VAR_CMD || (v != NULL && (v->flags & VAR_TO_ENV))) {
 		setenv(n, val, 1);
 	}
 	free(n);
+}
+
+/*
+ * Var_SetEnv --
+ *	Set the VAR_TO_ENV flag on a variable
+ */
+void
+Var_SetEnv(const char *name, GNode *ctxt)
+{
+	Var    *v;
+
+	v = VarFind(name, ctxt, FIND_CMD | FIND_GLOBAL | FIND_ENV);
+	if (v == NULL) {
+		Error("Cannot set environment flag on non-existant variable %s", name);
+	} else {
+		if ((v->flags & VAR_TO_ENV) == 0) {
+			v->flags |= VAR_TO_ENV;
+			setenv(v->name, Buf_Data(v->val), 1);
+		}
+	}
 }
 
 /*-
diff -ru  fbsd-src/make/var.h dfly-src/make/var.h
--- fbsd-src/make/var.h	Sat Mar 19 17:24:36 2005
+++ dfly-src/make/var.h	Sat Mar 19 17:24:41 2005
@@ -62,6 +62,8 @@
 				 * should be destroyed when done with
 				 * it. Used by Var_Parse for undefined,
 				 * modified variables */
+
+#define	VAR_TO_ENV	8	/* Place variable in environment */
 } Var;
 
 /* Var*Pattern flags */
@@ -98,6 +100,7 @@
 char *Var_Parse(const char *, struct GNode *, Boolean, size_t *, Boolean *);
 char *Var_Quote(const char *);
 void Var_Set(const char *, const char *, struct GNode *);
+void Var_SetEnv(const char *, struct GNode *);
 struct Buffer *Var_Subst(const char *, const char *, struct GNode *, Boolean);
 char *Var_Value(const char *, struct GNode *, char **);
 


[Date Prev][Date Next]  [Thread Prev][Thread Next]  [Date Index][Thread Index]