Fix for complex situations where directories are declared as prerequisites.
[make.git] / tests / scripts / features / reinvoke
bloba5a475cbfd4abdca4afbb92b38d4fa0e99e48056
1 #                                                              -*-mode: perl-*-
3 $description = "Test GNU make's auto-reinvocation feature.";
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.";
10 $makefile2 = &get_tmpfile;
11 $makefile_orig = &get_tmpfile;
13 open(MAKEFILE,"> $makefile");
15 print MAKEFILE <<EOM;
17 all: ; \@echo 'running rules.'
19 $makefile $makefile2: $makefile_orig
20         \@echo 'rebuilding \$\@.'
21         \@echo >> \$\@
23 include $makefile2
25 EOM
27 close(MAKEFILE);
29 &utouch(-10, $makefile, $makefile2);
30 &touch($makefile_orig);
32 &run_make_with_options($makefile, "", &get_logfile, 0);
34 # Create the answer to what should be produced by this Makefile
36 $answer = "rebuilding $makefile2.\nrebuilding $makefile.\nrunning rules.\n";
38 &compare_output($answer,&get_logfile(1))
39   && unlink "$makefile_orig";
41 # In this test we create an included file that's out-of-date, but then
42 # the rule doesn't update it.  Make shouldn't re-exec.
44 $makefile3 = &get_tmpfile;
46 open(MAKEFILE, "> $makefile3");
47 print MAKEFILE <<'EOM';
48 SHELL = /bin/sh
50 all: ; @echo hello
52 a : b ; echo >> $@
54 b : c ; [ -f $@ ] || echo >> $@
56 c: ; echo >> $@
58 include $(F)
59 EOM
61 close(MAKEFILE);
63 &utouch(-20, 'b','a');
64 #&utouch(-10, 'a');
65 &touch('c');
67 # First try with the file that's not updated "once removed" from the
68 # file we're including.
70 &run_make_with_options($makefile3, "F=a", &get_logfile, 0);
72 $answer = "[ -f b ] || echo >> b\nhello\n";
73 &compare_output($answer,&get_logfile(1));
75 # Now try with the file we're not updating being the actual file we're
76 # including: this and the previous one test different parts of the code.
78 &run_make_with_options($makefile3, "F=b", &get_logfile, 0);
80 $answer = "[ -f b ] || echo >> b\nhello\n";
81 &compare_output($answer,&get_logfile(1));
83 unlink('a','b','c');
85 # This tells the test driver that the perl test script executed properly.