Home | History | Annotate | Line # | Download | only in targets
      1  1.1  christos #! -*-perl-*-
      2  1.1  christos 
      3  1.1  christos $description = "Test the behaviour of the .SECONDARY target.";
      4  1.1  christos 
      5  1.1  christos $details = "\
      6  1.1  christos Test the behavior of the .SECONDARY special target.
      7  1.1  christos Create a makefile where a file would not normally be considered
      8  1.1  christos intermediate, then specify it as .SECONDARY.  Build and note that it's
      9  1.1  christos not automatically deleted.  Delete the file.  Rebuild to ensure that
     10  1.1  christos it's not created if it doesn't exist but doesn't need to be built.
     11  1.1  christos Change the original and ensure that the secondary file and the ultimate
     12  1.1  christos target are both rebuilt, and that the secondary file is not deleted.
     13  1.1  christos 
     14  1.1  christos Try this with implicit rules and explicit rules: both should work.\n";
     15  1.1  christos 
     16  1.1  christos open(MAKEFILE,"> $makefile");
     17  1.1  christos 
     18  1.1  christos print MAKEFILE <<'EOF';
     19  1.1  christos 
     20  1.1  christos .SECONDARY: foo.e
     21  1.1  christos 
     22  1.1  christos # Implicit rule test
     23  1.1  christos %.d : %.e ; cp $< $@
     24  1.1  christos %.e : %.f ; cp $< $@
     25  1.1  christos 
     26  1.1  christos foo.d: foo.e
     27  1.1  christos 
     28  1.1  christos # Explicit rule test
     29  1.1  christos foo.c: foo.e ; cp $< $@
     30  1.1  christos EOF
     31  1.1  christos 
     32  1.1  christos close(MAKEFILE);
     33  1.1  christos 
     34  1.1  christos # TEST #1
     35  1.1  christos 
     36  1.1  christos &utouch(-20, 'foo.f');
     37  1.1  christos 
     38  1.1  christos &run_make_with_options($makefile,'foo.d',&get_logfile);
     39  1.1  christos $answer = "cp foo.f foo.e\ncp foo.e foo.d\n";
     40  1.1  christos &compare_output($answer, &get_logfile(1));
     41  1.1  christos 
     42  1.1  christos # TEST #2
     43  1.1  christos 
     44  1.1  christos unlink('foo.e');
     45  1.1  christos 
     46  1.1  christos &run_make_with_options($makefile,'foo.d',&get_logfile);
     47  1.1  christos $answer = "$make_name: `foo.d' is up to date.\n";
     48  1.1  christos &compare_output($answer, &get_logfile(1));
     49  1.1  christos 
     50  1.1  christos # TEST #3
     51  1.1  christos 
     52  1.1  christos &utouch(-10, 'foo.d');
     53  1.1  christos &touch('foo.f');
     54  1.1  christos 
     55  1.1  christos &run_make_with_options($makefile,'foo.d',&get_logfile);
     56  1.1  christos $answer = "cp foo.f foo.e\ncp foo.e foo.d\n";
     57  1.1  christos &compare_output($answer, &get_logfile(1));
     58  1.1  christos 
     59  1.1  christos # TEST #4
     60  1.1  christos 
     61  1.1  christos &run_make_with_options($makefile,'foo.c',&get_logfile);
     62  1.1  christos $answer = "cp foo.e foo.c\n";
     63  1.1  christos &compare_output($answer, &get_logfile(1));
     64  1.1  christos 
     65  1.1  christos # TEST #5
     66  1.1  christos 
     67  1.1  christos unlink('foo.e');
     68  1.1  christos 
     69  1.1  christos &run_make_with_options($makefile,'foo.c',&get_logfile);
     70  1.1  christos $answer = "$make_name: `foo.c' is up to date.\n";
     71  1.1  christos &compare_output($answer, &get_logfile(1));
     72  1.1  christos 
     73  1.1  christos # TEST #6
     74  1.1  christos 
     75  1.1  christos &utouch(-10, 'foo.c');
     76  1.1  christos &touch('foo.f');
     77  1.1  christos 
     78  1.1  christos &run_make_with_options($makefile,'foo.c',&get_logfile);
     79  1.1  christos $answer = "cp foo.f foo.e\ncp foo.e foo.c\n";
     80  1.1  christos &compare_output($answer, &get_logfile(1));
     81  1.1  christos 
     82  1.1  christos unlink('foo.f', 'foo.e', 'foo.d', 'foo.c');
     83  1.1  christos 
     84  1.1  christos # TEST #7 -- test the "global" .SECONDARY, with no targets.
     85  1.1  christos 
     86  1.1  christos $makefile2 = &get_tmpfile;
     87  1.1  christos 
     88  1.1  christos open(MAKEFILE, "> $makefile2");
     89  1.1  christos 
     90  1.1  christos print MAKEFILE <<'EOF';
     91  1.1  christos .SECONDARY:
     92  1.1  christos 
     93  1.1  christos final: intermediate
     94  1.1  christos intermediate: source
     95  1.1  christos 
     96  1.1  christos final intermediate source:
     97  1.1  christos 	echo $< > $@
     98  1.1  christos EOF
     99  1.1  christos 
    100  1.1  christos close(MAKEFILE);
    101  1.1  christos 
    102  1.1  christos &utouch(-10, 'source');
    103  1.1  christos touch('final');
    104  1.1  christos 
    105  1.1  christos &run_make_with_options($makefile2, '', &get_logfile);
    106  1.1  christos $answer = "$make_name: `final' is up to date.\n";
    107  1.1  christos &compare_output($answer, &get_logfile(1));
    108  1.1  christos 
    109  1.1  christos unlink('source', 'final', 'intermediate');
    110  1.1  christos 
    111  1.1  christos 
    112  1.1  christos # TEST #8 -- test the "global" .SECONDARY, with .PHONY.
    113  1.1  christos 
    114  1.1  christos touch('version2');
    115  1.1  christos run_make_test('
    116  1.1  christos .PHONY: version
    117  1.1  christos .SECONDARY:
    118  1.1  christos version2: version ; @echo GOOD
    119  1.1  christos all: version2',
    120  1.1  christos               'all', 'GOOD');
    121  1.1  christos 
    122  1.1  christos unlink('version2');
    123  1.1  christos 
    124  1.1  christos # This tells the test driver that the perl test script executed properly.
    125  1.1  christos 1;
    126