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";
69
&compare_output($answer, &get_logfile(1));
72
# TEST eclipsing of arguments when invoking sub-calls
74
$makefile2 = &get_tmpfile;
76
open(MAKEFILE,"> $makefile2");
78
print MAKEFILE <<'EOF';
80
all = $1 $2 $3 $4 $5 $6 $7 $8 $9
82
level1 = $(call all,$1,$2,$3,$4,$5)
83
level2 = $(call level1,$1,$2,$3)
84
level3 = $(call level2,$1,$2,$3,$4,$5)
87
@echo $(call all,1,2,3,4,5,6,7,8,9,10,11)
88
@echo $(call level1,1,2,3,4,5,6,7,8)
89
@echo $(call level2,1,2,3,4,5,6,7,8)
90
@echo $(call level3,1,2,3,4,5,6,7,8)
95
&run_make_with_options($makefile2, "", &get_logfile);
96
$answer = "1 2 3 4 5 6 7 8 9\n1 2 3 4 5\n1 2 3\n1 2 3\n";
97
&compare_output($answer,&get_logfile(1));
99
# Ensure that variables are defined in global scope even in a $(call ...)
104
tst = $(eval export X123)
106
all: ; @echo "$${X123-not set}"