Imported Upstream version 4.4
[platform/upstream/make.git] / tests / scripts / variables / MAKEFLAGS
1 #                                                                    -*-perl-*-
2
3 $description = "Test proper behavior of MAKEFLAGS";
4
5 $details = "DETAILS";
6
7 # Normal flags aren't prefixed with "-"
8 run_make_test(q!
9 all: ; @echo /$(MAKEFLAGS)/
10 !,
11               '-e -r -R', '/erR/');
12
13 # Long arguments mean everything is prefixed with "-"
14 run_make_test(q!
15 all: ; @echo /$(MAKEFLAGS)/
16 !,
17               '--no-print-directory -e -r -R --trace', "#MAKEFILE#:2: update target 'all' due to: target does not exist
18 echo /erR --trace --no-print-directory/
19 /erR --trace --no-print-directory/");
20
21
22 # Recursive invocations of make should accumulate MAKEFLAGS values.
23 # Savannah bug #2216
24 run_make_test(q!
25 MSG = Fails
26 .RECIPEPREFIX = >
27 all:
28 > @echo '$@: MAKEFLAGS=$(MAKEFLAGS)'
29 > @MSG=Works $(MAKE) -e -f #MAKEFILE# jump
30 jump:
31 > @echo '$@ $(MSG): MAKEFLAGS=$(MAKEFLAGS)'
32 > @$(MAKE) -f #MAKEFILE# print
33 print:
34 > @echo '$@ $(MSG): MAKEFLAGS=$(MAKEFLAGS)'
35 .PHONY: all jump print
36 !,
37                   '--no-print-directory',
38                   'all: MAKEFLAGS= --no-print-directory
39 jump Works: MAKEFLAGS=e --no-print-directory
40 print Works: MAKEFLAGS=e --no-print-directory');
41
42 # Ensure MAKEFLAGS updates are handled immediately rather than later
43
44 mkdir('foo', 0777);
45 mkdir('bar', 0777);
46
47 run_make_test(q!
48 $(info MAKEFLAGS=$(MAKEFLAGS))
49 $(info INCLUDE_DIRS=$(.INCLUDE_DIRS))
50 MAKEFLAGS += -Ibar
51 $(info MAKEFLAGS=$(MAKEFLAGS))
52 $(info INCLUDE_DIRS=$(.INCLUDE_DIRS))
53 .PHONY: all
54 all: ; @echo 'MAKEFLAGS=$(MAKEFLAGS)' "\$$MAKEFLAGS=$$MAKEFLAGS"
55 !,
56               '-I- -Ifoo', 'MAKEFLAGS= -I- -Ifoo
57 INCLUDE_DIRS=foo
58 MAKEFLAGS= -I- -Ifoo -Ibar
59 INCLUDE_DIRS=foo bar
60 MAKEFLAGS= -I- -Ifoo -Ibar $MAKEFLAGS= -I- -Ifoo -Ibar');
61
62 rmdir('foo');
63 rmdir('bar');
64
65 # Test that command line switches are all present in MAKEFLAGS.
66 # sv 62514.
67 my @opts;
68
69 # Simple flags.
70 @opts = ('i', 'k', 'n', 'q', 'r', 's', 'w', 'd');
71 exists $FEATURES{'check-symlink'} and push @opts, 'L';
72
73 for my $opt (@opts) {
74   run_make_test(q!
75 MAKEFLAGS:=B
76 all:; $(info makeflags='$(MAKEFLAGS)')
77 !, "-$opt", "/makeflags='B$opt'/");
78 }
79
80 # Switches which carry arguments.
81 @opts = (' -I/tmp', ' -Onone', ' --debug=b', ' -l2.5');
82 for my $opt (@opts) {
83   run_make_test(q!
84 MAKEFLAGS:=B
85 all:; $(info makeflags='$(MAKEFLAGS)')
86 !, "$opt", "/makeflags='B$opt'/");
87 }
88
89 # Long options which take no arguments.
90 # sv 62514.
91 @opts = (' --no-print-directory', ' --warn-undefined-variables', ' --trace');
92 for my $opt (@opts) {
93 run_make_test(q!
94 MAKEFLAGS:=B
95 all:; $(info makeflags='$(MAKEFLAGS)')
96 !, "$opt", "/makeflags='B$opt'/");
97 }
98
99 # Test that make filters out duplicates.
100 # Each option is specified in the makefile, env and on the command line.
101 @opts = (' -I/tmp', ' -Onone', ' --debug=b', ' -l2.5');
102 $ENV{'MAKEFLAGS'} = $opt;
103 for my $opt (@opts) {
104   run_make_test("
105 MAKEFLAGS:=B $opt
106 all:; \$(info makeflags='\$(MAKEFLAGS)')
107 ", "$opt", "/makeflags='B$opt'/");
108 }
109
110 # Test that make filters out duplicates.
111 # Each option is specified in the makefile, env and on the command line.
112 # decode_switches reallocates when the number of parameters in sl->list exceeds 5.
113 # This test exercises the realloc branch.
114 $ENV{'MAKEFLAGS'} = '-I1 -Onone --debug=b -l2.5 -I2 -I3 -I4 -I5 -I6 -I2 -I2';
115 run_make_test(q!
116 MAKEFLAGS:=B -I1 -Onone --debug=b -l2.5 -I2 -I3 -I4 -I5 -I6 -I2 -I2
117 all:; $(info makeflags='$(MAKEFLAGS)')
118 !,
119 '-I1 -Onone --debug=b -l2.5 -I2 -I3 -I4 -I5 -I6',
120 "/makeflags='B -I1 -I2 -I3 -I4 -I5 -I6 -l2.5 -Onone --debug=b'/");
121
122 # A mix of multiple flags from env, the makefile and command line.
123 # Skip -L since it's not available everywhere
124 $ENV{'MAKEFLAGS'} = 'ikB --no-print-directory --warn-undefined-variables --trace';
125 run_make_test(q!
126 MAKEFLAGS:=iknqrswd -I/tmp -I/tmp -Onone -Onone -l2.5 -l2.5
127 all:; $(info makeflags='$(MAKEFLAGS)')
128 !,
129 '-Onone -l2.5 -l2.5 -Onone -I/tmp -iknqrswd -i -n -s -k -I/tmp',
130 "/makeflags='Bdiknqrsw -I/tmp -l2.5 -Onone --trace --warn-undefined-variables'/");
131
132 # Verify MAKEFLAGS are all available to shell functions
133 $ENV{'MAKEFLAGS'} = 'ikB --no-print-directory --warn-undefined-variables';
134 run_make_test(q!
135 MAKEFLAGS := iknqrsw -I/tmp -I/tmp -Onone -Onone -l2.5 -l2.5 --no-print-directory
136 XX := $(shell echo "$$MAKEFLAGS")
137 all:; $(info makeflags='$(XX)')
138 !,
139     '-Onone -l2.5 -l2.5 -Onone -I/tmp -iknqrs -i -n -s -k -I/tmp',
140     "makeflags='iknqrsw -I/tmp -I/tmp -Onone -Onone -l2.5 -l2.5 --no-print-directory'");
141
142 # Verify that command line arguments are included in MAKEFLAGS
143 run_make_test(q!
144 all: ; @echo $(MAKEFLAGS)
145 !,
146               '-e FOO=bar -r -R', 'erR -- FOO=bar');
147
148 # Long arguments mean everything is prefixed with "-"
149 run_make_test(q!
150 all: ; @echo /$(MAKEFLAGS)/
151 !,
152               '--no-print-directory -e -r -R --trace FOO=bar',
153               "#MAKEFILE#:2: update target 'all' due to: target does not exist
154 echo /erR --trace --no-print-directory -- FOO=bar/
155 /erR --trace --no-print-directory -- FOO=bar/");
156
157
158 1;