2 $description = "Test the call function.\n";
4 $details = "Try various uses of call and ensure they all give the correct
7 open(MAKEFILE, "> $makefile");
9 # The Contents of the MAKEFILE ...
11 print MAKEFILE <<'EOMAKE';
12 # Simple, just reverse two things
16 # A complex `map' function, using recursive `call'.
18 map = $(foreach a,$2,$(call $1,$a))
20 # Test using a builtin; this is silly as it's simpler to do without call
22 my-notdir = $(call notdir,$(1))
24 # Test using non-expanded builtins
26 my-foreach = $(foreach $(1),$(2),$(3))
27 my-if = $(if $(1),$(2),$(3))
29 # Test recursive invocations of call with different arguments
32 two = $(call one,$(1),foo,$(2))
34 # Test recursion on the user-defined function. As a special case make
35 # won't error due to this.
36 # Implement transitive closure using $(call ...)
38 DEP_foo = bar baz quux
40 rest = $(wordlist 2,$(words ${1}),${1})
41 tclose = $(if $1,$(firstword $1) \
42 $(call tclose,$(sort ${DEP_$(firstword $1)} $(call rest,$1))))
44 all: ; @echo '$(call reverse,bar,foo)'; \
45 echo '$(call map,origin,MAKE reverse map)'; \
46 echo '$(call my-notdir,a/b c/d e/f)'; \
47 echo '$(call my-foreach)'; \
48 echo '$(call my-foreach,a,,,)'; \
49 echo '$(call my-if,a,b,c)'; \
50 echo '$(call two,bar,baz)'; \
51 echo '$(call tclose,foo)'
57 # These won't work until/unless PR/1527 is resolved.
58 # echo '$(call my-foreach,a,x y z,$(a)$(a))'; \
59 # echo '$(call my-if,,$(warning don't print this),ok)'
61 # $answer = "xx yy zz\nok\n";
63 # END of Contents of MAKEFILE
67 &run_make_with_options($makefile, "", &get_logfile);
68 $answer = "foo bar\ndefault file file\nb d f\n\n\nb\nbar foo baz\nfoo bar baz blarp quux \n";
70 &compare_output($answer, &get_logfile(1));