Source-Changes-HG archive

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

[src/trunk]: src/usr.bin/make Modify handling of command line variable assign...



details:   https://anonhg.NetBSD.org/src/rev/92f707ce6808
branches:  trunk
changeset: 510928:92f707ce6808
user:      sjg <sjg%NetBSD.org@localhost>
date:      Sat Jun 09 05:22:47 2001 +0000

description:
Modify handling of command line variable assignments and their exporting
via MAKEFLAGS.  Instead of appending them directly to .MAKEFLAGS, put
them in .MAKEOVERRIDES (and ensure they are quoted).  This is now done
in Var_Set when it exports VAR_CMD's.
Use ExportMAKEFLAGS() to export MAKEFLAGS, using the combined content
of .MAKEFLAGS and .MAKEOVERRIDES (with duplicate supression).
If .MAKEFLAGS is assigned to in a Makefile, ExportMAKEFLAGS is called again.
This allows a line like:
.MAKEOVERRIDES=
to effectively stop the exporting of the command line vars in MAKEFLAGS.

diffstat:

 usr.bin/make/main.c  |  44 ++++++++++++++++++++++++++++++--------------
 usr.bin/make/make.h  |   4 +++-
 usr.bin/make/parse.c |   8 +++++---
 usr.bin/make/var.c   |  25 ++++++++++++++++++++++---
 4 files changed, 60 insertions(+), 21 deletions(-)

diffs (209 lines):

diff -r 7234ea554b08 -r 92f707ce6808 usr.bin/make/main.c
--- a/usr.bin/make/main.c       Sat Jun 09 05:17:51 2001 +0000
+++ b/usr.bin/make/main.c       Sat Jun 09 05:22:47 2001 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: main.c,v 1.67 2001/06/01 20:33:37 sjg Exp $    */
+/*     $NetBSD: main.c,v 1.68 2001/06/09 05:22:47 sjg Exp $    */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -39,7 +39,7 @@
  */
 
 #ifdef MAKE_BOOTSTRAP
-static char rcsid[] = "$NetBSD: main.c,v 1.67 2001/06/01 20:33:37 sjg Exp $";
+static char rcsid[] = "$NetBSD: main.c,v 1.68 2001/06/09 05:22:47 sjg Exp $";
 #else
 #include <sys/cdefs.h>
 #ifndef lint
@@ -51,7 +51,7 @@
 #if 0
 static char sccsid[] = "@(#)main.c     8.3 (Berkeley) 3/19/94";
 #else
-__RCSID("$NetBSD: main.c,v 1.67 2001/06/01 20:33:37 sjg Exp $");
+__RCSID("$NetBSD: main.c,v 1.68 2001/06/09 05:22:47 sjg Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -393,7 +393,6 @@
         */
        for (argv += optind, argc -= optind; *argv; ++argv, --argc)
                if (Parse_IsVar(*argv)) {
-                       Var_Append(MAKEFLAGS, *argv, VAR_GLOBAL);
                        Parse_DoVar(*argv, VAR_CMD);
                } else {
                        if (!**argv)
@@ -511,7 +510,7 @@
        Lst targs;      /* target nodes to create -- passed to Make_Init */
        Boolean outOfDate = TRUE;       /* FALSE if all targets up to date */
        struct stat sb, sa;
-       char *p, *p1, *path, *pathp, *pwd;
+       char *p1, *path, *pathp, *pwd;
        char mdpath[MAXPATHLEN + 1];
        char obpath[MAXPATHLEN + 1];
        char cdpath[MAXPATHLEN + 1];
@@ -711,6 +710,7 @@
        Var_Set("MAKE", argv[0], VAR_GLOBAL);
        Var_Set(".MAKE", argv[0], VAR_GLOBAL);
        Var_Set(MAKEFLAGS, "", VAR_GLOBAL);
+       Var_Set(MAKEOVERRIDES, "", VAR_GLOBAL);
        Var_Set("MFLAGS", "", VAR_GLOBAL);
 
        /*
@@ -832,15 +832,7 @@
            printf("job_pipe %d %d, maxjobs %d maxlocal %d compat %d\n", job_pipe[0], job_pipe[1], maxJobs,
                   maxLocal, compatMake);
 
-       /* Install all the flags into the MAKE envariable. */
-       if (((p = Var_Value(MAKEFLAGS, VAR_GLOBAL, &p1)) != NULL) && *p)
-#ifdef POSIX
-               setenv("MAKEFLAGS", p, 1);
-#else
-               setenv("MAKE", p, 1);
-#endif
-       if (p1)
-           free(p1);
+       ExportMAKEFLAGS(1);             /* initial export */
 
        Check_Cwd_av(0, NULL, 0);       /* initialize it */
        
@@ -1660,3 +1652,27 @@
     if (s && *s)
        printf("%s", s);
 }
+
+void
+ExportMAKEFLAGS(first)
+     int first;
+{
+    static int once = 1;
+    char tmp[64];
+    char *s;
+
+    if (once != first)
+       return;
+    once = 0;
+    
+    /* supress duplicates in MAKEOVERRIDES */
+    strncpy(tmp, "${.MAKEFLAGS} ${.MAKEOVERRIDES:O:u}", sizeof(tmp));
+    s = Var_Subst(NULL, tmp, VAR_GLOBAL, 0);
+    if (s && *s) {
+#ifdef POSIX
+       setenv("MAKEFLAGS", s, 1);
+#else
+       setenv("MAKE", s, 1);
+#endif
+    }
+}
diff -r 7234ea554b08 -r 92f707ce6808 usr.bin/make/make.h
--- a/usr.bin/make/make.h       Sat Jun 09 05:17:51 2001 +0000
+++ b/usr.bin/make/make.h       Sat Jun 09 05:22:47 2001 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: make.h,v 1.34 2001/06/01 20:33:37 sjg Exp $    */
+/*     $NetBSD: make.h,v 1.35 2001/06/09 05:22:47 sjg Exp $    */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -367,6 +367,7 @@
 extern char    *progname;      /* The program name */
 
 #define        MAKEFLAGS       ".MAKEFLAGS"
+#define        MAKEOVERRIDES   ".MAKEOVERRIDES"
 
 /*
  * debug control:
@@ -413,5 +414,6 @@
 char * Check_Cwd_Cmd __P((char *));
 void Check_Cwd __P((char **));
 void PrintOnError __P((char *));
+void ExportMAKEFLAGS __P((int));
 
 #endif /* _MAKE_H_ */
diff -r 7234ea554b08 -r 92f707ce6808 usr.bin/make/parse.c
--- a/usr.bin/make/parse.c      Sat Jun 09 05:17:51 2001 +0000
+++ b/usr.bin/make/parse.c      Sat Jun 09 05:22:47 2001 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: parse.c,v 1.67 2001/06/02 18:04:44 sommerfeld Exp $    */
+/*     $NetBSD: parse.c,v 1.68 2001/06/09 05:22:47 sjg Exp $   */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -39,14 +39,14 @@
  */
 
 #ifdef MAKE_BOOTSTRAP
-static char rcsid[] = "$NetBSD: parse.c,v 1.67 2001/06/02 18:04:44 sommerfeld Exp $";
+static char rcsid[] = "$NetBSD: parse.c,v 1.68 2001/06/09 05:22:47 sjg Exp $";
 #else
 #include <sys/cdefs.h>
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)parse.c    8.3 (Berkeley) 3/19/94";
 #else
-__RCSID("$NetBSD: parse.c,v 1.67 2001/06/02 18:04:44 sommerfeld Exp $");
+__RCSID("$NetBSD: parse.c,v 1.68 2001/06/09 05:22:47 sjg Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -1585,6 +1585,8 @@
         * Normal assignment -- just do it.
         */
        Var_Set(line, cp, ctxt);
+       if (strcmp(line, MAKEOVERRIDES) == 0)
+           ExportMAKEFLAGS(0);         /* re-export MAKEFLAGS */
     }
 }
 
diff -r 7234ea554b08 -r 92f707ce6808 usr.bin/make/var.c
--- a/usr.bin/make/var.c        Sat Jun 09 05:17:51 2001 +0000
+++ b/usr.bin/make/var.c        Sat Jun 09 05:22:47 2001 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: var.c,v 1.61 2001/06/05 06:00:39 explorer Exp $        */
+/*     $NetBSD: var.c,v 1.62 2001/06/09 05:22:47 sjg Exp $     */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -39,14 +39,14 @@
  */
 
 #ifdef MAKE_BOOTSTRAP
-static char rcsid[] = "$NetBSD: var.c,v 1.61 2001/06/05 06:00:39 explorer Exp $";
+static char rcsid[] = "$NetBSD: var.c,v 1.62 2001/06/09 05:22:47 sjg Exp $";
 #else
 #include <sys/cdefs.h>
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)var.c      8.3 (Berkeley) 3/19/94";
 #else
-__RCSID("$NetBSD: var.c,v 1.61 2001/06/05 06:00:39 explorer Exp $");
+__RCSID("$NetBSD: var.c,v 1.62 2001/06/09 05:22:47 sjg Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -468,7 +468,26 @@
      * to the environment (as per POSIX standard)
      */
     if (ctxt == VAR_CMD) {
+       char tmp[256];
+       char *exp;
+       int nbytes;
+       
        setenv(name, val, 1);
+
+       exp = 0;
+       if ((nbytes = snprintf(tmp, sizeof(tmp), "%s='%s'", name, val))
+           < sizeof(tmp)) {
+           exp = tmp;
+       } else {
+           /* alloca is handy, but not everyone has it. */
+           if ((exp = malloc(nbytes + 1)))
+               snprintf(exp, nbytes + 1, "%s='%s'", name, val);
+       }
+       if (exp) {
+           Var_Append(MAKEOVERRIDES, exp, VAR_GLOBAL);
+           if (exp != tmp)
+               free(exp);
+       }
     }
     if (name != cp)
        free(name);



Home | Main Index | Thread Index | Old Index