[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: eval of foreach loop of a define runs first target more than once
From: |
Utku Ozcan |
Subject: |
Re: eval of foreach loop of a define runs first target more than once |
Date: |
Mon, 24 May 2010 17:57:24 +0200 |
Sorry my message was sent to Philip only. I resent it to the mailing list.
On Mon, May 24, 2010 at 5:55 PM, Utku Ozcan <address@hidden> wrote:
> On Fri, May 21, 2010 at 8:51 PM, Philip Guenther <address@hidden> wrote:
> ...
>>> define write_list_to_file
>>> $(2):
>>> $(foreach file,$($1),$(shell echo $(file) >> $(2)))
>>> endef
>>
>> As you noticed, this function is completely broken. Consider the
>> output and side-effects of
>>
>> $(info $(call write_list_to_file foo,bar))
>>
>> Note that simply putting that line in the makefiles results in the
>> creation of the file 'bar' EVEN IF 'bar' ISN'T A MAKE TARGET! When
>> does the $(shell) function get expanded?
>>
>> Why are you using the make functions $(foreach) and $(shell) in the
>> commands for the rule and not just writing shell commands? Did you
>> first write a correct Makefile that does stuff directly without using
>> $(eval) and only factor out the code after doing that? If not, how
>> did you know what the generated Makefile rules should look like?
>>
>>
>> Philip Guenther
>>
>
> Hi guys, I am really running out of ideas. I have replaced the code in
> define with shell commands, as Philip proposed:
>
> define write_list_to_file
> $(2):
> for file in $($(1)); do \
> echo $$$$file >> $(2) ; \
> done
> endef
>
> it gave me following error:
>
> for file in a b; do echo $file >> codefile_list_CODE ; done
> codefile_list_CODE_part01:
> /bin/sh: -c: line 0: syntax error near unexpected token
> `codefile_list_CODE_part01:'
> /bin/sh: -c: line 0: `for file in a b; do echo $file >>
> codefile_list_CODE ; done codefile_list_CODE_part01:'
> gmake: *** [codefile_list_CODE] Error 2
>
> But if I encapsulate it with $(shell):
>
> define write_list_to_file
> $(2):
> $(shell \
> for file in $($(1)); do \
> echo $$file >> $(2) ; \
> done \
> )
> endef
>
> then I get following message:
>
> gmake: `codefile_list_CODE' is up to date.
>
> Where is my mistake?
>
> Thank you very much in advance.
> Utku
>