1#                                                                    -*-perl-*-
2
3$description = "Test the make -k (don't stop on error) option.\n";
4
5$details = "\
6The makefile created in this test is a simulation of building
7a small product.  However, the trick to this one is that one
8of the dependencies of the main target does not exist.
9Without the -k option, make would fail immediately and not
10build any part of the target.  What we are looking for here,
11is that make builds the rest of the dependencies even though
12it knows that at the end it will fail to rebuild the main target.";
13
14open(MAKEFILE,"> $makefile");
15
16# The Contents of the MAKEFILE ...
17
18print MAKEFILE <<EOF;
19VPATH = $workdir
20edit:  main.o kbd.o commands.o display.o
21\t\@echo cc -o edit main.o kbd.o commands.o display.o
22
23main.o : main.c defs.h
24\t\@echo cc -c main.c
25
26kbd.o : kbd.c defs.h command.h
27\t\@echo cc -c kbd.c
28
29commands.o : command.c defs.h command.h
30\t\@echo cc -c commands.c
31
32display.o : display.c defs.h buffer.h
33\t\@echo cc -c display.c
34EOF
35
36# END of Contents of MAKEFILE
37
38close(MAKEFILE);
39
40
41@files_to_touch = ("$workdir${pathsep}main.c","$workdir${pathsep}defs.h",
42               "$workdir${pathsep}command.h",
43               "$workdir${pathsep}commands.c","$workdir${pathsep}display.c",
44               "$workdir${pathsep}buffer.h",
45	       "$workdir${pathsep}command.c");
46
47&touch(@files_to_touch);
48
49if ($vos) {
50  $error_code = 3307;
51}
52else {
53  $error_code = 512;
54}
55
56&run_make_with_options($makefile, "-k", &get_logfile, $error_code);
57
58# Create the answer to what should be produced by this Makefile
59$answer = "cc -c main.c
60$make_name: *** No rule to make target `kbd.c', needed by `kbd.o'.
61cc -c commands.c
62cc -c display.c
63$make_name: Target `edit' not remade because of errors.\n";
64
65# COMPARE RESULTS
66
67&compare_output($answer, &get_logfile(1));
68
69unlink(@files_to_touch) unless $keep;
70
71
72# TEST 1: Make sure that top-level targets that depend on targets that
73# previously failed to build, aren't attempted.  Regression for PR/1634.
74
75$makefile2 = &get_tmpfile;
76
77open(MAKEFILE, "> $makefile2");
78print MAKEFILE <<'EOF';
79.SUFFIXES:
80
81all: exe1 exe2; @echo making $@
82
83exe1 exe2: lib; @echo cp $^ $@
84
85lib: foo.o; @echo cp $^ $@
86
87foo.o: ; exit 1
88EOF
89
90close(MAKEFILE);
91
92&run_make_with_options($makefile2, "-k", &get_logfile, $error_code);
93
94$answer = "exit 1
95$make_name: *** [foo.o] Error 1
96$make_name: Target `all' not remade because of errors.\n";
97
98&compare_output($answer, &get_logfile(1));
99
100# TEST -- make sure we keep the error code if we can't create an included
101# makefile.
102
103run_make_test('all: ; @echo hi
104include ifile
105ifile: no-such-file; @false
106',
107              '-k',
108              "#MAKEFILE#:2: ifile: No such file or directory
109#MAKE#: *** No rule to make target `no-such-file', needed by `ifile'.
110#MAKE#: Failed to remake makefile `ifile'.
111hi\n",
112              512);
113
1141;
115