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