main shinobi / tests / mk / gnu / functions / call / t001 / mk
 1
 2# Simple, just reverse two things
 3#
 4reverse = $2 $1
 5
 6# A complex 'map' function, using recursive 'call'.
 7#
 8map = $(foreach a,$2,$(call $1,$a))
 9
10# Test using a builtin; this is silly as it's simpler to do without call
11#
12my-notdir = $(call notdir,$(1))
13
14# Test using non-expanded builtins
15#
16my-foreach = $(foreach $(1),$(2),$(3))
17my-if      = $(if $(1),$(2),$(3))
18
19# Test recursive invocations of call with different arguments
20#
21one = $(1) $(2) $(3)
22two = $(call one,$(1),foo,$(2))
23
24# Test recursion on the user-defined function.  As a special case make
25# won't error due to this.
26# Implement transitive closure using $(call ...)
27#
28DEP_foo = bar baz quux
29DEP_baz = quux blarp
30rest = $(wordlist 2,$(words ${1}),${1})
31tclose = $(if $1,$(firstword $1)\
32		$(call tclose,$(sort ${DEP_$(firstword $1)} $(call rest,$1))))
33
34all: ; @echo '$(call reverse,bar,foo)'; \
35        echo '$(call map,origin,MAKE reverse map)'; \
36        echo '$(call my-notdir,a/b   c/d      e/f)'; \
37        echo '$(call my-foreach)'; \
38        echo '$(call my-foreach,a,,,)'; \
39        echo '$(call my-if,a,b,c)'; \
40        echo '$(call two,bar,baz)'; \
41	echo '$(call tclose,foo)';