bug-make
[Top][All Lists]
Advanced

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

Re: GNU make: Please give an example for the 'if' function (chapter 8 .5


From: Sam Ravnborg
Subject: Re: GNU make: Please give an example for the 'if' function (chapter 8 .5 of 'make.html')
Date: Tue, 23 Sep 2003 22:56:49 +0200
User-agent: Mutt/1.4.1i

On Tue, Sep 23, 2003 at 02:42:36PM +0200, Haeusler Reinhard wrote:
> 
> I wanted to set a variable depending on another variable to different
> values.

You need to use a few tricks to do this.
I have rewritten the code you provided:
> VAR2 = $(if ??? $(VAR1), S1, s, $(if ??? $(VAR1), M, m))  # ??? means: don't

VAR2 := $(if $(filter S1,$(VAR1)),s)
VAR2 := $(if $(filter M, $(VAR1)),m,$(VAR2))

So what happens here:

The expression $(filter S1,$(VAR1)) result in 'S1' when VAR1 equals S1.
Therefore $(if select the first part, which is s.
The second line have $(VAR2) in the else clause to avoid overwriting the 
previously
assigned value.

You can use filter-out, filter, patsubst to obtain the same functionality.

HTH,
        Sam




reply via email to

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