tech-toolchain archive

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

make: dependfile preference list



The patch below, adds:

     .MAKE.DEPENDFILE_PREFERENCE
                     The ordered list of makefile names (default
                     `${.MAKE.DEPENDFILE:T}') that make will look for to
                     read
                     dependencies from.  Only the first found will be
                     read.

which is used in the same way as 

      .MAKE.MAKEFILE_PREFERENCE
                     The ordered list of makefile names (default
                     `makefile',
                     `Makefile') that make will look for.  Only the
                     first found will be read.

it also removes the supression of duplicate entries in 
.MAKE.MAKEFILES - which while a rare even can be rather important (to me
anyway). 

The .MAKE.DEPENDFILE_PREFERENCE is especially interesting in making meta
mode more flexible and potentially useful in different environments.
AFAIK in most all? use to date has been heavily oriented to pure
cross-building environments.

Eg. one might set

.MAKE.DEPENDFILE_PREFERENCE = \
        Makefile.depend.${MACHINE} \
        Makefile.depend.auto \
        Makefile.depend

etc.  The goal is to allow - possibly on a per directory basis,
to set the style of dependencies, with perhaps deliniation between
manually maintained and auto-updated files.  
The later relies on the filemon(4) module which could be tricky for
pkgsrc - given the wide set of OS's it is used on.

Index: main.c
===================================================================
RCS file: /cvsroot/src/usr.bin/make/main.c,v
retrieving revision 1.198
diff -u -p -r1.198 main.c
--- main.c      16 Sep 2011 15:38:04 -0000      1.198
+++ main.c      19 Apr 2012 06:09:59 -0000
@@ -871,6 +871,15 @@ main(int argc, char **argv)
 #endif
        Var_Set(MAKEFILE_PREFERENCE, MAKEFILE_PREFERENCE_LIST,
                VAR_GLOBAL, 0);
+
+       /*
+        * This is the traditional preference for depend file.
+        */
+#ifndef DEPENDFILE_PREFERENCE_LIST
+# define DEPENDFILE_PREFERENCE_LIST "${" MAKE_DEPENDFILE ":T}"
+#endif
+       Var_Set(DEPENDFILE_PREFERENCE, DEPENDFILE_PREFERENCE_LIST,
+               VAR_GLOBAL, 0);
        Var_Set(MAKE_DEPENDFILE, ".depend", VAR_GLOBAL, 0);
 
        create = Lst_Init(FALSE);
@@ -1139,10 +1148,17 @@ main(int argc, char **argv)
 
        /* In particular suppress .depend for '-r -V .OBJDIR -f /dev/null' */
        if (!noBuiltins || !printVars) {
-           makeDependfile = Var_Subst(NULL, "${.MAKE.DEPENDFILE:T}",
-               VAR_CMD, 0);
            doing_depend = TRUE;
-           (void)ReadMakefile(makeDependfile, NULL);
+           p1 = Var_Subst(NULL, "${" DEPENDFILE_PREFERENCE "}",
+               VAR_CMD, 0);
+           if (p1) {
+               Lst_Destroy(makefiles, NULL);
+               makefiles = Lst_Init(FALSE);
+               (void)str2Lst_Append(makefiles, p1, NULL);
+               (void)Lst_Find(makefiles, NULL, ReadMakefile);
+               free(p1);
+           } else
+               (void)ReadMakefile(makeDependfile, NULL);
            doing_depend = FALSE;
        }
 
@@ -1289,6 +1305,20 @@ main(int argc, char **argv)
        return outOfDate ? 1 : 0;
 }
 
+static const char *
+bmake_basename(const char *s)
+{
+       const char *b;
+
+       b = strrchr(s, '/');
+       if (!b) {
+               b = s;
+       } else if (b[1]) {
+               b++;
+       }
+       return b;
+}
+
 /*-
  * ReadMakefile  --
  *     Open and parse the given makefile.
@@ -1357,7 +1387,9 @@ ReadMakefile(const void *p, const void *
                 * makefile specified, as it is set by SysV make.
                 */
 found:
-               if (!doing_depend)
+               if (doing_depend)
+                       makeDependfile = bmake_strdup(bmake_basename(fname));
+               else
                        Var_Set("MAKEFILE", fname, VAR_GLOBAL, 0);
                Parse_File(fname, fd);
        }
Index: make.1
===================================================================
RCS file: /cvsroot/src/usr.bin/make/make.1,v
retrieving revision 1.202
diff -u -p -r1.202 make.1
--- make.1      8 Apr 2012 22:00:39 -0000       1.202
+++ make.1      19 Apr 2012 06:10:03 -0000
@@ -675,6 +675,14 @@ and cannot be confused with the special 
 Names the makefile (default
 .Ql Pa .depend )
 from which generated dependencies are read.
+.It Va .MAKE.DEPENDFILE_PREFERENCE
+The ordered list of makefile names
+(default
+.Ql Li ${.MAKE.DEPENDFILE:T} )
+that
+.Nm
+will look for to read dependencies from.
+Only the first found will be read.
 .It Va .MAKE.EXPORTED
 The list of variables exported by
 .Nm .
@@ -731,11 +739,11 @@ The ordered list of makefile names
 that
 .Nm
 will look for.
+Only the first found will be read.
 .It Va .MAKE.MAKEFILES
 The list of makefiles read by
 .Nm ,
 which is useful for tracking dependencies.
-Each makefile is recorded only once, regardless of the number of times read.
 .It Va .MAKE.MODE
 Processed after reading all makefiles.
 Can affect the mode that
Index: make.h
===================================================================
RCS file: /cvsroot/src/usr.bin/make/make.h,v
retrieving revision 1.87
diff -u -p -r1.87 make.h
--- make.h      16 Sep 2011 15:38:04 -0000      1.87
+++ make.h      19 Apr 2012 06:10:03 -0000
@@ -416,6 +416,7 @@ extern pid_t        myPid;
 #define        MAKE_MAKEFILES  ".MAKE.MAKEFILES"  /* all the makefiles we read 
*/
 #define        MAKE_LEVEL      ".MAKE.LEVEL"      /* recursion level */
 #define MAKEFILE_PREFERENCE ".MAKE.MAKEFILE_PREFERENCE"
+#define DEPENDFILE_PREFERENCE ".MAKE.DEPENDFILE_PREFERENCE"
 #define MAKE_DEPENDFILE        ".MAKE.DEPENDFILE" /* .depend */
 #define MAKE_MODE      ".MAKE.MODE"
 
Index: parse.c
===================================================================
RCS file: /cvsroot/src/usr.bin/make/parse.c,v
retrieving revision 1.182
diff -u -p -r1.182 parse.c
--- parse.c     31 Mar 2012 00:12:24 -0000      1.182
+++ parse.c     19 Apr 2012 06:10:04 -0000
@@ -2248,10 +2248,13 @@ ParseSetParseFile(const char *filename)
 static void
 ParseTrackInput(const char *name)
 {
+#if 1
+    Var_Append(MAKE_MAKEFILES, name, VAR_GLOBAL);
+#else
     char *old;
     char *fp = NULL;
     size_t name_len = strlen(name);
-    
+
     old = Var_Value(MAKE_MAKEFILES, VAR_GLOBAL, &fp);
     if (old) {
        /* does it contain name? */
@@ -2263,11 +2266,13 @@ ParseTrackInput(const char *name)
                goto cleanup;
        }
     }
+
     Var_Append (MAKE_MAKEFILES, name, VAR_GLOBAL);
  cleanup:
     if (fp) {
        free(fp);
     }
+#endif
 }
 
 


Home | Main Index | Thread Index | Old Index