Source-Changes-HG archive

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

[src/trunk]: src/usr.bin/make More gmake compatibility:



details:   https://anonhg.NetBSD.org/src/rev/6921e64f5e89
branches:  trunk
changeset: 787945:6921e64f5e89
user:      christos <christos%NetBSD.org@localhost>
date:      Tue Jul 16 14:00:53 2013 +0000

description:
More gmake compatibility:
1. add -w flag to print Entering and Leaving directory name the the beginning
   and the end of processing.
2. export MAKELEVEL=$((MAKELEVEL + 1)) only in the child environment.
3. when printing error messages, prefix them with the program name [$MAKELEVEL]
   for $MAKELEVEL > 0
4. if $MAKEFLAGS consists only of letters assume it is a set of flags (as
   allowed by posix), convert them to -f -l -a -g -s, so that they get parsed
   properly.
With those fixes gmake -> bmake -> gmake -> bmake etc. works as expected.

diffstat:

 usr.bin/make/main.c |  74 +++++++++++++++++++++++++++++++++++++++++++++++-----
 usr.bin/make/make.1 |   8 +++--
 usr.bin/make/var.c  |  25 +++++++++--------
 3 files changed, 84 insertions(+), 23 deletions(-)

diffs (279 lines):

diff -r f3dd1766103f -r 6921e64f5e89 usr.bin/make/main.c
--- a/usr.bin/make/main.c       Tue Jul 16 10:49:36 2013 +0000
+++ b/usr.bin/make/main.c       Tue Jul 16 14:00:53 2013 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: main.c,v 1.219 2013/07/15 20:33:11 christos Exp $      */
+/*     $NetBSD: main.c,v 1.220 2013/07/16 14:00:53 christos Exp $      */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -69,7 +69,7 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: main.c,v 1.219 2013/07/15 20:33:11 christos Exp $";
+static char rcsid[] = "$NetBSD: main.c,v 1.220 2013/07/16 14:00:53 christos 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.219 2013/07/15 20:33:11 christos Exp $");
+__RCSID("$NetBSD: main.c,v 1.220 2013/07/16 14:00:53 christos Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -128,6 +128,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <time.h>
+#include <ctype.h>
 
 #include "make.h"
 #include "hash.h"
@@ -163,6 +164,7 @@
 Boolean                        keepgoing;      /* -k flag */
 Boolean                        queryFlag;      /* -q flag */
 Boolean                        touchFlag;      /* -t flag */
+Boolean                        enterFlag;      /* -w flag */
 Boolean                        ignoreErrors;   /* -i flag */
 Boolean                        beSilent;       /* -s flag */
 Boolean                        oldVars;        /* variable substitution style */
@@ -184,11 +186,44 @@
 char *progname;                                /* the program name */
 char *makeDependfile;
 pid_t myPid;
+int makelevel;
 
 Boolean forceJobs = FALSE;
 
 extern Lst parseIncPath;
 
+/*
+ * For compatibility with the POSIX version of MAKEFLAGS that includes
+ * all the options with out -, convert flags to -f -l -a -g -s.
+ */
+static char *
+explode(const char *flags)
+{
+    size_t len;
+    char *nf, *st;
+    const char *f;
+
+    if (flags == NULL)
+       return NULL;
+
+    for (f = flags; *f; f++)
+       if (!isalpha((unsigned char)*f))
+           break;
+
+    if (*f)
+       return estrdup(flags);
+
+    len = strlen(flags);
+    st = nf = emalloc(len * 3 + 1);
+    while (*flags) {
+       *nf++ = '-';
+       *nf++ = *flags++;
+       *nf++ = ' ';
+    }
+    *nf = '\0';
+    return st;
+}
+           
 static void
 parse_debug_options(const char *argvalue)
 {
@@ -341,7 +376,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:nqrst"
+#define OPTFLAGS "BC:D:I:J:NST:V:WXd:ef:ij:km:nqrstw"
 /* Can't actually use getopt(3) because rescanning is not portable */
 
        getopt_def = OPTFLAGS;
@@ -549,6 +584,10 @@
                        touchFlag = TRUE;
                        Var_Append(MAKEFLAGS, "-t", VAR_GLOBAL);
                        break;
+               case 'w':
+                       enterFlag = TRUE;
+                       Var_Append(MAKEFLAGS, "-w", VAR_GLOBAL);
+                       break;
                case '-':
                        dashDash = TRUE;
                        break;
@@ -941,14 +980,21 @@
        {
            char tmp[64], *ep;
 
-           snprintf(tmp, sizeof(tmp), "%d",
-               ((ep = getenv(MAKE_LEVEL_ENV)) && *ep) ? atoi(ep) + 1 : 0);
+           makelevel = ((ep = getenv(MAKE_LEVEL_ENV)) && *ep) ? atoi(ep) : 0;
+           if (makelevel < 0)
+               makelevel = 0;
+           snprintf(tmp, sizeof(tmp), "%d", makelevel);
            Var_Set(MAKE_LEVEL, tmp, VAR_GLOBAL, 0);
            snprintf(tmp, sizeof(tmp), "%u", myPid);
            Var_Set(".MAKE.PID", tmp, VAR_GLOBAL, 0);
            snprintf(tmp, sizeof(tmp), "%u", getppid());
            Var_Set(".MAKE.PPID", tmp, VAR_GLOBAL, 0);
        }
+       if (makelevel > 0) {
+               char pn[1024];
+               snprintf(pn, sizeof(pn), "%s[%d]", progname, makelevel);
+               progname = estrdup(pn);
+       }
        Job_SetPrefix();
 
 #ifdef USE_META
@@ -960,7 +1006,9 @@
         * in a different format).
         */
 #ifdef POSIX
-       Main_ParseArgLine(getenv("MAKEFLAGS"));
+       p1 = explode(getenv("MAKEFLAGS"));
+       Main_ParseArgLine(p1);
+       free(p1);
 #else
        Main_ParseArgLine(getenv("MAKE"));
 #endif
@@ -977,6 +1025,9 @@
 
        MainParseArgs(argc, argv);
 
+       if (enterFlag)
+               printf("%s: Entering directory `%s'\n", progname, curdir);
+
        /*
         * Verify that cwd is sane.
         */
@@ -1293,6 +1344,9 @@
 
        Trace_Log(MAKEEND, 0);
 
+       if (enterFlag)
+               printf("%s: Leaving directory `%s'\n", progname, curdir);
+
        Suff_End();
         Targ_End();
        Arch_End();
@@ -1721,8 +1775,12 @@
 static void
 usage(void)
 {
+       char *p;
+       if ((p = strchr(progname, '[')) != NULL)
+           *p = '\0';
+
        (void)fprintf(stderr,
-"usage: %s [-BeikNnqrstWX] \n\
+"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);
diff -r f3dd1766103f -r 6921e64f5e89 usr.bin/make/make.1
--- a/usr.bin/make/make.1       Tue Jul 16 10:49:36 2013 +0000
+++ b/usr.bin/make/make.1       Tue Jul 16 14:00:53 2013 +0000
@@ -1,4 +1,4 @@
-.\"    $NetBSD: make.1,v 1.218 2013/06/26 20:20:36 agc Exp $
+.\"    $NetBSD: make.1,v 1.219 2013/07/16 14:00:53 christos 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 June 24, 2013
+.Dd July 15, 2013
 .Dt MAKE 1
 .Os
 .Sh NAME
@@ -37,7 +37,7 @@
 .Nd maintain program dependencies
 .Sh SYNOPSIS
 .Nm
-.Op Fl BeikNnqrstWX
+.Op Fl BeikNnqrstWwX
 .Op Fl C Ar directory
 .Op Fl D Ar variable
 .Op Fl d Ar flags
@@ -209,6 +209,8 @@
 option to print raw values of variables.
 .It Ar v
 Print debugging information about variable assignment.
+.It Ar w
+Print entering and leaving directory messages, pre and post processing.
 .It Ar x
 Run shell commands with
 .Fl x
diff -r f3dd1766103f -r 6921e64f5e89 usr.bin/make/var.c
--- a/usr.bin/make/var.c        Tue Jul 16 10:49:36 2013 +0000
+++ b/usr.bin/make/var.c        Tue Jul 16 14:00:53 2013 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: var.c,v 1.181 2013/07/15 20:33:11 christos Exp $       */
+/*     $NetBSD: var.c,v 1.182 2013/07/16 14:00:53 christos Exp $       */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: var.c,v 1.181 2013/07/15 20:33:11 christos Exp $";
+static char rcsid[] = "$NetBSD: var.c,v 1.182 2013/07/16 14:00:53 christos 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.181 2013/07/15 20:33:11 christos Exp $");
+__RCSID("$NetBSD: var.c,v 1.182 2013/07/16 14:00:53 christos Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -139,6 +139,7 @@
 #include    "dir.h"
 #include    "job.h"
 
+extern int makelevel;
 /*
  * This lets us tell if we have replaced the original environ
  * (which we cannot free).
@@ -657,6 +658,15 @@
     char *val;
     int n;
 
+    /*
+     * Several make's support this sort of mechanism for tracking
+     * recursion - but each uses a different name.
+     * We allow the makefiles to update MAKELEVEL and ensure
+     * children see a correctly incremented value.
+     */
+    snprintf(tmp, sizeof(tmp), "%d", makelevel + 1);
+    setenv(MAKE_LEVEL_ENV, tmp, 1);
+
     if (VAR_EXPORTED_NONE == var_exportedVars)
        return;
 
@@ -953,15 +963,6 @@
 
        Var_Append(MAKEOVERRIDES, name, VAR_GLOBAL);
     }
-    /*
-     * Another special case.
-     * Several make's support this sort of mechanism for tracking
-     * recursion - but each uses a different name.
-     * We allow the makefiles to update .MAKE.LEVEL and ensure
-     * children see a correctly incremented value.
-     */
-    if (ctxt == VAR_GLOBAL && strcmp(MAKE_LEVEL, name) == 0)
-       setenv(MAKE_LEVEL_ENV, val, 1);
        
  out:
     if (expanded_name != NULL)



Home | Main Index | Thread Index | Old Index