help-make
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Using nested $(foreach) built-in commands.


From: Gary Allan Howard
Subject: Using nested $(foreach) built-in commands.
Date: Sat, 1 Dec 2007 15:35:07 -0800

Hello,

I do not understand the behavior of line #8 in the numbers.mak makefile I have attached. I am attempting to write a nested foreach loop. Both loops iterate correctly but the output is not what I expected.

I have attached the 34 line makefile I am testing with. I have also attached the report output. Targets test0 and test1 work as I expected. Target 2 produced output I do not understand.

I am using GNU 3.81 on Windows XP in a Cygwin environment. My Mac is still at GNU 3.80 (darn).

I used make -f numbers.mak test2 to produce all the results. I used the pr command to format the report included in the email

I would appreciate it if someone could explain to me why my desired- loop iterates correctly but does not properly expand $($i).

Thank you.

Gary Howard

Formatted output note:  DL - desired-output; IL - inner-loop



Dec  1 14:44 2007 numbers.mak Page 1

 1:tens := 1 2 3
 2:units:= 6 7 8 9
 3:
 4:header = $(info ==========)$(info $@: started)
 5:
 6:footer = echo "$@: completed"
 7:
8:desired-loop = $(foreach $i,$1,$(foreach $j,$2,$(info --> DL: $ ($i)$($j))))
 9:
10:outer-loop = $(foreach $i,$1,$(call inner-loop,$($i),$2))
11:
12:inner-loop = $(foreach $i,$2,$(info --> IL: $1$($i)))
13:
14:.PHONY : test0
15:test0:
16:     @ $(header)
17:     @ $(info -> tens:)
18:     @ $(call inner-loop,t,$(tens))
19:
20:     @ $(info -> units:)
21:     @ $(call inner-loop,u,$(units))
22:     @ $(footer)
23:
24:.PHONY : test1
25:test1: test0
26:     @ $(header)
27:     @ $(call outer-loop,$(tens),$(units))
28:     @ $(footer)
29:
30:.PHONY : test2
31:test2: test1
32:     @ $(header)
33:     @ $(call desired-loop,$(tens),$(units))
34:     @ $(footer)


Dec  1 15:00 2007 build.log Page 1
 1:==========
 2:test0: started
 3:-> tens:
 4:--> IL: t1
 5:--> IL: t2
 6:--> IL: t3
 7:-> units:
 8:--> IL: u6
 9:--> IL: u7
10:--> IL: u8
11:--> IL: u9
12:test0: completed
13:==========
14:test1: started
15:--> IL: 16
16:--> IL: 17
17:--> IL: 18
18:--> IL: 19
19:--> IL: 26
20:--> IL: 27
21:--> IL: 28
22:--> IL: 29
23:--> IL: 36
24:--> IL: 37
25:--> IL: 38
26:--> IL: 39
27:test1: completed
28:==========
29:test2: started
30:--> DL: 66
31:--> DL: 77
32:--> DL: 88
33:--> DL: 99
34:--> DL: 66
35:--> DL: 77
36:--> DL: 88
37:--> DL: 99
38:--> DL: 66
39:--> DL: 77
40:--> DL: 88
41:--> DL: 99
42:test2: completed























reply via email to

[Prev in Thread] Current Thread [Next in Thread]