help-make
[Top][All Lists]
Advanced

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

Re: character substitution loop and eval


From: John Graham-Cumming
Subject: Re: character substitution loop and eval
Date: Thu, 06 Jan 2005 17:26:28 -0500

On Thu, 2005-01-06 at 16:59, Dill, John wrote:
> I have a problem I want to create a list of characters to pass to a function 
> which calls subst over that list.  I want to do something like this.
> 
> my_chars:=1 2 3 4 5 6 7 8 9
> 
> my-subst=$(eval temp_variable := $1)$(foreach iter,$(my_chars),$(eval 
> temp_variable:=$(subst $(iter),,$(temp_variable))))$(temp_variable)
> 
> where my_chars could be simply $2.
> 
> I'm new to 3.80 so I'm not very familiar of the capabilities of eval.  Can I 
> store temporary state within a foreach loop?  This way I wouldn't need a lot 
> of nested subst to implement this in make.  (I can also do this with a 
> program easily enough, but I want to try to implement it within make).
> 
> Is there a way to make this kind of loop work in 3.80?

I think what you are trying to do is remove certain characters from a list.   
You can do this like this:

remove_these_characters := 1 2 3 4 5 6 7 8 9

my_subst=$(strip $(eval temp_variable := $2)$(foreach c,$1,$(eval temp_variable 
:= $(subst $c,,$(temp_variable))))$(strip $(temp_variable)))

bar := $(call my_subst,$(remove_these_characters),a1b a2c a3d drg)

If you run that Makefile then the list 'a1b a2c a3d drg' has all numbers 
removed from it and bar ends up being 'ab ac ad drg'.

John.
-- 
John Graham-Cumming

Home: http://www.jgc.org/
Work: http://www.electric-cloud.com/
POPFile: http://getpopfile.org/








reply via email to

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