From 79226860ee5627ffee9b3d4722f6bc91b64ce91c Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Mon, 22 Apr 2024 15:32:25 +0100 Subject: make: better determine that a file is up-to-date POSIX says: A target shall be considered up-to-date... if it has already been made up-to-date by the current invocation of make (regardless of the target's existence or age). If the target does not exist after the target has been successfully made up-to-date, the target shall be treated as being newer than any target for which it is a prerequisite. Previously 'make' assumed that if a rule had succeeded the modification time of the target would be the current time. This isn't necessarily the case. Instead: - If the file exists use the modification time of the file as the the time of the target. - If it doesn't exist use the current time, which should be more recent than the time of any file for which it's a prerequisite. Adds 16 bytes. (GitHub issue #410) --- miscutils/make.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/miscutils/make.c b/miscutils/make.c index 97ee8d879..c2e12f2ed 100644 --- a/miscutils/make.c +++ b/miscutils/make.c @@ -2509,9 +2509,11 @@ make(struct name *np, int level) free(oodate); } - if (estat & MAKE_DIDSOMETHING) - clock_gettime(CLOCK_REALTIME, &np->n_tim); - else if (!quest && level == 0 && !timespec_le(&np->n_tim, &dtim)) + if (estat & MAKE_DIDSOMETHING) { + modtime(np); + if (np->n_tim.tv_sec == 0 && np->n_tim.tv_nsec == 0) + clock_gettime(CLOCK_REALTIME, &np->n_tim); + } else if (!quest && level == 0 && !timespec_le(&np->n_tim, &dtim)) printf("%s: '%s' is up to date\n", applet_name, np->n_name); free(allsrc); -- cgit v1.2.3-55-g6feb