Debian Codegraph @

tests/scripts/options/dash-I

raw
1 # -*-perl-*-
2
3 $description = "The following test creates a makefile to test the -I option.";
4
5 $details = "\
6 This test tests the -I option by including a filename in
7 another directory and giving make that directory name
8 under -I in the command line. Without this option, the make
9 would fail to find the included file. It also checks to make
10 sure that the -I option gets passed to recursive makes.";
11
12 use File::Spec;
13
14 # Create a directory and put a makefile in it.
15 # We can't put it in the current directory since that's automatically searched
16 # anyway.
17 my $subdir = 'idir';
18 mkdir($subdir, 0777);
19
20 my $included = 'ifile.mk';
21 my $ipath = File::Spec->catfile($subdir, $included);
22 create_file($ipath, "
23 ANOTHER:
24 \t\@echo This is another included makefile
25 recurse:
26 \t\@\$(MAKE) ANOTHER -f \$(main_makefile)\n");
27
28 my $nosuch = "#MAKEFILE#:5: $included: $ERR_no_such_file
29 #MAKE#: *** No rule to make target '$included'. Stop.\n";
30
31
32 # Verify that we get an error if we don't have -I
33 run_make_test(qq!
34 main_makefile := \$(firstword \$(MAKEFILE_LIST))
35 all:
36 \t\@echo There should be no errors for this makefile
37 include $included
38 !,
39 '', $nosuch, 512);
40
41 # Check basic -I works
42 run_make_test(undef, "-I $subdir all",
43 "There should be no errors for this makefile\n");
44
45 # Check that the included target works
46 run_make_test(undef, "-I $subdir ANOTHER",
47 "This is another included makefile\n");
48
49 # Check that -I is passed down through MAKEFLAGS
50 run_make_test(undef, "-I $subdir recurse",
51 "#MAKE#[1]: Entering directory '#PWD#'
52 This is another included makefile
53 #MAKE#[1]: Leaving directory '#PWD#'\n");
54
55 # Verify that we get an error if we add -I- to delete previous includes
56 run_make_test(undef, "-I $subdir -I- all", $nosuch, 512);
57
58 # Make another directory with the same name and make sure the right one is
59 # chosen if -I- stops the path.
60
61 mkdir('idir2', 0777);
62 my $ipath2 = File::Spec->catfile('idir2', $included);
63 create_file($ipath2, "This is a bad makefile!!\n");
64
65 run_make_test(undef, "-I idir2 -I $subdir ANOTHER",
66 "$included:1: *** missing separator. Stop.\n", 512);
67
68 run_make_test(undef, "-I idir2 -I - -I $subdir ANOTHER",
69 "This is another included makefile\n");
70
71 # Check that -I- is passed down through MAKEFLAGS
72 run_make_test(undef, "-I idir2 -I - -I $subdir recurse",
73 "#MAKE#[1]: Entering directory '#PWD#'
74 This is another included makefile
75 #MAKE#[1]: Leaving directory '#PWD#'\n");
76
77 unlink($ipath2);
78 rmdir('idir2');
79
80 # The only way to check if -I- voids included directories is to see if a file
81 # exists in one and try to include it. We very likely can't add our own files
82 # to the default directories since they're probably write-protected. This
83 # won't work if none of the default directories contain any files :-/
84
85 create_file('defaultdirs.mk', "\$(info \$(.INCLUDE_DIRS))\nall:;\@:\n");
86 my $cmd = subst_make_string("#MAKEPATH# -f defaultdirs.mk");
87 my @dirs = `$cmd`;
88 my $dirs = $dirs[0];
89 $dirs =~ s/\r?\n//g;
90 unlink('defaultdirs.mk');
91
92 my $fn = undef;
93 foreach my $dn (split ' ', $dirs) {
94 # On Windows the default is "." which is bogus!
95 if ($dn ne '.') {
96 my @files = glob(File::Spec->catfile($dn, "*"));
97 if (@files) {
98 (undef, undef, $fn) = File::Spec->splitpath($files[0]);
99 last;
100 }
101 }
102 }
103
104 if ($fn) {
105 run_make_test("
106 all:;
107 include $fn
108 ",
109 '-I-', "#MAKEFILE#:3: $fn: $ERR_no_such_file
110 #MAKE#: *** No rule to make target '$fn'. Stop.\n", 512);
111 }
112
113 unlink($ipath);
114 rmdir($subdir);
115
116 1;