tech-toolchain archive

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

Re: make -V



On Wed, 22 Aug 2012 19:38:05 -0700, "Simon J. Gerraty" writes:
>Sorry, to open this again...
>
>On Sun, 12 Aug 2012 05:14:36 +1000, matthew green writes:
>>> No problem.  It would seem the consensus is leave things as is.
>>> It would have been useful to not have to re-work all the freebsd ports
>>> collection - which relies on make -V PKGNAME doing full expansion.
>
>What if this behavior were controlled by a knob
>such that the default behavior is unchanged? 
>
>This would allow a setting in sys.mk for FreeBSD to maintain
>compatability for them.
>
>The patch is trivial (I had it laying around - just need to find it ;-)

Index: main.c
===================================================================
RCS file: /cvsroot/src/usr.bin/make/main.c,v
retrieving revision 1.200
diff -u -p -r1.200 main.c
--- main.c      12 Jun 2012 19:21:51 -0000      1.200
+++ main.c      23 Aug 2012 03:13:56 -0000
@@ -1214,7 +1214,9 @@ main(int argc, char **argv)
        /* print the values of any variables requested by the user */
        if (printVars) {
                LstNode ln;
+               Boolean expandVars;
 
+               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 +1224,13 @@ main(int argc, char **argv)
                        
                        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 +2028,49 @@ mkTempFile(const char *pattern, char **f
     }
     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);
+}
Index: nonints.h
===================================================================
RCS file: /cvsroot/src/usr.bin/make/nonints.h,v
retrieving revision 1.64
diff -u -p -r1.64 nonints.h
--- nonints.h   12 Jun 2012 19:21:51 -0000      1.64
+++ nonints.h   23 Aug 2012 03:13:56 -0000
@@ -118,6 +118,7 @@ void Finish(int) MAKE_ATTR_DEAD;
 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