1999-09-14 02:03:19 +00:00
|
|
|
# -*-perl-*-
|
|
|
|
$description = "Test the call function.\n";
|
|
|
|
|
|
|
|
$details = "Try various uses of call and ensure they all give the correct
|
|
|
|
results.\n";
|
|
|
|
|
2016-03-21 04:36:55 +00:00
|
|
|
run_make_test(q!
|
2000-01-11 07:31:42 +00:00
|
|
|
# Simple, just reverse two things
|
1999-09-14 02:03:19 +00:00
|
|
|
#
|
|
|
|
reverse = $2 $1
|
|
|
|
|
2012-03-04 00:24:20 +00:00
|
|
|
# A complex 'map' function, using recursive 'call'.
|
1999-09-14 02:03:19 +00:00
|
|
|
#
|
|
|
|
map = $(foreach a,$2,$(call $1,$a))
|
|
|
|
|
|
|
|
# Test using a builtin; this is silly as it's simpler to do without call
|
|
|
|
#
|
|
|
|
my-notdir = $(call notdir,$(1))
|
|
|
|
|
2000-01-11 07:31:42 +00:00
|
|
|
# Test using non-expanded builtins
|
|
|
|
#
|
|
|
|
my-foreach = $(foreach $(1),$(2),$(3))
|
|
|
|
my-if = $(if $(1),$(2),$(3))
|
|
|
|
|
2000-03-27 06:54:37 +00:00
|
|
|
# Test recursive invocations of call with different arguments
|
|
|
|
#
|
|
|
|
one = $(1) $(2) $(3)
|
|
|
|
two = $(call one,$(1),foo,$(2))
|
|
|
|
|
2002-05-10 03:15:07 +00:00
|
|
|
# Test recursion on the user-defined function. As a special case make
|
|
|
|
# won't error due to this.
|
|
|
|
# Implement transitive closure using $(call ...)
|
|
|
|
#
|
|
|
|
DEP_foo = bar baz quux
|
|
|
|
DEP_baz = quux blarp
|
|
|
|
rest = $(wordlist 2,$(words ${1}),${1})
|
2010-11-06 21:56:23 +00:00
|
|
|
tclose = $(if $1,$(firstword $1)\
|
2002-05-10 03:15:07 +00:00
|
|
|
$(call tclose,$(sort ${DEP_$(firstword $1)} $(call rest,$1))))
|
2000-03-27 06:54:37 +00:00
|
|
|
|
1999-09-14 02:03:19 +00:00
|
|
|
all: ; @echo '$(call reverse,bar,foo)'; \
|
|
|
|
echo '$(call map,origin,MAKE reverse map)'; \
|
2000-01-11 07:31:42 +00:00
|
|
|
echo '$(call my-notdir,a/b c/d e/f)'; \
|
|
|
|
echo '$(call my-foreach)'; \
|
|
|
|
echo '$(call my-foreach,a,,,)'; \
|
|
|
|
echo '$(call my-if,a,b,c)'; \
|
2002-05-10 03:15:07 +00:00
|
|
|
echo '$(call two,bar,baz)'; \
|
2016-03-21 04:36:55 +00:00
|
|
|
echo '$(call tclose,foo)';
|
|
|
|
!,
|
|
|
|
"", "foo bar\ndefault file file\nb d f\n\n\nb\nbar foo baz\nfoo bar baz blarp quux \n");
|
1999-09-14 02:03:19 +00:00
|
|
|
|
2016-03-21 04:36:55 +00:00
|
|
|
# These won't work because call expands all its arguments first, before
|
|
|
|
# passing them on, then marks them as resolved/simple, so they're not
|
|
|
|
# expanded again by the function.
|
2000-03-27 06:54:37 +00:00
|
|
|
#
|
2016-03-21 04:36:55 +00:00
|
|
|
# echo '$(call my-foreach,a,x y z,$$(a)$$(a))'; \
|
|
|
|
# echo '$(call my-if,,$$(info don't print this),$$(info do print this))'
|
|
|
|
#
|
|
|
|
# $answer = "xx yy zz\ndo print this\n";
|
2003-01-22 13:45:44 +00:00
|
|
|
|
|
|
|
# TEST eclipsing of arguments when invoking sub-calls
|
|
|
|
|
2016-03-21 04:36:55 +00:00
|
|
|
run_make_test(q!
|
2003-01-22 13:45:44 +00:00
|
|
|
all = $1 $2 $3 $4 $5 $6 $7 $8 $9
|
|
|
|
|
|
|
|
level1 = $(call all,$1,$2,$3,$4,$5)
|
|
|
|
level2 = $(call level1,$1,$2,$3)
|
|
|
|
level3 = $(call level2,$1,$2,$3,$4,$5)
|
|
|
|
|
|
|
|
all:
|
|
|
|
@echo $(call all,1,2,3,4,5,6,7,8,9,10,11)
|
|
|
|
@echo $(call level1,1,2,3,4,5,6,7,8)
|
|
|
|
@echo $(call level2,1,2,3,4,5,6,7,8)
|
|
|
|
@echo $(call level3,1,2,3,4,5,6,7,8)
|
2016-03-21 04:36:55 +00:00
|
|
|
!,
|
|
|
|
"", "1 2 3 4 5 6 7 8 9\n1 2 3 4 5\n1 2 3\n1 2 3\n");
|
2003-01-22 13:45:44 +00:00
|
|
|
|
2011-09-12 05:29:58 +00:00
|
|
|
# Ensure that variables are defined in global scope even in a $(call ...)
|
|
|
|
|
|
|
|
delete $ENV{X123};
|
|
|
|
|
|
|
|
run_make_test('
|
|
|
|
tst = $(eval export X123)
|
|
|
|
$(call tst)
|
|
|
|
all: ; @echo "$${X123-not set}"
|
|
|
|
',
|
|
|
|
'', "\n");
|
|
|
|
|
1999-09-14 02:03:19 +00:00
|
|
|
1;
|
2016-03-21 04:36:55 +00:00
|
|
|
|
|
|
|
### Local Variables:
|
|
|
|
### eval: (setq whitespace-action (delq 'auto-cleanup whitespace-action))
|
|
|
|
### End:
|