2005-03-25  Casper Hornstrup  <chorns@users.sourceforge.net>

	* remake.c (name_mtime): On Windows, use the creation time
	of directories instead of last modification time.


Index: remake.c
===================================================================
RCS file: /cvsroot/make/make/remake.c,v
retrieving revision 1.115
diff -u -r1.115 remake.c
--- remake.c	28 Feb 2005 09:41:25 -0000	1.115
+++ remake.c	25 Mar 2005 22:02:05 -0000
@@ -38,6 +38,8 @@
 #include <starlet.h>
 #endif
 #ifdef WINDOWS32
+#include <sys/types.h>
+#include <sys/stat.h>
 #include <io.h>
 #endif
 
@@ -1326,14 +1328,38 @@
   FILE_TIMESTAMP mtime;
   struct stat st;
   int e;
+#ifdef WINDOWS32
+  struct _stat wst;
+#endif
 
+#ifdef WINDOWS32
+  EINTRLOOP (e, _stat(name, &wst));
+#else /* !WINDOWS32 */
   EINTRLOOP (e, stat (name, &st));
+#endif
   if (e != 0)
     {
       if (errno != ENOENT && errno != ENOTDIR)
         perror_with_name ("stat:", name);
       return NONEXISTENT_MTIME;
     }
+
+#ifdef WINDOWS32
+  st.st_atime = wst.st_atime;
+  st.st_ctime = wst.st_ctime;
+  st.st_mode = wst.st_mode;
+  st.st_size = wst.st_size;
+  /* On NTFS volumes, the last modification time of directories is changed
+     whenever a change occurs to the directory or an entry within it. This
+     behaviour can cause make to go into a loop if an entry within the
+     directory is changed, and there exist other targets that depend on the
+     directory which then again causes changes to be made to the directory. */
+  if (S_ISDIR (wst.st_mode))
+    st.st_mtime = wst.st_ctime;
+  else
+    st.st_mtime = wst.st_mtime;
+#endif
+
   mtime = FILE_TIMESTAMP_STAT_MODTIME (name, st);
 
 #ifdef MAKE_SYMLINKS
