~ubuntu-branches/debian/sid/make-doc-non-dfsg/sid

« back to all changes in this revision

Viewing changes to tests/scripts/functions/call

  • Committer: Package Import Robot
  • Author(s): Manoj Srivastava
  • Date: 2014-05-04 18:48:47 UTC
  • mfrom: (4.1.1 experimental)
  • Revision ID: package-import@ubuntu.com-20140504184847-50zxi1b08m22ehle
Tags: 4.0-2
Move to usntable, since the make binary package has been uploaded
there. No changes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#                                                                    -*-perl-*-
 
2
$description = "Test the call function.\n";
 
3
 
 
4
$details = "Try various uses of call and ensure they all give the correct
 
5
results.\n";
 
6
 
 
7
open(MAKEFILE, "> $makefile");
 
8
 
 
9
# The Contents of the MAKEFILE ...
 
10
 
 
11
print MAKEFILE <<'EOMAKE';
 
12
# Simple, just reverse two things
 
13
#
 
14
reverse = $2 $1
 
15
 
 
16
# A complex 'map' function, using recursive 'call'.
 
17
#
 
18
map = $(foreach a,$2,$(call $1,$a))
 
19
 
 
20
# Test using a builtin; this is silly as it's simpler to do without call
 
21
#
 
22
my-notdir = $(call notdir,$(1))
 
23
 
 
24
# Test using non-expanded builtins
 
25
#
 
26
my-foreach = $(foreach $(1),$(2),$(3))
 
27
my-if      = $(if $(1),$(2),$(3))
 
28
 
 
29
# Test recursive invocations of call with different arguments
 
30
#
 
31
one = $(1) $(2) $(3)
 
32
two = $(call one,$(1),foo,$(2))
 
33
 
 
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 ...)
 
37
#
 
38
DEP_foo = bar baz quux
 
39
DEP_baz = quux blarp
 
40
rest = $(wordlist 2,$(words ${1}),${1})
 
41
tclose = $(if $1,$(firstword $1)\
 
42
                $(call tclose,$(sort ${DEP_$(firstword $1)} $(call rest,$1))))
 
43
 
 
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)'
 
52
 
 
53
 
 
54
 
 
55
EOMAKE
 
56
 
 
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)'
 
60
#
 
61
# $answer = "xx yy zz\nok\n";
 
62
 
 
63
# END of Contents of MAKEFILE
 
64
 
 
65
close(MAKEFILE);
 
66
 
 
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));
 
70
 
 
71
 
 
72
# TEST eclipsing of arguments when invoking sub-calls
 
73
 
 
74
$makefile2 = &get_tmpfile;
 
75
 
 
76
open(MAKEFILE,"> $makefile2");
 
77
 
 
78
print MAKEFILE <<'EOF';
 
79
 
 
80
all = $1 $2 $3 $4 $5 $6 $7 $8 $9
 
81
 
 
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)
 
85
 
 
86
all:
 
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)
 
91
EOF
 
92
 
 
93
close(MAKEFILE);
 
94
 
 
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));
 
98
 
 
99
# Ensure that variables are defined in global scope even in a $(call ...)
 
100
 
 
101
delete $ENV{X123};
 
102
 
 
103
run_make_test('
 
104
tst = $(eval export X123)
 
105
$(call tst)
 
106
all: ; @echo "$${X123-not set}"
 
107
',
 
108
              '', "\n");
 
109
 
 
110
1;