Source-Changes-HG archive

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

[src/netbsd-8]: src/usr.bin/make Pull up following revision(s) (requested by ...



details:   https://anonhg.NetBSD.org/src/rev/eb889e582e2a
branches:  netbsd-8
changeset: 850830:eb889e582e2a
user:      snj <snj%NetBSD.org@localhost>
date:      Tue Jul 18 15:26:14 2017 +0000

description:
Pull up following revision(s) (requested by jmcneill in ticket #113):
        usr.bin/make/main.c: 1.266-1.272
        usr.bin/make/make.1: revision 1.267
move some code out of the gigantic main function; no functional change.
--
-V: try to expand the variable again if the value contains a variable.
--
simplify
--
a variable that starts with \\ is not expanded.
--
Remove previous variable expansion code; sjg had already added the code to
do it. Note that the manual page already documents this behavior and does
not need to change:
        -dV -V VAR:     prints the raw variable
        -V VAR:         prints the expanded variable
--
make the code look like to 1.266
--
Add -v variable that always expands variables; restore -V the way it was.

diffstat:

 usr.bin/make/main.c |  172 +++++++++++++++++++++++++++++----------------------
 usr.bin/make/make.1 |    9 ++-
 2 files changed, 106 insertions(+), 75 deletions(-)

diffs (291 lines):

diff -r ee8c94226b9a -r eb889e582e2a usr.bin/make/main.c
--- a/usr.bin/make/main.c       Fri Jul 14 08:42:07 2017 +0000
+++ b/usr.bin/make/main.c       Tue Jul 18 15:26:14 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: main.c,v 1.265 2017/05/10 22:26:14 sjg Exp $   */
+/*     $NetBSD: main.c,v 1.265.2.1 2017/07/18 15:26:14 snj Exp $       */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -69,7 +69,7 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: main.c,v 1.265 2017/05/10 22:26:14 sjg Exp $";
+static char rcsid[] = "$NetBSD: main.c,v 1.265.2.1 2017/07/18 15:26:14 snj 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.265 2017/05/10 22:26:14 sjg Exp $");
+__RCSID("$NetBSD: main.c,v 1.265.2.1 2017/07/18 15:26:14 snj Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -155,7 +155,9 @@
 
 static Boolean         noBuiltins;     /* -r flag */
 static Lst             makefiles;      /* ordered list of makefiles to read */
-static Boolean         printVars;      /* print value of one or more vars */
+static int             printVars;      /* -[vV] argument */
+#define COMPAT_VARS 1
+#define EXPAND_VARS 2
 static Lst             variables;      /* list of variables to print */
 int                    maxJobs;        /* -j argument */
 static int             maxJobTokens;   /* -j argument */
@@ -408,7 +410,7 @@
        Boolean inOption, dashDash = FALSE;
        char found_path[MAXPATHLEN + 1];        /* for searching for sys.mk */
 
-#define OPTFLAGS "BC:D:I:J:NST:V:WXd:ef:ij:km:nqrstw"
+#define OPTFLAGS "BC:D:I:J:NST:V:WXd:ef:ij:km:nqrstv:w"
 /* Can't actually use getopt(3) because rescanning is not portable */
 
        getopt_def = OPTFLAGS;
@@ -533,8 +535,9 @@
                        Var_Append(MAKEFLAGS, argvalue, VAR_GLOBAL);
                        break;
                case 'V':
+               case 'v':
                        if (argvalue == NULL) goto noarg;
-                       printVars = TRUE;
+                       printVars = c == 'v' ? EXPAND_VARS : COMPAT_VARS;
                        (void)Lst_AtEnd(variables, argvalue);
                        Var_Append(MAKEFLAGS, "-V", VAR_GLOBAL);
                        Var_Append(MAKEFLAGS, argvalue, VAR_GLOBAL);
@@ -846,6 +849,89 @@
     free(mp);
 }
 
+static void
+doPrintVars(void)
+{
+       LstNode ln;
+       Boolean expandVars;
+
+       if (printVars == EXPAND_VARS)
+               expandVars = TRUE;
+       else 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);
+               char *value;
+               char *p1;
+               
+               if (strchr(var, '$')) {
+                       value = p1 = Var_Subst(NULL, var, VAR_GLOBAL,
+                           VARF_WANTRES);
+               } else if (expandVars) {
+                       char tmp[128];
+                       int len = snprintf(tmp, sizeof(tmp), "${%s}", var);
+                                                       
+                       if (len >= (int)sizeof(tmp))
+                               Fatal("%s: variable name too big: %s",
+                                   progname, var);
+                       value = p1 = Var_Subst(NULL, tmp, VAR_GLOBAL,
+                           VARF_WANTRES);
+               } else {
+                       value = Var_Value(var, VAR_GLOBAL, &p1);
+               }
+               printf("%s\n", value ? value : "");
+               free(p1);
+       }
+}
+
+static Boolean
+runTargets(void)
+{
+       Lst targs;      /* target nodes to create -- passed to Make_Init */
+       Boolean outOfDate;      /* FALSE if all targets up to date */
+
+       /*
+        * Have now read the entire graph and need to make a list of
+        * targets to create. If none was given on the command line,
+        * we consult the parsing module to find the main target(s)
+        * to create.
+        */
+       if (Lst_IsEmpty(create))
+               targs = Parse_MainName();
+       else
+               targs = Targ_FindList(create, TARG_CREATE);
+
+       if (!compatMake) {
+               /*
+                * Initialize job module before traversing the graph
+                * now that any .BEGIN and .END targets have been read.
+                * This is done only if the -q flag wasn't given
+                * (to prevent the .BEGIN from being executed should
+                * it exist).
+                */
+               if (!queryFlag) {
+                       Job_Init();
+                       jobsRunning = TRUE;
+               }
+
+               /* Traverse the graph, checking on all the targets */
+               outOfDate = Make_Run(targs);
+       } else {
+               /*
+                * Compat_Init will take care of creating all the
+                * targets as well as initializing the module.
+                */
+               Compat_Run(targs);
+               outOfDate = FALSE;
+       }
+       Lst_Destroy(targs, NULL);
+       return outOfDate;
+}
+
 /*-
  * main --
  *     The main function, for obvious reasons. Initializes variables
@@ -866,8 +952,7 @@
 int
 main(int argc, char **argv)
 {
-       Lst targs;      /* target nodes to create -- passed to Make_Init */
-       Boolean outOfDate = FALSE;      /* FALSE if all targets up to date */
+       Boolean outOfDate;      /* FALSE if all targets up to date */
        struct stat sb, sa;
        char *p1, *path;
        char mdpath[MAXPATHLEN];
@@ -992,7 +1077,7 @@
 
        create = Lst_Init(FALSE);
        makefiles = Lst_Init(FALSE);
-       printVars = FALSE;
+       printVars = 0;
        debugVflag = FALSE;
        variables = Lst_Init(FALSE);
        beSilent = FALSE;               /* Print commands as executed */
@@ -1372,73 +1457,13 @@
 
        /* 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);
-                       char *value;
-                       
-                       if (strchr(var, '$')) {
-                           value = p1 = Var_Subst(NULL, var, VAR_GLOBAL,
-                                                  VARF_WANTRES);
-                       } else if (expandVars) {
-                               char tmp[128];
-                                                               
-                               if (snprintf(tmp, sizeof(tmp), "${%s}", var) >= (int)(sizeof(tmp)))
-                                       Fatal("%s: variable name too big: %s",
-                                             progname, var);
-                               value = p1 = Var_Subst(NULL, tmp, VAR_GLOBAL,
-                                                      VARF_WANTRES);
-                       } else {
-                               value = Var_Value(var, VAR_GLOBAL, &p1);
-                       }
-                       printf("%s\n", value ? value : "");
-                       free(p1);
-               }
+               doPrintVars();
+               outOfDate = FALSE;
        } else {
-               /*
-                * Have now read the entire graph and need to make a list of
-                * targets to create. If none was given on the command line,
-                * we consult the parsing module to find the main target(s)
-                * to create.
-                */
-               if (Lst_IsEmpty(create))
-                       targs = Parse_MainName();
-               else
-                       targs = Targ_FindList(create, TARG_CREATE);
-
-               if (!compatMake) {
-                       /*
-                        * Initialize job module before traversing the graph
-                        * now that any .BEGIN and .END targets have been read.
-                        * This is done only if the -q flag wasn't given
-                        * (to prevent the .BEGIN from being executed should
-                        * it exist).
-                        */
-                       if (!queryFlag) {
-                               Job_Init();
-                               jobsRunning = TRUE;
-                       }
-
-                       /* Traverse the graph, checking on all the targets */
-                       outOfDate = Make_Run(targs);
-               } else {
-                       /*
-                        * Compat_Init will take care of creating all the
-                        * targets as well as initializing the module.
-                        */
-                       Compat_Run(targs);
-               }
+               outOfDate = runTargets();
        }
 
 #ifdef CLEANUP
-       Lst_Destroy(targs, NULL);
        Lst_Destroy(variables, NULL);
        Lst_Destroy(makefiles, NULL);
        Lst_Destroy(create, (FreeProc *)free);
@@ -1897,7 +1922,8 @@
 "usage: %s [-BeikNnqrstWwX] \n\
             [-C directory] [-D variable] [-d flags] [-f makefile]\n\
             [-I directory] [-J private] [-j max_jobs] [-m directory] [-T file]\n\
-            [-V variable] [variable=value] [target ...]\n", progname);
+            [-V variable] [-v variable] [variable=value] [target ...]\n",
+           progname);
        exit(2);
 }
 
diff -r ee8c94226b9a -r eb889e582e2a usr.bin/make/make.1
--- a/usr.bin/make/make.1       Fri Jul 14 08:42:07 2017 +0000
+++ b/usr.bin/make/make.1       Tue Jul 18 15:26:14 2017 +0000
@@ -1,4 +1,4 @@
-.\"    $NetBSD: make.1,v 1.266 2017/02/01 18:39:27 sjg Exp $
+.\"    $NetBSD: make.1,v 1.266.4.1 2017/07/18 15:26:14 snj Exp $
 .\"
 .\" Copyright (c) 1990, 1993
 .\"    The Regents of the University of California.  All rights reserved.
@@ -29,7 +29,7 @@
 .\"
 .\"    from: @(#)make.1        8.4 (Berkeley) 3/19/94
 .\"
-.Dd February 1, 2017
+.Dd June 19, 2017
 .Dt MAKE 1
 .Os
 .Sh NAME
@@ -48,6 +48,7 @@
 .Op Fl m Ar directory
 .Op Fl T Ar file
 .Op Fl V Ar variable
+.Op Fl v Ar variable
 .Op Ar variable=value
 .Op Ar target ...
 .Sh DESCRIPTION
@@ -348,6 +349,10 @@
 contains a
 .Ql \&$
 then the value will be expanded before printing.
+.It Fl v Ar variable
+Like 
+.Fl V
+but the variable is always expanded to its final value.
 .It Fl W
 Treat any warnings during makefile parsing as errors.
 .It Fl w



Home | Main Index | Thread Index | Old Index