VirtualBox

source: kBuild/vendor/gnumake/current/tests/scripts/functions/call

Last change on this file was 3138, checked in by bird, 7 years ago

Imported make 4.2.1 (2e55f5e4abdc0e38c1d64be703b446695e70b3b6) from https://git.savannah.gnu.org/git/make.git.

  • Property svn:eol-style set to LF
File size: 2.5 KB
Line 
1# -*-perl-*-
2$description = "Test the call function.\n";
3
4$details = "Try various uses of call and ensure they all give the correct
5results.\n";
6
7run_make_test(q!
8# Simple, just reverse two things
9#
10reverse = $2 $1
11
12# A complex 'map' function, using recursive 'call'.
13#
14map = $(foreach a,$2,$(call $1,$a))
15
16# Test using a builtin; this is silly as it's simpler to do without call
17#
18my-notdir = $(call notdir,$(1))
19
20# Test using non-expanded builtins
21#
22my-foreach = $(foreach $(1),$(2),$(3))
23my-if = $(if $(1),$(2),$(3))
24
25# Test recursive invocations of call with different arguments
26#
27one = $(1) $(2) $(3)
28two = $(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#
34DEP_foo = bar baz quux
35DEP_baz = quux blarp
36rest = $(wordlist 2,$(words ${1}),${1})
37tclose = $(if $1,$(firstword $1)\
38 $(call tclose,$(sort ${DEP_$(firstword $1)} $(call rest,$1))))
39
40all: ; @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
62run_make_test(q!
63all = $1 $2 $3 $4 $5 $6 $7 $8 $9
64
65level1 = $(call all,$1,$2,$3,$4,$5)
66level2 = $(call level1,$1,$2,$3)
67level3 = $(call level2,$1,$2,$3,$4,$5)
68
69all:
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
79delete $ENV{X123};
80
81run_make_test('
82tst = $(eval export X123)
83$(call tst)
84all: ; @echo "$${X123-not set}"
85',
86 '', "\n");
87
881;
89
90### Local Variables:
91### eval: (setq whitespace-action (delq 'auto-cleanup whitespace-action))
92### End:
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette