| 1 | # -*-perl-*-
|
|---|
| 2 | $description = "Test the -n option.\n";
|
|---|
| 3 |
|
|---|
| 4 | $details = "Try various uses of -n and ensure they all give the correct results.\n";
|
|---|
| 5 |
|
|---|
| 6 | touch('orig');
|
|---|
| 7 |
|
|---|
| 8 | run_make_test(q!
|
|---|
| 9 | final: intermediate ; echo >> $@
|
|---|
| 10 | intermediate: orig ; echo >> $@
|
|---|
| 11 | !,
|
|---|
| 12 | '', "echo >> intermediate\necho >> final\n");
|
|---|
| 13 |
|
|---|
| 14 | # TEST 1
|
|---|
| 15 |
|
|---|
| 16 | run_make_test(undef, '-Worig -n', "echo >> intermediate\necho >> final\n");
|
|---|
| 17 |
|
|---|
| 18 | rmfiles(qw(orig intermediate final));
|
|---|
| 19 |
|
|---|
| 20 | # We consider the actual updated timestamp of targets with all
|
|---|
| 21 | # recursive commands, even with -n. Switching this to the new model
|
|---|
| 22 | # is non-trivial because we use a trick below to change the log content
|
|---|
| 23 | # before we compare it ...
|
|---|
| 24 |
|
|---|
| 25 | $makefile2 = &get_tmpfile;
|
|---|
| 26 |
|
|---|
| 27 | open(MAKEFILE, "> $makefile2");
|
|---|
| 28 |
|
|---|
| 29 | print MAKEFILE <<'EOF';
|
|---|
| 30 | .SUFFIXES:
|
|---|
| 31 | BAR = # nothing
|
|---|
| 32 | FOO = +$(BAR)
|
|---|
| 33 | a: b; echo > $@
|
|---|
| 34 | b: c; $(FOO)
|
|---|
| 35 | EOF
|
|---|
| 36 |
|
|---|
| 37 | close(MAKEFILE);
|
|---|
| 38 |
|
|---|
| 39 | &utouch(-20, 'b');
|
|---|
| 40 | &utouch(-10, 'a');
|
|---|
| 41 | &touch('c');
|
|---|
| 42 |
|
|---|
| 43 | # TEST 2
|
|---|
| 44 |
|
|---|
| 45 | &run_make_with_options($makefile2, "", &get_logfile);
|
|---|
| 46 | $answer = "$make_name: 'a' is up to date.\n";
|
|---|
| 47 | &compare_output($answer, &get_logfile(1));
|
|---|
| 48 |
|
|---|
| 49 | # TEST 3
|
|---|
| 50 |
|
|---|
| 51 | &run_make_with_options($makefile2, "-n", &get_logfile);
|
|---|
| 52 | $answer = "$make_name: 'a' is up to date.\n";
|
|---|
| 53 | &compare_output($answer, &get_logfile(1));
|
|---|
| 54 |
|
|---|
| 55 | # TEST 4
|
|---|
| 56 |
|
|---|
| 57 | unlink(qw(a b));
|
|---|
| 58 |
|
|---|
| 59 | &run_make_with_options($makefile2, "-t -n", &get_logfile);
|
|---|
| 60 |
|
|---|
| 61 | open(DASH_N_LOG, ">>" . &get_logfile(1));
|
|---|
| 62 | print DASH_N_LOG "a exists but should not!\n" if -e 'a';
|
|---|
| 63 | print DASH_N_LOG "b exists but should not!\n" if -e 'b';
|
|---|
| 64 | close(DASH_N_LOG);
|
|---|
| 65 |
|
|---|
| 66 | &compare_output("touch b\ntouch a\n", &get_logfile(1));
|
|---|
| 67 |
|
|---|
| 68 | # CLEANUP
|
|---|
| 69 |
|
|---|
| 70 | unlink(qw(a b c));
|
|---|
| 71 |
|
|---|
| 72 | # Ensure -n continues to be included with recursive/re-execed make
|
|---|
| 73 | # See Savannah bug #38051
|
|---|
| 74 |
|
|---|
| 75 | $topmake = &get_tmpfile;
|
|---|
| 76 | $submake = &get_tmpfile;
|
|---|
| 77 |
|
|---|
| 78 | open(MAKEFILE, "> $topmake");
|
|---|
| 79 | print MAKEFILE <<"EOF";
|
|---|
| 80 | foo: ; \@\$(MAKE) -f "$submake" bar
|
|---|
| 81 | EOF
|
|---|
| 82 | close(MAKEFILE);
|
|---|
| 83 |
|
|---|
| 84 |
|
|---|
| 85 | # The bar target should print what would happen, but not actually run
|
|---|
| 86 | open(MAKEFILE, "> $submake");
|
|---|
| 87 | print MAKEFILE <<'EOF';
|
|---|
| 88 | inc: ; touch $@
|
|---|
| 89 | -include inc
|
|---|
| 90 | bar: ; @echo $(strip $(MAKEFLAGS))
|
|---|
| 91 | EOF
|
|---|
| 92 | close(MAKEFILE);
|
|---|
| 93 |
|
|---|
| 94 | &run_make_with_options($topmake, '-n --no-print-directory', &get_logfile);
|
|---|
| 95 | $answer = "$make_command -f \"$submake\" bar\ntouch inc\necho n --no-print-directory\n";
|
|---|
| 96 | &compare_output($answer, &get_logfile(1));
|
|---|
| 97 |
|
|---|
| 98 | unlink('inc');
|
|---|
| 99 |
|
|---|
| 100 | 1;
|
|---|