| 1 | # -*-perl-*-
|
|---|
| 2 |
|
|---|
| 3 | $description = "Test define/endef variable assignments.";
|
|---|
| 4 |
|
|---|
| 5 | $details = "";
|
|---|
| 6 |
|
|---|
| 7 | # TEST 0: old-style basic define/endef
|
|---|
| 8 |
|
|---|
| 9 | run_make_test('
|
|---|
| 10 | define multi
|
|---|
| 11 | @echo hi
|
|---|
| 12 | echo there
|
|---|
| 13 | endef
|
|---|
| 14 |
|
|---|
| 15 | all: ; $(multi)
|
|---|
| 16 | ',
|
|---|
| 17 | '', "hi\necho there\nthere\n");
|
|---|
| 18 |
|
|---|
| 19 | # TEST 1: Various new-style define/endef
|
|---|
| 20 |
|
|---|
| 21 | run_make_test('
|
|---|
| 22 | FOO = foo
|
|---|
| 23 |
|
|---|
| 24 | define multi =
|
|---|
| 25 | echo hi
|
|---|
| 26 | @echo $(FOO)
|
|---|
| 27 | endef # this is the end
|
|---|
| 28 |
|
|---|
| 29 | define simple :=
|
|---|
| 30 | @echo $(FOO)
|
|---|
| 31 | endef
|
|---|
| 32 |
|
|---|
| 33 | define posix ::=
|
|---|
| 34 | @echo $(FOO)
|
|---|
| 35 | endef
|
|---|
| 36 |
|
|---|
| 37 | append = @echo a
|
|---|
| 38 |
|
|---|
| 39 | define append +=
|
|---|
| 40 |
|
|---|
| 41 | @echo b
|
|---|
| 42 | endef
|
|---|
| 43 |
|
|---|
| 44 | define cond ?= # this is a conditional
|
|---|
| 45 | @echo first
|
|---|
| 46 | endef
|
|---|
| 47 |
|
|---|
| 48 | define cond ?=
|
|---|
| 49 | @echo second
|
|---|
| 50 | endef
|
|---|
| 51 |
|
|---|
| 52 | FOO = there
|
|---|
| 53 |
|
|---|
| 54 | all: ; $(multi)
|
|---|
| 55 | $(simple)
|
|---|
| 56 | $(posix)
|
|---|
| 57 | $(append)
|
|---|
| 58 | $(cond)
|
|---|
| 59 | ',
|
|---|
| 60 | '', "echo hi\nhi\nthere\nfoo\nfoo\na\nb\nfirst\n");
|
|---|
| 61 |
|
|---|
| 62 | # TEST 1a: Various new-style define/endef, with no spaces
|
|---|
| 63 |
|
|---|
| 64 | run_make_test('
|
|---|
| 65 | FOO = foo
|
|---|
| 66 |
|
|---|
| 67 | define multi=
|
|---|
| 68 | echo hi
|
|---|
| 69 | @echo $(FOO)
|
|---|
| 70 | endef # this is the end
|
|---|
| 71 |
|
|---|
| 72 | define simple:=
|
|---|
| 73 | @echo $(FOO)
|
|---|
| 74 | endef
|
|---|
| 75 |
|
|---|
| 76 | define posix::=
|
|---|
| 77 | @echo $(FOO)
|
|---|
| 78 | endef
|
|---|
| 79 |
|
|---|
| 80 | append = @echo a
|
|---|
| 81 |
|
|---|
| 82 | define append+=
|
|---|
| 83 |
|
|---|
| 84 | @echo b
|
|---|
| 85 | endef
|
|---|
| 86 |
|
|---|
| 87 | define cond?= # this is a conditional
|
|---|
| 88 | @echo first
|
|---|
| 89 | endef
|
|---|
| 90 |
|
|---|
| 91 | define cond?=
|
|---|
| 92 | @echo second
|
|---|
| 93 | endef
|
|---|
| 94 |
|
|---|
| 95 | FOO = there
|
|---|
| 96 |
|
|---|
| 97 | all: ; $(multi)
|
|---|
| 98 | $(simple)
|
|---|
| 99 | $(posix)
|
|---|
| 100 | $(append)
|
|---|
| 101 | $(cond)
|
|---|
| 102 | ',
|
|---|
| 103 | '', "echo hi\nhi\nthere\nfoo\nfoo\na\nb\nfirst\n");
|
|---|
| 104 |
|
|---|
| 105 | # TEST 2: define in true section of conditional (containing conditional)
|
|---|
| 106 |
|
|---|
| 107 | run_make_test('
|
|---|
| 108 | FOO = foo
|
|---|
| 109 | NAME = def
|
|---|
| 110 | def =
|
|---|
| 111 | ifdef BOGUS
|
|---|
| 112 | define $(subst e,e,$(NAME)) =
|
|---|
| 113 | ifeq (1,1)
|
|---|
| 114 | FOO = bar
|
|---|
| 115 | endif
|
|---|
| 116 | endef
|
|---|
| 117 | endif
|
|---|
| 118 |
|
|---|
| 119 | $(eval $(def))
|
|---|
| 120 | all: ; @echo $(FOO)
|
|---|
| 121 | ',
|
|---|
| 122 | 'BOGUS=1', "bar\n");
|
|---|
| 123 |
|
|---|
| 124 | # TEST 3: define in false section of conditional (containing conditional)
|
|---|
| 125 |
|
|---|
| 126 | run_make_test(undef, '', "foo\n");
|
|---|
| 127 |
|
|---|
| 128 | # TEST 4: nested define (supported?)
|
|---|
| 129 |
|
|---|
| 130 | run_make_test('
|
|---|
| 131 | define outer
|
|---|
| 132 | define inner
|
|---|
| 133 | A = B
|
|---|
| 134 | endef
|
|---|
| 135 | endef
|
|---|
| 136 |
|
|---|
| 137 | $(eval $(outer))
|
|---|
| 138 |
|
|---|
| 139 | outer: ; @echo $(inner)
|
|---|
| 140 | ',
|
|---|
| 141 | '', "A = B\n");
|
|---|
| 142 |
|
|---|
| 143 | # TEST 5: NEGATIVE: Missing variable name
|
|---|
| 144 |
|
|---|
| 145 | run_make_test('
|
|---|
| 146 | NAME =
|
|---|
| 147 | define $(NAME) =
|
|---|
| 148 | ouch
|
|---|
| 149 | endef
|
|---|
| 150 | all: ; @echo ouch
|
|---|
| 151 | ',
|
|---|
| 152 | '', "#MAKEFILE#:3: *** empty variable name. Stop.\n", 512);
|
|---|
| 153 |
|
|---|
| 154 | # TEST 6: NEGATIVE: extra text after define
|
|---|
| 155 |
|
|---|
| 156 | run_make_test('
|
|---|
| 157 | NAME =
|
|---|
| 158 | define NAME = $(NAME)
|
|---|
| 159 | ouch
|
|---|
| 160 | endef
|
|---|
| 161 | all: ; @echo ok
|
|---|
| 162 | ',
|
|---|
| 163 | '', "#MAKEFILE#:3: extraneous text after 'define' directive\nok\n");
|
|---|
| 164 |
|
|---|
| 165 | # TEST 7: NEGATIVE: extra text after endef
|
|---|
| 166 |
|
|---|
| 167 | run_make_test('
|
|---|
| 168 | NAME =
|
|---|
| 169 | define NAME =
|
|---|
| 170 | ouch
|
|---|
| 171 | endef $(NAME)
|
|---|
| 172 | all: ; @echo ok
|
|---|
| 173 | ',
|
|---|
| 174 | '', "#MAKEFILE#:5: extraneous text after 'endef' directive\nok\n");
|
|---|
| 175 |
|
|---|
| 176 | # TEST 8: NEGATIVE: missing endef
|
|---|
| 177 |
|
|---|
| 178 | run_make_test('
|
|---|
| 179 | NAME =
|
|---|
| 180 | all: ; @echo ok
|
|---|
| 181 | define NAME =
|
|---|
| 182 | ouch
|
|---|
| 183 | endef$(NAME)
|
|---|
| 184 | ',
|
|---|
| 185 | '', "#MAKEFILE#:4: *** missing 'endef', unterminated 'define'. Stop.\n", 512);
|
|---|
| 186 |
|
|---|
| 187 | # -------------------------
|
|---|
| 188 | # Make sure that prefix characters apply properly to define/endef values.
|
|---|
| 189 | #
|
|---|
| 190 | # There's a bit of oddness here if you try to use a variable to hold the
|
|---|
| 191 | # prefix character for a define. Even though something like this:
|
|---|
| 192 | #
|
|---|
| 193 | # define foo
|
|---|
| 194 | # echo bar
|
|---|
| 195 | # endef
|
|---|
| 196 | #
|
|---|
| 197 | # all: ; $(V)$(foo)
|
|---|
| 198 | #
|
|---|
| 199 | # (where V=@) can be seen by the user to be obviously different than this:
|
|---|
| 200 | #
|
|---|
| 201 | # define foo
|
|---|
| 202 | # $(V)echo bar
|
|---|
| 203 | # endef
|
|---|
| 204 | #
|
|---|
| 205 | # all: ; $(foo)
|
|---|
| 206 | #
|
|---|
| 207 | # and the user thinks it should behave the same as when the "@" is literal
|
|---|
| 208 | # instead of in a variable, that can't happen because by the time make
|
|---|
| 209 | # expands the variables for the command line and sees it begins with a "@" it
|
|---|
| 210 | # can't know anymore whether the prefix character came before the variable
|
|---|
| 211 | # reference or was included in the first line of the variable reference.
|
|---|
| 212 |
|
|---|
| 213 | # TEST #5
|
|---|
| 214 | # -------
|
|---|
| 215 |
|
|---|
| 216 | run_make_test('
|
|---|
| 217 | define FOO
|
|---|
| 218 | $(V1)echo hello
|
|---|
| 219 | $(V2)echo world
|
|---|
| 220 | endef
|
|---|
| 221 | all: ; @$(FOO)
|
|---|
| 222 | ', '', 'hello
|
|---|
| 223 | world');
|
|---|
| 224 |
|
|---|
| 225 | # TEST #6
|
|---|
| 226 | # -------
|
|---|
| 227 |
|
|---|
| 228 | run_make_test(undef, 'V1=@ V2=@', 'hello
|
|---|
| 229 | world');
|
|---|
| 230 |
|
|---|
| 231 | # TEST #7
|
|---|
| 232 | # -------
|
|---|
| 233 |
|
|---|
| 234 | run_make_test('
|
|---|
| 235 | define FOO
|
|---|
| 236 | $(V1)echo hello
|
|---|
| 237 | $(V2)echo world
|
|---|
| 238 | endef
|
|---|
| 239 | all: ; $(FOO)
|
|---|
| 240 | ', 'V1=@', 'hello
|
|---|
| 241 | echo world
|
|---|
| 242 | world');
|
|---|
| 243 |
|
|---|
| 244 | # TEST #8
|
|---|
| 245 | # -------
|
|---|
| 246 |
|
|---|
| 247 | run_make_test(undef, 'V2=@', 'echo hello
|
|---|
| 248 | hello
|
|---|
| 249 | world');
|
|---|
| 250 |
|
|---|
| 251 | # TEST #9
|
|---|
| 252 | # -------
|
|---|
| 253 |
|
|---|
| 254 | run_make_test(undef, 'V1=@ V2=@', 'hello
|
|---|
| 255 | world');
|
|---|
| 256 |
|
|---|
| 257 | # TEST #10
|
|---|
| 258 | # -------
|
|---|
| 259 | # Test the basics; a "@" internally to the variable applies to only one line.
|
|---|
| 260 | # A "@" before the variable applies to the entire variable.
|
|---|
| 261 |
|
|---|
| 262 | run_make_test('
|
|---|
| 263 | define FOO
|
|---|
| 264 | @echo hello
|
|---|
| 265 | echo world
|
|---|
| 266 | endef
|
|---|
| 267 | define BAR
|
|---|
| 268 | echo hello
|
|---|
| 269 | echo world
|
|---|
| 270 | endef
|
|---|
| 271 |
|
|---|
| 272 | all: foo bar
|
|---|
| 273 | foo: ; $(FOO)
|
|---|
| 274 | bar: ; @$(BAR)
|
|---|
| 275 | ', '', 'hello
|
|---|
| 276 | echo world
|
|---|
| 277 | world
|
|---|
| 278 | hello
|
|---|
| 279 | world
|
|---|
| 280 | ');
|
|---|
| 281 |
|
|---|
| 282 | 1;
|
|---|