Subject: Re: "Soft" make dependencies? Was: make build problem - BIND
To: None <current-users@NetBSD.ORG>
From: Takahiro Kambe <taca@sky.yamashina.kyoto.jp>
List: current-users
Date: 05/30/2001 09:30:57
In message <20010528164648.24D74100@proven.weird.com>
	on Mon, 28 May 2001 12:46:48 -0400 (EDT),
	woods@weird.com (Greg A. Woods) wrote:
> [ On Monday, May 28, 2001 at 16:09:54 (+0900), Takahiro Kambe wrote: ]
> > Subject: Re: "Soft" make dependencies?  Was: make build problem - BIND
> >
> > Simply, is there any problem ignoring .depend older than Makefile?
> 
> That sounds like a good idea, at least on first glance.
Yes, better solution would exist.

Anyway, here is my several minitues simple (or dirty) hack.  Warning
message sould be ignored that honoring some options.

--
Takahiro Kambe <taca@sky.yamashina.kyoto.jp>

--- src/usr.bin/main.c.orig	Sat Jan 20 17:22:18 2001
+++ src/usr.bin/main.c	Wed May 30 09:28:40 2001
@@ -808,7 +808,7 @@
 	} else if (!ReadMakefile("makefile", NULL))
 		(void)ReadMakefile("Makefile", NULL);
 
-	(void)ReadMakefile(".depend", NULL);
+	(void)ReadMakefile(".depend", "dummy");
 
 	Var_Append("MFLAGS", Var_Value(MAKEFLAGS, VAR_GLOBAL, &p1), VAR_GLOBAL);
 	if (p1)
@@ -975,6 +975,9 @@
 	FILE *stream;
 	size_t len = MAXPATHLEN;
 	char *name, *path = emalloc(len);
+	struct stat st;
+	time_t cur_mtime;
+	static time_t old_mtime;
 
 	if (!strcmp(fname, "-")) {
 		Parse_File("(stdin)", stdin);
@@ -1007,8 +1010,18 @@
 		 * placement of the setting here means it gets set to the last
 		 * makefile specified, as it is set by SysV make.
 		 */
-found:		Var_Set("MAKEFILE", fname, VAR_GLOBAL);
-		Parse_File(fname, stream);
+found:		if (fstat(fileno(stream), &st) == 0)
+			cur_mtime = st.st_mtime;
+		else
+			cur_mtime = old_mtime;
+		if (q == NULL || cur_mtime > old_mtime) {
+			Var_Set("MAKEFILE", fname, VAR_GLOBAL);
+			Parse_File(fname, stream);
+			old_mtime = cur_mtime;
+		} else if (q != NULL && cur_mtime <= old_mtime)
+			(void)fprintf(stderr,
+				      "make warning: older %s was ignored,\n",
+				      fname);
 		(void)fclose(stream);
 	}
 	free(path);