From b4d811aa232df8c7416a14f38a2396b028c35ac9 Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Tue, 10 Sep 2024 07:54:16 +0100 Subject: make: reinstate conditional skipping of command lines Commit e90345c10 (make: allow empty commands) rearranged readline() in a way that broke the use of conditionals within the definition of a rule. Add a test case to detect this. Adjust readline() so that conditionals are processed before returning command lines or checking for empty lines and comments. Remove the test for a leading tab in skip_lines(). This allows conditionals in the definition of a rule to be indented with a leading tab. --- miscutils/make.c | 22 +++++++++++----------- testsuite/make.tests | 2 ++ 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/miscutils/make.c b/miscutils/make.c index 871c434f8..b2edfdbb4 100644 --- a/miscutils/make.c +++ b/miscutils/make.c @@ -1605,9 +1605,6 @@ skip_line(const char *str1) int ret = cstate[clevel] & SKIP_LINE; int key; - if (*str1 == '\t') - return ret; - copy = xstrdup(str1); q = process_line(copy); if ((token = gettok(&q)) != NULL) { @@ -1754,16 +1751,19 @@ readline(FILE *fd, int want_command) } dispno = lineno; - if (want_command && *str == '\t') - return str; + // Check for lines that are conditionally skipped. + if (posix || !skip_line(str)) { + if (want_command && *str == '\t') + return str; - // Check for comment lines and lines that are conditionally skipped. - p = str; - while (isblank(*p)) - p++; + // Check for comment lines + p = str; + while (isblank(*p)) + p++; - if (*p != '\n' && *str != '#' && (posix || !skip_line(str))) - return str; + if (*p != '\n' && *str != '#') + return str; + } pos = 0; } diff --git a/testsuite/make.tests b/testsuite/make.tests index c92c69340..a12e50b8b 100755 --- a/testsuite/make.tests +++ b/testsuite/make.tests @@ -652,6 +652,8 @@ B = b target: ifeq ($(A),a) @echo A OK +else + @echo A not OK endif ifneq "a" "$B" @echo B OK -- cgit v1.2.3-55-g6feb