Paul Smith c59cc4f932 [SV 64185] Clarify handling of directive lines starting with TAB
It's clear that this change causes too many problems to be made
without warning.  Revert the change disallowing conditional lines to
start with TAB.

Instead, generate warnings whenever a directive line begins with a
TAB character.  Make this change for all directives, not just
conditional directives: define, undefine, export, unexport, vpath,
load, include, etc.

* NEWS: Update the backward-compatibility warning.
* src/read.c (eval): Track whether the line starts with a TAB.
If so then whenever we recognize a directive, emit a warning.
Revert the previous change for this bug.
(parse_var_assignment): Accept a file location if the line begins
with TAB; show a warning if we discover a directive.
(conditional_line): Warn about lines starting with TAB.
* tests/scripts/...: Add tests to verify warnings for initial TAB.
2025-08-26 08:13:55 -04:00

65 lines
1.3 KiB
Perl

# -*-perl-*-
$description = "Test the override directive on variable assignments.";
$details = "";
# TEST 0: Basic override
run_make_test('
X = start
override recur = $(X)
override simple := $(X)
X = end
all: ; @echo "$(recur) $(simple)"
',
'recur=I simple=J', "end start\n");
# TEST 1: Override with append
run_make_test('
X += X1
override X += X2
override Y += Y1
Y += Y2
all: ; @echo "$(X) $(Y)"
',
'', "X1 X2 Y1\n");
# TEST 2: Override with append to the command line
run_make_test(undef, 'X=C Y=C', "C X2 C Y1\n");
# Test override of define/endef
run_make_test('
override define foo
@echo First comes the definition.
@echo Then comes the override.
endef
all: ; $(foo)
',
'foo=Hello', "First comes the definition.\nThen comes the override.\n");
# Directive lines cannot begin with TAB
run_make_test(q!
#TAB#override FOO = bar
all:;@echo hi
!,
'', "#MAKEFILE#:2: warning: directive lines cannot start with TAB\nhi");
run_make_test(q!
#TAB#override#TAB#export FOO = bar
all:;@echo hi
!,
'', "#MAKEFILE#:2: warning: directive lines cannot start with TAB\nhi");
run_make_test(q!
override#TAB#export FOO = bar
all:;@echo hi
!,
'', "hi");
1;