help-make
[Top][All Lists]
Advanced

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

Re: call for each target within multiple targets in single rule


From: Utku Ozcan
Subject: Re: call for each target within multiple targets in single rule
Date: Fri, 9 Apr 2010 01:23:28 +0200

I think I have found the solution.

Instead of writing a rule, using $(eval) achieves the effect.

$(eval $(foreach dir,${LIB_LIST}, $(call
write_to_file,$(dir)_FILE_LIST, $(dir)_FILE_LIST)))

write_to_file gets var name as 2nd arg, and file name as 3rd arg,
which is again the variable name itself.
The rule could expand the targets, however eval iterates to achieve
the same effect.

For this, the thread "Multiple target patterns" was helpful: (
http://lists.gnu.org/archive/html/help-make/2008-06/msg00039.html )

It seems to be working.
Utku

On Fri, Apr 9, 2010 at 12:48 AM, Utku Ozcan <address@hidden> wrote:
> I have a list, which stores modified name of the variables. Each
> variable holds a list of filenames.
> I want to store each of these variables to its own separate file,
> using "one rule-multiple target" method.
>
> List of variable names, together with the variables come from a file
> "filelist.mk". This file includes following:
>
> # variable 1
> name1_lib_FILE_LIST :=
> name1_lib_FILE_LIST += name1_lib_file1.txt
> name1_lib_FILE_LIST += name1_lib_file2.txt
> ...
>
> # variable 2
> name2_lib_FILE_LIST :=
> name2_lib_FILE_LIST += name2_lib_file1.txt
> name2_lib_FILE_LIST += name2_lib_file2.txt
> ...
>
> # list of variables but their names are modified
> LIB_LIST :=  \
>  name1_lib \
>  name2_lib \
>  ...
>
>
> Now I tried following in Makefile:
>
> include filelist.mk
> write_to_file=$(strip $(shell printf "\# %s\\n" ${1} >> $2)$(foreach
> w,$($1),$(shell echo $(w) >> $2 )))
> files_list_list := $(addsuffix _FILE_LIST,${LIB_LIST})
>
> $(files_list_list):
> <tab>$(call write_to_file,LIB_LIST, $@)
>
> In the rule above, each of the multiple target set cannot call
> function "write_to_file" with its own dedicated name, ie
>
> name1_lib must call $(call write_to_file,name1_lib_LIB_LIST, $@)
> name2_lib must call $(call write_to_file,name2_lib_LIB_LIST, $@)
>
> I get only the list LIB_LIST in each file. Each target is generated
> correctly but content is thus wrong. Each file does not include the
> corresponding variable.
>
> Questions:
> 1. Does it make sense to use multiple targets? (
> http://www.gnu.org/software/make/manual/make.html#Multiple-Targets )
> 2. Where is my mistake?
>
> Cheers,
> Utku
>




reply via email to

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