bug-make
[Top][All Lists]
Advanced

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

Re: Help : how to use $(or condition ) & $(and condition ) inmakefile


From: Tim Murphy
Subject: Re: Help : how to use $(or condition ) & $(and condition ) inmakefile
Date: Tue, 17 Jun 2008 18:36:07 +0100

Yup, that's why the eq macro one is better:

make -f and.mk A=22 B=44
Crude AND Demo:
TRUE: A is 2, B is 4
Macro-based AND Demo:
FALSE: A is 22, B is 44

The crude one fails because as you noticed, it considers 2, 22 and 222  to all be the same.

That's why the macro also reverses the subst and tries to subst 22 into 2 which obviously catches the problem:

   $(if $(1:$(2)=),,$(if $(2:$(1)=),,T))

.... note the second $(if)

I am not sure about eq with lists, though.  Perhaps it has some problem there?

Cheers,

Tim

2008/6/17 Martin Dorey <address@hidden>:

Try make -f and.mk A=22 B=44.

 


From: bug-make-bounces+mdorey=bluearc.com@gnu.org [mailto:bug-make-bounces+mdorey=bluearc.com@gnu.org] On Behalf Of Tim Murphy
Sent: Tuesday, June 17, 2008 09:31


To: address@hidden
Subject: Re: Help : how to use $(or condition ) & $(and condition ) inmakefile

 

Hi,



I have amended an example of how to use $(and) that I posted earlier for Rakesh.  I have tested this on Linux with make 3.81.

It shows a crude way and a slightly more sophisticated way to use $(and) in an if statement to determine if two variables have equal values:

A=2
B=4

# do "equal" by seeing if a subst returns the empty string:
A_is_2:=$(if $(subst 2,,$(A)),,T)
B_is_4:=$(if $(subst 4,,$(B)),,T)

AandB:=$(and $(A_is_2),$(B_is_4))

# then you could do something based on this:
$(info Crude AND Demo: )
ifneq ($(AandB),)
$(info TRUE: A is 2, B is 4)
else
$(info FALSE: A is $(A), B is $(B))
endif


# One could make it look nicer by making an equals macro:
define eq
$(if $(1:$(2)=),,$(if $(2:$(1)=),,T))
endef

# which you could use as follows:

$(info Macro-based AND Demo: )
ifneq ($(and $(call eq,$(A),2),$(call eq,$(B),4)),)
$(info TRUE: A is 2, B is 4)
# do what you want to do when A=2 and B=4
else
$(info FALSE: A is $(A), B is $(B))
endif



The output looks like this:


address@hidden base]make -f and.mk A=1 B=5
Crude AND Demo:
FALSE: A is 1, B is 5
Macro-based AND Demo:
FALSE: A is 1, B is 5
make: *** No targets.  Stop.

 


address@hidden base]make -f and.mk A=2 B=4
Crude AND Demo:
TRUE: A is 2, B is 4
Macro-based AND Demo:
TRUE: A is 2, B is 4
make: *** No targets.  Stop.

 


address@hidden base]make -f and.mk A=2 B=3
Crude AND Demo:
FALSE: A is 2, B is 3
Macro-based AND Demo:
FALSE: A is 2, B is 3
make: *** No targets.  Stop.

 

2008/6/6 Paul Smith <address@hidden>:

On Fri, 2008-06-06 at 05:05 -0700, rakesh aggarwal wrote:
> But still there is some problem.

I haven't looked at your example.

But, the very first thing to check is the version of GNU make you're
using (make --version).  If it's not 3.81, then the manual you're
reading is not the right one for the version of GNU make you're using.

--
-------------------------------------------------------------------------------
 Paul D. Smith <address@hidden>          Find some GNU make tips at:
 http://www.gnu.org                      http://make.mad-scientist.us
 "Please remain calm...I may be mad, but I am a professional." --Mad Scientist




--
You could help some brave and decent people to have access to uncensored news by making a donation at:

http://www.thezimbabwean.co.uk/




--
You could help some brave and decent people to have access to uncensored news by making a donation at:

http://www.thezimbabwean.co.uk/
reply via email to

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