help-make
[Top][All Lists]
Advanced

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

Re: variable parameter list


From: Luke Shumaker
Subject: Re: variable parameter list
Date: Fri, 12 Nov 2010 12:20:07 -0500

On Wed, 2010-11-10 at 14:55 +0100, Warlich, Christof wrote:
> Hi,
> 
> consider this makefile:
> 
> .PHONY: all
> all: sorted.tgt header.tgt reverse.tgt footer.tgt
> # The lines below are supposed to do this:
> #sorted.tgt: list1.lst list2.lst
> # cat $^ | sort >$@
> #header.tgt: list1.lst list2.lst list3.lst
> # cat $^ | head >$@
> #reverse.tgt: list1.lst
> # cat $^ | tac >$@
> #footer.tgt: list1.lst list2.lst list3.lst list4.lst list5.lst list6.lst 
> list7.lst list8.lst
> # cat $^ | tac >$@
> define FILTER_RULE
> ${2}: ${3} ${4} ${5} ${6} ${7} ${8} ${9} ${10}
>  cat $$^ | ${1} >$$@
> endef
> $(eval $(call FILTER_RULE, sort, sorted.tgt, list1.lst, list2.lst))
> $(eval $(call FILTER_RULE, head -n1, header.tgt, list1.lst, list2.lst, 
> list3.lst))
> $(eval $(call FILTER_RULE, tac, reverse.tgt, list1.lst))
> $(eval $(call FILTER_RULE, tail -n1, footer.tgt, list1.lst, list2.lst, 
> list3.lst, list4.lst, list5.lst, list6.lst, list7.lst, list8.lst))
> 
> Is there a way to pass an arbitrary number of positional parameters to my 
> FILTER_RULE function?
> I certainly could add ${11} ${12} ... to the dependency list, but that 
> doesn't exatly look elegant. Is there
> a better, i.e. more general way to do this? I think that foreach could be my 
> friend, but I just don't
> know how to get hold of the entire list of positional parameters.
> 
> Thanks for any help,
> 
> Christof

You don't need to break the list into separate parameters, you can just
feed it the dependency list as just ${3}:

define FILTER_RULE
${2}: ${3}
        cat $$^ | ${1} >$$@
endef
$(eval $(call FILTER_RULE, sort, sorted.tgt, list1.lst list2.lst))
$(eval $(call FILTER_RULE, head -n1, header.tgt, list1.lst list2.lst list3.lst))
$(eval $(call FILTER_RULE, tac, reverse.tgt, list1.lst))
$(eval $(call FILTER_RULE, tail -n1, footer.tgt, list1.lst list2.lst list3.lst 
list4.lst list5.lst list6.lst list7.lst list8.lst))

-- 
~ LukeShu
http://lukeshu.ath.cx/




reply via email to

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