1*69606e3fSchristos# -*-perl-*- 2*69606e3fSchristos$description = "Test the call function.\n"; 3*69606e3fSchristos 4*69606e3fSchristos$details = "Try various uses of call and ensure they all give the correct 5*69606e3fSchristosresults.\n"; 6*69606e3fSchristos 7*69606e3fSchristosopen(MAKEFILE, "> $makefile"); 8*69606e3fSchristos 9*69606e3fSchristos# The Contents of the MAKEFILE ... 10*69606e3fSchristos 11*69606e3fSchristosprint MAKEFILE <<'EOMAKE'; 12*69606e3fSchristos# Simple, just reverse two things 13*69606e3fSchristos# 14*69606e3fSchristosreverse = $2 $1 15*69606e3fSchristos 16*69606e3fSchristos# A complex `map' function, using recursive `call'. 17*69606e3fSchristos# 18*69606e3fSchristosmap = $(foreach a,$2,$(call $1,$a)) 19*69606e3fSchristos 20*69606e3fSchristos# Test using a builtin; this is silly as it's simpler to do without call 21*69606e3fSchristos# 22*69606e3fSchristosmy-notdir = $(call notdir,$(1)) 23*69606e3fSchristos 24*69606e3fSchristos# Test using non-expanded builtins 25*69606e3fSchristos# 26*69606e3fSchristosmy-foreach = $(foreach $(1),$(2),$(3)) 27*69606e3fSchristosmy-if = $(if $(1),$(2),$(3)) 28*69606e3fSchristos 29*69606e3fSchristos# Test recursive invocations of call with different arguments 30*69606e3fSchristos# 31*69606e3fSchristosone = $(1) $(2) $(3) 32*69606e3fSchristostwo = $(call one,$(1),foo,$(2)) 33*69606e3fSchristos 34*69606e3fSchristos# Test recursion on the user-defined function. As a special case make 35*69606e3fSchristos# won't error due to this. 36*69606e3fSchristos# Implement transitive closure using $(call ...) 37*69606e3fSchristos# 38*69606e3fSchristosDEP_foo = bar baz quux 39*69606e3fSchristosDEP_baz = quux blarp 40*69606e3fSchristosrest = $(wordlist 2,$(words ${1}),${1}) 41*69606e3fSchristostclose = $(if $1,$(firstword $1) \ 42*69606e3fSchristos $(call tclose,$(sort ${DEP_$(firstword $1)} $(call rest,$1)))) 43*69606e3fSchristos 44*69606e3fSchristosall: ; @echo '$(call reverse,bar,foo)'; \ 45*69606e3fSchristos echo '$(call map,origin,MAKE reverse map)'; \ 46*69606e3fSchristos echo '$(call my-notdir,a/b c/d e/f)'; \ 47*69606e3fSchristos echo '$(call my-foreach)'; \ 48*69606e3fSchristos echo '$(call my-foreach,a,,,)'; \ 49*69606e3fSchristos echo '$(call my-if,a,b,c)'; \ 50*69606e3fSchristos echo '$(call two,bar,baz)'; \ 51*69606e3fSchristos echo '$(call tclose,foo)' 52*69606e3fSchristos 53*69606e3fSchristos 54*69606e3fSchristos 55*69606e3fSchristosEOMAKE 56*69606e3fSchristos 57*69606e3fSchristos# These won't work until/unless PR/1527 is resolved. 58*69606e3fSchristos# echo '$(call my-foreach,a,x y z,$(a)$(a))'; \ 59*69606e3fSchristos# echo '$(call my-if,,$(warning don't print this),ok)' 60*69606e3fSchristos# 61*69606e3fSchristos# $answer = "xx yy zz\nok\n"; 62*69606e3fSchristos 63*69606e3fSchristos# END of Contents of MAKEFILE 64*69606e3fSchristos 65*69606e3fSchristosclose(MAKEFILE); 66*69606e3fSchristos 67*69606e3fSchristos&run_make_with_options($makefile, "", &get_logfile); 68*69606e3fSchristos$answer = "foo bar\ndefault file file\nb d f\n\n\nb\nbar foo baz\nfoo bar baz blarp quux \n"; 69*69606e3fSchristos&compare_output($answer, &get_logfile(1)); 70*69606e3fSchristos 71*69606e3fSchristos 72*69606e3fSchristos# TEST eclipsing of arguments when invoking sub-calls 73*69606e3fSchristos 74*69606e3fSchristos$makefile2 = &get_tmpfile; 75*69606e3fSchristos 76*69606e3fSchristosopen(MAKEFILE,"> $makefile2"); 77*69606e3fSchristos 78*69606e3fSchristosprint MAKEFILE <<'EOF'; 79*69606e3fSchristos 80*69606e3fSchristosall = $1 $2 $3 $4 $5 $6 $7 $8 $9 81*69606e3fSchristos 82*69606e3fSchristoslevel1 = $(call all,$1,$2,$3,$4,$5) 83*69606e3fSchristoslevel2 = $(call level1,$1,$2,$3) 84*69606e3fSchristoslevel3 = $(call level2,$1,$2,$3,$4,$5) 85*69606e3fSchristos 86*69606e3fSchristosall: 87*69606e3fSchristos @echo $(call all,1,2,3,4,5,6,7,8,9,10,11) 88*69606e3fSchristos @echo $(call level1,1,2,3,4,5,6,7,8) 89*69606e3fSchristos @echo $(call level2,1,2,3,4,5,6,7,8) 90*69606e3fSchristos @echo $(call level3,1,2,3,4,5,6,7,8) 91*69606e3fSchristosEOF 92*69606e3fSchristos 93*69606e3fSchristosclose(MAKEFILE); 94*69606e3fSchristos 95*69606e3fSchristos&run_make_with_options($makefile2, "", &get_logfile); 96*69606e3fSchristos$answer = "1 2 3 4 5 6 7 8 9\n1 2 3 4 5\n1 2 3\n1 2 3\n"; 97*69606e3fSchristos&compare_output($answer,&get_logfile(1)); 98*69606e3fSchristos 99*69606e3fSchristos1; 100