From 9376eebd8d16ce38278ee709177e9e7fd5d7ec14 Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Sun, 15 Sep 2024 09:56:36 +0100 Subject: make: fix error reporting for included files The global variables 'makefile' and 'lineno' weren't properly reset after a recursive call to input(). As a result error messages for included files could refer to the wrong file or line number. Restore 'makefile' and 'lineno' immediately after a rescursive call to input(). This also requires a different fix for commit b21546ddb (make: fix test for include with no pathnames). Adds 16 bytes in the 32-bit build. --- miscutils/make.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/miscutils/make.c b/miscutils/make.c index bd3b23f21..8d953f9fc 100644 --- a/miscutils/make.c +++ b/miscutils/make.c @@ -2073,23 +2073,27 @@ input(FILE *fd, int ilevel) if (ilevel > 16) error("too many includes"); + count = 0; q = expanded = expand_macros(p + 7, FALSE); while ((p = gettok(&q)) != NULL) { FILE *ifd; + ++count; if (!POSIX_2017) { // Try to create include file or bring it up-to-date opts |= OPT_include; make(newname(p), 1); opts &= ~OPT_include; } - makefile = p; if ((ifd = fopen(p, "r")) == NULL) { if (!minus) error("can't open include file '%s'", p); } else { + makefile = p; input(ifd, ilevel + 1); fclose(ifd); + makefile = old_makefile; + lineno = old_lineno; } if (POSIX_2017) break; @@ -2100,14 +2104,11 @@ input(FILE *fd, int ilevel) if (p == NULL || gettok(&q)) { error("one include file per line"); } - } else if (makefile == old_makefile) { + } else if (count == 0) { // In POSIX 2024 no include file is unspecified behaviour. if (posix) error("no include file"); } - - makefile = old_makefile; - lineno = old_lineno; goto end_loop; } -- cgit v1.2.3-55-g6feb