| 1 | # -*-perl-*-
|
|---|
| 2 | $description = "Test the call function.\n";
|
|---|
| 3 |
|
|---|
| 4 | $details = "Try various uses of call and ensure they all give the correct
|
|---|
| 5 | results.\n";
|
|---|
| 6 |
|
|---|
| 7 | run_make_test(q!
|
|---|
| 8 | # Simple, just reverse two things
|
|---|
| 9 | #
|
|---|
| 10 | reverse = $2 $1
|
|---|
| 11 |
|
|---|
| 12 | # A complex 'map' function, using recursive 'call'.
|
|---|
| 13 | #
|
|---|
| 14 | map = $(foreach a,$2,$(call $1,$a))
|
|---|
| 15 |
|
|---|
| 16 | # Test using a builtin; this is silly as it's simpler to do without call
|
|---|
| 17 | #
|
|---|
| 18 | my-notdir = $(call notdir,$(1))
|
|---|
| 19 |
|
|---|
| 20 | # Test using non-expanded builtins
|
|---|
| 21 | #
|
|---|
| 22 | my-foreach = $(foreach $(1),$(2),$(3))
|
|---|
| 23 | my-if = $(if $(1),$(2),$(3))
|
|---|
| 24 |
|
|---|
| 25 | # Test recursive invocations of call with different arguments
|
|---|
| 26 | #
|
|---|
| 27 | one = $(1) $(2) $(3)
|
|---|
| 28 | two = $(call one,$(1),foo,$(2))
|
|---|
| 29 |
|
|---|
| 30 | # Test recursion on the user-defined function. As a special case make
|
|---|
| 31 | # won't error due to this.
|
|---|
| 32 | # Implement transitive closure using $(call ...)
|
|---|
| 33 | #
|
|---|
| 34 | DEP_foo = bar baz quux
|
|---|
| 35 | DEP_baz = quux blarp
|
|---|
| 36 | rest = $(wordlist 2,$(words ${1}),${1})
|
|---|
| 37 | tclose = $(if $1,$(firstword $1)\
|
|---|
| 38 | $(call tclose,$(sort ${DEP_$(firstword $1)} $(call rest,$1))))
|
|---|
| 39 |
|
|---|
| 40 | all: ; @echo '$(call reverse,bar,foo)'; \
|
|---|
| 41 | echo '$(call map,origin,MAKE reverse map)'; \
|
|---|
| 42 | echo '$(call my-notdir,a/b c/d e/f)'; \
|
|---|
| 43 | echo '$(call my-foreach)'; \
|
|---|
| 44 | echo '$(call my-foreach,a,,,)'; \
|
|---|
| 45 | echo '$(call my-if,a,b,c)'; \
|
|---|
| 46 | echo '$(call two,bar,baz)'; \
|
|---|
| 47 | echo '$(call tclose,foo)';
|
|---|
| 48 | !,
|
|---|
| 49 | "", "foo bar\ndefault file file\nb d f\n\n\nb\nbar foo baz\nfoo bar baz blarp quux \n");
|
|---|
| 50 |
|
|---|
| 51 | # These won't work because call expands all its arguments first, before
|
|---|
| 52 | # passing them on, then marks them as resolved/simple, so they're not
|
|---|
| 53 | # expanded again by the function.
|
|---|
| 54 | #
|
|---|
| 55 | # echo '$(call my-foreach,a,x y z,$$(a)$$(a))'; \
|
|---|
| 56 | # echo '$(call my-if,,$$(info don't print this),$$(info do print this))'
|
|---|
| 57 | #
|
|---|
| 58 | # $answer = "xx yy zz\ndo print this\n";
|
|---|
| 59 |
|
|---|
| 60 | # TEST eclipsing of arguments when invoking sub-calls
|
|---|
| 61 |
|
|---|
| 62 | run_make_test(q!
|
|---|
| 63 | all = $1 $2 $3 $4 $5 $6 $7 $8 $9
|
|---|
| 64 |
|
|---|
| 65 | level1 = $(call all,$1,$2,$3,$4,$5)
|
|---|
| 66 | level2 = $(call level1,$1,$2,$3)
|
|---|
| 67 | level3 = $(call level2,$1,$2,$3,$4,$5)
|
|---|
| 68 |
|
|---|
| 69 | all:
|
|---|
| 70 | @echo $(call all,1,2,3,4,5,6,7,8,9,10,11)
|
|---|
| 71 | @echo $(call level1,1,2,3,4,5,6,7,8)
|
|---|
| 72 | @echo $(call level2,1,2,3,4,5,6,7,8)
|
|---|
| 73 | @echo $(call level3,1,2,3,4,5,6,7,8)
|
|---|
| 74 | !,
|
|---|
| 75 | "", "1 2 3 4 5 6 7 8 9\n1 2 3 4 5\n1 2 3\n1 2 3\n");
|
|---|
| 76 |
|
|---|
| 77 | # Ensure that variables are defined in global scope even in a $(call ...)
|
|---|
| 78 |
|
|---|
| 79 | delete $ENV{X123};
|
|---|
| 80 |
|
|---|
| 81 | run_make_test('
|
|---|
| 82 | tst = $(eval export X123)
|
|---|
| 83 | $(call tst)
|
|---|
| 84 | all: ; @echo "$${X123-not set}"
|
|---|
| 85 | ',
|
|---|
| 86 | '', "\n");
|
|---|
| 87 |
|
|---|
| 88 | 1;
|
|---|
| 89 |
|
|---|
| 90 | ### Local Variables:
|
|---|
| 91 | ### eval: (setq whitespace-action (delq 'auto-cleanup whitespace-action))
|
|---|
| 92 | ### End:
|
|---|