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:



details:   https://anonhg.NetBSD.org/src/rev/a7098815723b
branches:  trunk
changeset: 753691:a7098815723b
user:      sjg <sjg%NetBSD.org@localhost>
date:      Wed Apr 07 00:11:27 2010 +0000

description:
Add:

.error "message"
.warning "message"
        based on FreeBSD implementation.
        add .info while were at it.

.ERROR: a target to run on error.
        We pass the failing GNode to PrintOnError so it can set
        .ERROR_TARGET.

.MAKE.MAKEFILE_PREFERENCE
        As a means to control make's list of prefered makefile names.
        (Default: "makefile Makefile")

.MAKE.DEPENDFILE
        Names the file to read dependencies from
        (Default ".depend")

.MAKE.MODE
        Processed after all makefiles are read.
        Can put make into "compat" mode (more to come).

Fix:

compat.c: Error code should not be sent to debug_file.
Make_DoAllVar: use DONE_ALLSRC to avoid processing a node multiple times.
ReadMakefile: we can simply use doing_depend to control setting MAKEFILE.

diffstat:

 usr.bin/make/compat.c  |   14 +++---
 usr.bin/make/job.c     |   14 +++---
 usr.bin/make/main.c    |  104 +++++++++++++++++++++++++++++++++++++++++-------
 usr.bin/make/make.1    |   42 ++++++++++++++++++-
 usr.bin/make/make.c    |   10 +++-
 usr.bin/make/make.h    |    9 +++-
 usr.bin/make/nonints.h |    3 +-
 usr.bin/make/parse.c   |   59 +++++++++++++++++++++++++--
 8 files changed, 212 insertions(+), 43 deletions(-)

diffs (truncated from 633 to 300 lines):

diff -r aef93b11d0ce -r a7098815723b usr.bin/make/compat.c
--- a/usr.bin/make/compat.c     Tue Apr 06 23:02:10 2010 +0000
+++ b/usr.bin/make/compat.c     Wed Apr 07 00:11:27 2010 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: compat.c,v 1.76 2009/02/22 07:33:00 dholland Exp $     */
+/*     $NetBSD: compat.c,v 1.77 2010/04/07 00:11:27 sjg Exp $  */
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -70,14 +70,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: compat.c,v 1.76 2009/02/22 07:33:00 dholland Exp $";
+static char rcsid[] = "$NetBSD: compat.c,v 1.77 2010/04/07 00:11:27 sjg Exp $";
 #else
 #include <sys/cdefs.h>
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)compat.c   8.2 (Berkeley) 3/19/94";
 #else
-__RCSID("$NetBSD: compat.c,v 1.76 2009/02/22 07:33:00 dholland Exp $");
+__RCSID("$NetBSD: compat.c,v 1.77 2010/04/07 00:11:27 sjg Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -407,7 +407,7 @@
                        }
                        fprintf(debug_file, "\n");
                    }
-                   fprintf(debug_file, "*** Error code %d", status);
+                   printf("*** Error code %d", status);
                }
            } else {
                status = WTERMSIG(reason);              /* signaled */
@@ -574,7 +574,7 @@
        } else if (keepgoing) {
            pgn->flags &= ~REMAKE;
        } else {
-           PrintOnError("\n\nStop.");
+           PrintOnError(gn, "\n\nStop.");
            exit(1);
        }
     } else if (gn->made == ERROR) {
@@ -665,7 +665,7 @@
        if (gn != NULL) {
            Compat_Make(gn, gn);
             if (gn->made == ERROR) {
-                PrintOnError("\n\nStop.");
+                PrintOnError(gn, "\n\nStop.");
                 exit(1);
             }
        }
@@ -706,7 +706,7 @@
     if (errors == 0) {
        Compat_Make(ENDNode, ENDNode);
        if (gn->made == ERROR) {
-           PrintOnError("\n\nStop.");
+           PrintOnError(gn, "\n\nStop.");
            exit(1);
        }
     }
diff -r aef93b11d0ce -r a7098815723b usr.bin/make/job.c
--- a/usr.bin/make/job.c        Tue Apr 06 23:02:10 2010 +0000
+++ b/usr.bin/make/job.c        Wed Apr 07 00:11:27 2010 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: job.c,v 1.146 2009/06/26 01:26:32 sjg Exp $    */
+/*     $NetBSD: job.c,v 1.147 2010/04/07 00:11:27 sjg Exp $    */
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -70,14 +70,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: job.c,v 1.146 2009/06/26 01:26:32 sjg Exp $";
+static char rcsid[] = "$NetBSD: job.c,v 1.147 2010/04/07 00:11:27 sjg Exp $";
 #else
 #include <sys/cdefs.h>
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)job.c      8.2 (Berkeley) 3/19/94";
 #else
-__RCSID("$NetBSD: job.c,v 1.146 2009/06/26 01:26:32 sjg Exp $");
+__RCSID("$NetBSD: job.c,v 1.147 2010/04/07 00:11:27 sjg Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -1225,8 +1225,8 @@
            static const char msg[] = ": don't know how to make";
 
            if (gn->flags & FROM_DEPEND) {
-               fprintf(stdout, "%s: ignoring stale .depend for %s\n",
-                       progname, gn->name);
+               fprintf(stdout, "%s: ignoring stale %s for %s\n",
+                       progname, makeDependfile, gn->name);
                return TRUE;
            }
 
@@ -1897,7 +1897,7 @@
 #else
     Compat_Make(targ, targ);
     if (targ->made == ERROR) {
-       PrintOnError("\n\nStop.");
+       PrintOnError(targ, "\n\nStop.");
        exit(1);
     }
 #endif
@@ -2227,7 +2227,7 @@
     if (begin != NULL) {
        JobRun(begin);
        if (begin->made == ERROR) {
-           PrintOnError("\n\nStop.");
+           PrintOnError(begin, "\n\nStop.");
            exit(1);
        }
     }
diff -r aef93b11d0ce -r a7098815723b usr.bin/make/main.c
--- a/usr.bin/make/main.c       Tue Apr 06 23:02:10 2010 +0000
+++ b/usr.bin/make/main.c       Wed Apr 07 00:11:27 2010 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: main.c,v 1.175 2010/01/04 17:05:25 sjg Exp $   */
+/*     $NetBSD: main.c,v 1.176 2010/04/07 00:11:27 sjg Exp $   */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -69,7 +69,7 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: main.c,v 1.175 2010/01/04 17:05:25 sjg Exp $";
+static char rcsid[] = "$NetBSD: main.c,v 1.176 2010/04/07 00:11:27 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.175 2010/01/04 17:05:25 sjg Exp $");
+__RCSID("$NetBSD: main.c,v 1.176 2010/04/07 00:11:27 sjg Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -184,6 +184,7 @@
 static char curdir[MAXPATHLEN + 1];    /* startup directory */
 static char objdir[MAXPATHLEN + 1];    /* where we chdir'ed to */
 char *progname;                                /* the program name */
+char *makeDependfile;
 
 Boolean forceJobs = FALSE;
 
@@ -680,6 +681,22 @@
        return (ReadMakefile(p, q) == 0);
 }
 
+static int
+str2Lst_Append(Lst lp, char *str, const char *sep)
+{
+    char *cp;
+    int n;
+
+    if (!sep)
+       sep = " \t";
+
+    for (n = 0, cp = strtok(str, sep); cp; cp = strtok(NULL, sep)) {
+       (void)Lst_AtEnd(lp, cp);
+       n++;
+    }
+    return (n);
+}
+
 #ifdef SIGINFO
 /*ARGSUSED*/
 static void
@@ -696,6 +713,27 @@
 }
 #endif
 
+/*
+ * Allow makefiles some control over the mode we run in.
+ */
+void
+MakeMode(const char *mode)
+{
+    char *mp = NULL;
+
+    if (!mode)
+       mode = mp = Var_Subst(NULL, "${" MAKE_MODE ":tl}", VAR_GLOBAL, 0);
+
+    if (mode && *mode) {
+       if (strstr(mode, "compat")) {
+           compatMake = TRUE;
+           forceJobs = FALSE;
+       }
+    }
+    if (mp)
+       free(mp);
+}
+
 /*-
  * main --
  *     The main function, for obvious reasons. Initializes variables
@@ -813,6 +851,15 @@
        Var_Set("MAKE_VERSION", MAKE_VERSION, VAR_GLOBAL, 0);
 #endif
        Var_Set(".newline", "\n", VAR_GLOBAL, 0); /* handy for :@ loops */
+       /*
+        * This is the traditional preference for makefiles.
+        */
+#ifndef MAKEFILE_PREFERENCE_LIST
+# define MAKEFILE_PREFERENCE_LIST "makefile Makefile"
+#endif
+       Var_Set(MAKEFILE_PREFERENCE, MAKEFILE_PREFERENCE_LIST,
+               VAR_GLOBAL, 0);
+       Var_Set(MAKE_DEPENDFILE, ".depend", VAR_GLOBAL, 0);
 
        create = Lst_Init(FALSE);
        makefiles = Lst_Init(FALSE);
@@ -1051,16 +1098,27 @@
                if (ln != NULL)
                        Fatal("%s: cannot open %s.", progname, 
                            (char *)Lst_Datum(ln));
-       } else if (ReadMakefile("makefile", NULL) != 0)
-               (void)ReadMakefile("Makefile", NULL);
+       } else {
+           p1 = Var_Subst(NULL, "${" MAKEFILE_PREFERENCE "}",
+               VAR_CMD, 0);
+           if (p1) {
+               (void)str2Lst_Append(makefiles, p1, NULL);
+               (void)Lst_Find(makefiles, NULL, ReadMakefile);
+               free(p1);
+           }
+       }
 
        /* In particular suppress .depend for '-r -V .OBJDIR -f /dev/null' */
        if (!noBuiltins || !printVars) {
-               doing_depend = TRUE;
-               (void)ReadMakefile(".depend", NULL);
-               doing_depend = FALSE;
+           makeDependfile = Var_Subst(NULL, "${.MAKE.DEPENDFILE:T}",
+               VAR_CMD, 0);
+           doing_depend = TRUE;
+           (void)ReadMakefile(makeDependfile, NULL);
+           doing_depend = FALSE;
        }
 
+       MakeMode(NULL);
+
        Var_Append("MFLAGS", Var_Value(MAKEFLAGS, VAR_GLOBAL, &p1), VAR_GLOBAL);
        if (p1)
            free(p1);
@@ -1219,14 +1277,11 @@
        int fd;
        size_t len = MAXPATHLEN;
        char *name, *path = bmake_malloc(len);
-       int setMAKEFILE;
 
        if (!strcmp(fname, "-")) {
                Parse_File("(stdin)", dup(fileno(stdin)));
                Var_Set("MAKEFILE", "", VAR_GLOBAL, 0);
        } else {
-               setMAKEFILE = strcmp(fname, ".depend");
-
                /* if we've chdir'd, rebuild the path name */
                if (strcmp(curdir, objdir) && *fname != '/') {
                        size_t plen = strlen(curdir) + strlen(fname) + 2;
@@ -1273,7 +1328,7 @@
                 * makefile specified, as it is set by SysV make.
                 */
 found:
-               if (setMAKEFILE)
+               if (!doing_depend)
                        Var_Set("MAKEFILE", fname, VAR_GLOBAL, 0);
                Parse_File(fname, fd);
        }
@@ -1666,7 +1721,7 @@
        (void)fprintf(stderr, "\n");
        (void)fflush(stderr);
 
-       PrintOnError(NULL);
+       PrintOnError(NULL, NULL);
 
        if (DEBUG(GRAPH2) || DEBUG(GRAPH3))
                Targ_PrintGraph(2);
@@ -1698,7 +1753,7 @@
        (void)fprintf(stderr, "\n");
        (void)fflush(stderr);
 
-       PrintOnError(NULL);
+       PrintOnError(NULL, NULL);
 
        DieHorribly();
 }
@@ -1819,15 +1874,32 @@
 
 
 void
-PrintOnError(const char *s)
+PrintOnError(GNode *gn, const char *s)



Home | Main Index | Thread Index | Old Index