| 1 |
# -*-mode: perl-*- |
| 2 |
|
| 3 |
$description = "Test GNU Make's auto-reinvocation feature."; |
| 4 |
|
| 5 |
$details = "\ |
| 6 |
If the makefile or one it includes can be rebuilt then it is, and make |
| 7 |
is reinvoked. We create a rule to rebuild the makefile from a temp |
| 8 |
file, then touch the temp file to make it newer than the makefile."; |
| 9 |
|
| 10 |
$omkfile = $makefile; |
| 11 |
|
| 12 |
&utouch(-600, 'incl.mk'); |
| 13 |
# For some reason if we don't do this then the test fails for systems |
| 14 |
# with sub-second timestamps, maybe + NFS? Not sure. |
| 15 |
&utouch(-1, 'incl-1.mk'); |
| 16 |
|
| 17 |
run_make_test(' |
| 18 |
all: ; @echo running rules. |
| 19 |
|
| 20 |
#MAKEFILE# incl.mk: incl-1.mk ; @echo rebuilding $@; echo >> $@ |
| 21 |
|
| 22 |
include incl.mk', |
| 23 |
'', "rebuilding incl.mk\nrunning rules.\n"); |
| 24 |
|
| 25 |
# Make sure updating the makefile itself also works |
| 26 |
|
| 27 |
&utouch(-600, $omkfile); |
| 28 |
|
| 29 |
run_make_test(undef, '', "rebuilding #MAKEFILE#\nrunning rules.\n"); |
| 30 |
|
| 31 |
&rmfiles('incl.mk', 'incl-1.mk'); |
| 32 |
|
| 33 |
|
| 34 |
# In this test we create an included file that's out-of-date, but then |
| 35 |
# the rule doesn't update it. Make shouldn't re-exec. |
| 36 |
|
| 37 |
&utouch(-600, 'b','a'); |
| 38 |
#&utouch(-10, 'a'); |
| 39 |
&touch('c'); |
| 40 |
|
| 41 |
run_make_test(' |
| 42 |
all: ; @echo hello |
| 43 |
|
| 44 |
a : b ; echo >> $@ |
| 45 |
|
| 46 |
b : c ; test -f $@ || echo >> $@ |
| 47 |
|
| 48 |
c: ; echo >> $@ |
| 49 |
|
| 50 |
include $(F)', |
| 51 |
'F=a', "test -f b || echo >> b\nhello\n"); |
| 52 |
|
| 53 |
# Now try with the file we're not updating being the actual file we're |
| 54 |
# including: this and the previous one test different parts of the code. |
| 55 |
|
| 56 |
run_make_test(undef, 'F=b', "test -f b || echo >> b\nhello\n"); |
| 57 |
|
| 58 |
&rmfiles('a','b','c'); |
| 59 |
|
| 60 |
# Ensure command line variables are preserved properly across re-exec |
| 61 |
# Tests for Savannah bug #30723 |
| 62 |
|
| 63 |
run_make_test(' |
| 64 |
ifdef RECURSE |
| 65 |
-include foo30723 |
| 66 |
endif |
| 67 |
recurse: ; @$(MAKE) -f $(MAKEFILE_LIST) RECURSE=1 test |
| 68 |
test: ; @echo F.O=$(F.O) |
| 69 |
foo30723: ; @touch $@ |
| 70 |
', |
| 71 |
'--no-print-directory F.O=bar', "F.O=bar\n"); |
| 72 |
|
| 73 |
unlink('foo30723'); |
| 74 |
|
| 75 |
# If ANY makefile is rebuilt then we should re-exec |
| 76 |
|
| 77 |
run_make_test(' |
| 78 |
all: ; @echo RESTARTS=$(MAKE_RESTARTS) |
| 79 |
|
| 80 |
m1.d: ; @echo $@; touch $@ |
| 81 |
|
| 82 |
m2.d: m1.d ; @test -f $< || { echo $@; touch $@; } |
| 83 |
|
| 84 |
include m1.d |
| 85 |
-include m2.d |
| 86 |
', |
| 87 |
'', "m1.d\nRESTARTS=1\n"); |
| 88 |
|
| 89 |
unlink('m1.d', 'm2.d'); |
| 90 |
|
| 91 |
# Same as before but be sure we get error messages for un-created makefiles |
| 92 |
run_make_test(' |
| 93 |
all: ; @echo RESTARTS=$(MAKE_RESTARTS) |
| 94 |
|
| 95 |
m1.d: ; @echo $@; touch $@ |
| 96 |
|
| 97 |
m2.d: m1.d ; @test -f $< || { echo $@; touch $@; } |
| 98 |
|
| 99 |
include m1.d m2.d |
| 100 |
', '', |
| 101 |
# This runs afoul of https://savannah.gnu.org/bugs/?61226 |
| 102 |
0 ? "m1.d\n#MAKEFILE#:8: m2.d: $ERR_no_such_file" |
| 103 |
: "m1.d\nRESTARTS=1", |
| 104 |
0 ? 512 : 0); |
| 105 |
|
| 106 |
unlink('m1.d', 'm2.d'); |
| 107 |
|
| 108 |
# sv 61226. |
| 109 |
# This set of four cases tests two aspects of make. |
| 110 |
# |
| 111 |
# 1. If a rule has no prerequisites or recipe, and the target of the rule is a |
| 112 |
# nonexistent file, then make imagines this target to have been updated |
| 113 |
# whenever its rule is run. |
| 114 |
# |
| 115 |
# 2. Make does not re-execute itself in this case of imagined target. |
| 116 |
# |
| 117 |
# Test case 1. |
| 118 |
# Make imagines hello.d was updated by a rule without recipe and without |
| 119 |
# prereqs. |
| 120 |
# This should succeed. |
| 121 |
# Make should not re-execute itself. |
| 122 |
run_make_test(' |
| 123 |
hello.o: hello.d; $(info RESTARTS=$(MAKE_RESTARTS)) |
| 124 |
hello.d: |
| 125 |
include hello.d |
| 126 |
', '', "RESTARTS=\n#MAKE#: 'hello.o' is up to date."); |
| 127 |
|
| 128 |
# Test case 2. |
| 129 |
# Make imagines hello.d was updated by a rule with a recipe and without |
| 130 |
# prereqs. |
| 131 |
# This should succeed. |
| 132 |
# Make should not re-execute itself. |
| 133 |
run_make_test(' |
| 134 |
hello.o: hello.d; $(info RESTARTS=$(MAKE_RESTARTS)) |
| 135 |
hello.d:; $(info $@) |
| 136 |
include hello.d |
| 137 |
', '', "hello.d\nRESTARTS=\n#MAKE#: 'hello.o' is up to date."); |
| 138 |
|
| 139 |
&touch('hello.td'); |
| 140 |
# Test case 3. |
| 141 |
# Make imagines hello.d was updated by a rule without a recipe and with |
| 142 |
# prereqs. |
| 143 |
# This should succeed. |
| 144 |
# Make should not re-execute itself. |
| 145 |
run_make_test(' |
| 146 |
hello.o: hello.d; $(info RESTARTS=$(MAKE_RESTARTS)) |
| 147 |
hello.d: hello.td |
| 148 |
include hello.d |
| 149 |
', '', "RESTARTS=\n#MAKE#: 'hello.o' is up to date."); |
| 150 |
|
| 151 |
# Test case 4. |
| 152 |
# Same test as three tests above, but the rule has both recipe and prereqs. |
| 153 |
# Make should report this error. |
| 154 |
run_make_test(' |
| 155 |
hello.o: hello.d; $(info $@) |
| 156 |
hello.d: hello.td; $(info $@) |
| 157 |
include hello.d |
| 158 |
', '', |
| 159 |
# This runs afoul of https://savannah.gnu.org/bugs/?61226 |
| 160 |
0 ? "hello.d\n#MAKEFILE#:4: hello.d: $ERR_no_such_file" |
| 161 |
: "hello.d\nhello.o\n#MAKE#: 'hello.o' is up to date.", |
| 162 |
0 ? 512 : 0); |
| 163 |
|
| 164 |
unlink('hello.td'); |
| 165 |
|
| 166 |
# Test SV 62088 : make sure we don't re-invoke for stdin makefiles. |
| 167 |
# The test framework doesn't seem to have a good way to do this. |
| 168 |
|
| 169 |
create_file('input.mk', "all:;\$(info all)\n"); |
| 170 |
|
| 171 |
close(STDIN); |
| 172 |
open(STDIN, "<", 'input.mk') || die "input.mk: $!\n"; |
| 173 |
|
| 174 |
run_make_test('', '-sf -', "all\n"); |
| 175 |
|
| 176 |
|
| 177 |
# This close MUST come at the end of the test!! |
| 178 |
close(STDIN); |
| 179 |
unlink('input.mk'); |
| 180 |
|
| 181 |
# This tells the test driver that the perl test script executed properly. |
| 182 |
1; |