Source-Changes-HG archive

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

[src/trunk]: src/usr.bin/make Add a knob to control whether -V fully expands ...



details:   https://anonhg.NetBSD.org/src/rev/6f20a4215379
branches:  trunk
changeset: 781286:6f20a4215379
user:      sjg <sjg%NetBSD.org@localhost>
date:      Thu Aug 30 21:17:05 2012 +0000

description:
Add a knob to control whether -V fully expands a plain variable by default.
The default retains the traditional NetBSD behavior, but the knob
can be set so that FreeBSD can retain their expected behavior.
This is a compromise to be sure.

Add a debug flag -dV to override the above, so that regardless of
the knob setting, the raw value of a variable can be easily seen.

diffstat:

 usr.bin/make/main.c    |  69 +++++++++++++++++++++++++++++++++++++++++++++++--
 usr.bin/make/nonints.h |   3 +-
 2 files changed, 68 insertions(+), 4 deletions(-)

diffs (147 lines):

diff -r a32954a47fc4 -r 6f20a4215379 usr.bin/make/main.c
--- a/usr.bin/make/main.c       Thu Aug 30 12:42:41 2012 +0000
+++ b/usr.bin/make/main.c       Thu Aug 30 21:17:05 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: main.c,v 1.200 2012/06/12 19:21:51 joerg Exp $ */
+/*     $NetBSD: main.c,v 1.201 2012/08/30 21:17:05 sjg Exp $   */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -69,7 +69,7 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: main.c,v 1.200 2012/06/12 19:21:51 joerg Exp $";
+static char rcsid[] = "$NetBSD: main.c,v 1.201 2012/08/30 21:17:05 sjg Exp $";
 #else
 #include <sys/cdefs.h>
 #ifndef lint
@@ -81,7 +81,7 @@
 #if 0
 static char sccsid[] = "@(#)main.c     8.3 (Berkeley) 3/19/94";
 #else
-__RCSID("$NetBSD: main.c,v 1.200 2012/06/12 19:21:51 joerg Exp $");
+__RCSID("$NetBSD: main.c,v 1.201 2012/08/30 21:17:05 sjg Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -159,6 +159,7 @@
 static int             maxJobTokens;   /* -j argument */
 Boolean                        compatMake;     /* -B argument */
 int                    debug;          /* -d argument */
+Boolean                        debugVflag;     /* -dV */
 Boolean                        noExecute;      /* -n flag */
 Boolean                        noRecursiveExecute;     /* -N flag */
 Boolean                        keepgoing;      /* -k flag */
@@ -260,6 +261,9 @@
                case 't':
                        debug |= DEBUG_TARG;
                        break;
+               case 'V':
+                       debugVflag = TRUE;
+                       break;
                case 'v':
                        debug |= DEBUG_VAR;
                        break;
@@ -877,6 +881,7 @@
        create = Lst_Init(FALSE);
        makefiles = Lst_Init(FALSE);
        printVars = FALSE;
+       debugVflag = FALSE;
        variables = Lst_Init(FALSE);
        beSilent = FALSE;               /* Print commands as executed */
        ignoreErrors = FALSE;           /* Pay attention to non-zero returns */
@@ -1214,7 +1219,12 @@
        /* print the values of any variables requested by the user */
        if (printVars) {
                LstNode ln;
+               Boolean expandVars;
 
+               if (debugVflag)
+                       expandVars = FALSE;
+               else
+                       expandVars = getBoolean(".MAKE.EXPAND_VARIABLES", FALSE);
                for (ln = Lst_First(variables); ln != NULL;
                    ln = Lst_Succ(ln)) {
                        char *var = (char *)Lst_Datum(ln);
@@ -1222,6 +1232,13 @@
                        
                        if (strchr(var, '$')) {
                                value = p1 = Var_Subst(NULL, var, VAR_GLOBAL, 0);
+                       } else if (expandVars) {
+                               char tmp[128];
+                                                               
+                               if (snprintf(tmp, sizeof(tmp), "${%s}", var) >= sizeof(tmp))
+                                       Fatal("%s: variable name too big: %s",
+                                             progname, var);
+                               value = p1 = Var_Subst(NULL, tmp, VAR_GLOBAL, 0);
                        } else {
                                value = Var_Value(var, VAR_GLOBAL, &p1);
                        }
@@ -2019,3 +2036,49 @@
     }
     return fd;
 }
+
+
+/*
+ * Return a Boolean based on setting of a knob.
+ *
+ * If the knob is not set, the supplied default is the return value.
+ * If set, anything that looks or smells like "No", "False", "Off", "0" etc,
+ * is FALSE, otherwise TRUE.
+ */
+Boolean
+getBoolean(const char *name, Boolean bf)
+{
+    char tmp[64];
+    char *cp;
+
+    if (snprintf(tmp, sizeof(tmp), "${%s:tl}", name) < sizeof(tmp)) {
+       cp = Var_Subst(NULL, tmp, VAR_GLOBAL, 0);
+
+       if (cp) {
+           switch(*cp) {
+           case '\0':                  /* not set - the default wins */
+               break;
+           case '0':
+           case 'f':
+           case 'n':
+               bf = FALSE;
+               break;
+           case 'o':
+               switch (cp[1]) {
+               case 'f':
+                   bf = FALSE;
+                   break;
+               default:
+                   bf = TRUE;
+                   break;
+               }
+               break;
+           default:
+               bf = TRUE;
+               break;
+           }
+           free(cp);
+       }
+    }
+    return (bf);
+}
diff -r a32954a47fc4 -r 6f20a4215379 usr.bin/make/nonints.h
--- a/usr.bin/make/nonints.h    Thu Aug 30 12:42:41 2012 +0000
+++ b/usr.bin/make/nonints.h    Thu Aug 30 21:17:05 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: nonints.h,v 1.64 2012/06/12 19:21:51 joerg Exp $       */
+/*     $NetBSD: nonints.h,v 1.65 2012/08/30 21:17:05 sjg Exp $ */
 
 /*-
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -118,6 +118,7 @@
 int eunlink(const char *);
 void execError(const char *, const char *);
 char *getTmpdir(void);
+Boolean getBoolean(const char *, Boolean);
 
 /* parse.c */
 void Parse_Error(int, const char *, ...) MAKE_ATTR_PRINTFLIKE(2, 3);



Home | Main Index | Thread Index | Old Index