help-make
[Top][All Lists]
Advanced

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

Re: Question regarding variables


From: John Graham-Cumming
Subject: Re: Question regarding variables
Date: Thu, 30 Jun 2005 10:14:02 -0400

On Thu, 2005-06-30 at 12:06 +0530, Bhaskar G wrote:
> I would like to know if there is macro that stores list of all the
> existing variables. 

Yes there is, it's called .VARIABLES.  

> My requirement is as follows. I have a set of variables defined
> currently which starts with _BG%. 
> I need to change these variables to begin with _SP% and also need to
> support _BG% for sometime. 
> 
> I know that I can individually look for  variables and conditionally
> assign it as follows 
> _SPTMP ?= _BGTMP 
> 
> Can I handle this using a foreach command in make easily? without
> individual assignments. 

Yes, you can with GNU Make 3.80 or above like this:

    FOO1 = foo1
    FOO2 = foo2

    $(foreach a,$(.VARIABLES),$(if $(patsubst FOO%,,$a),,$(eval BAR
    $(patsubst FOO%,%,$a) = $$($a))))

    all:
        @echo $(BAR1) $(BAR2)

Which is the same as doing:

    FOO1 = bg1
    FOO2 = bg2

    BAR1 = $(FOO1)
    BAR2 = $(FOO2)

    all:
        @echo $(BAR1) $(BAR2)

John.
-- 
John Graham-Cumming

Home: http://www.jgc.org/
Work: http://www.electric-cloud.com/
POPFile: http://getpopfile.org/
GNU Make Standard Library: http://gmsl.sf.net/






reply via email to

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