tech-toolchain archive

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

make: ignore stale .depend



The logic in make to ignore stale dependencies learned from .depend 
seems incomplete.

When a source file moves, make will ignore the stale dependency,
but if the file in question is one that needs to be compiled, it
still hands the bogus name to the compiler.

To avoid this, when adding targets from .depend, check if they contain
'/' and if so, whether they exist.  If they do not, use the basename
instead which may then be found via the presumably new .PATH:

Also fix error about 'he' being possibly used unititialized.

--sjg

Index: targ.c
===================================================================
RCS file: /cvsroot/src/usr.bin/make/targ.c,v
retrieving revision 1.55
diff -u -p -r1.55 targ.c
--- targ.c      23 Jan 2009 21:26:30 -0000      1.55
+++ targ.c      24 Nov 2010 01:30:23 -0000
@@ -337,6 +337,7 @@ Targ_FindNode(const char *name, int flag
     Boolean      isNew;      /* Set TRUE if Hash_CreateEntry had to create */
                              /* an entry for the node */
 
+    he = NULL;
     if (!(flags & (TARG_CREATE | TARG_NOHASH))) {
        he = Hash_FindEntry(&targets, name);
        if (he == NULL)
@@ -351,12 +352,40 @@ Targ_FindNode(const char *name, int flag
     }
 
     gn = Targ_NewGN(name);
-    if (!(flags & TARG_NOHASH))
+
+    if (doing_depend) {
+       /*
+        * Deal with stale dependencies as early as possible.
+        * If name contains '/', check if it can be found.
+        * If it cannot, assume the file moved, and use its basname
+        * instead. This really only matters for source files which
+        * would otherwise be fed to the compiler.
+        */
+       char *fullName;
+       char *baseName;
+       
+       gn->flags |= FROM_DEPEND;
+       baseName = strrchr(name, '/');
+       if (baseName) {
+           baseName++;
+           fullName = Dir_FindFile(gn->name, Suff_FindPath(gn));
+           if (!fullName) {
+               free(gn->name);
+               gn->name = bmake_strdup(baseName);
+               fprintf(stdout, "%s: ignoring stale %s for %s\n",
+                       progname, makeDependfile, name);
+           } else if (gn->path == NULL && strcmp(fullName, name) != 0) {
+               /* save our effort */
+               gn->path = fullName;
+           } else {
+               free(fullName);
+           }
+       }
+    }                  
+    if (he)
        Hash_SetValue(he, gn);
-    Var_Append(".ALLTARGETS", name, VAR_GLOBAL);
+    Var_Append(".ALLTARGETS", gn->name, VAR_GLOBAL);
     (void)Lst_AtEnd(allTargets, gn);
-    if (doing_depend)
-       gn->flags |= FROM_DEPEND;
     return gn;
 }
 


Home | Main Index | Thread Index | Old Index