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 ) in makefile


From: rakesh aggarwal
Subject: Re: Help : how to use $(or condition ) & $(and condition ) in makefile
Date: Fri, 6 Jun 2008 05:05:30 -0700 (PDT)


Hi Tim,


Thanks for your response.

But still there is some problem.
Just look the below code and its output:

Code:


A=1
B=1
$(warning A=$(A), B=$(B))
res_A  :=   $(subst 2,,$(A))
res_B  :=   $(subst 1,,$(B))

$(warning res_A=$(res_A), res_B=$(res_B))

first := $(and  $(res_A), $(res_B))

second :=  $(and  $(subst 2,,$(A)), $(subst 2,,$(B)))

third  :=  $(or  $(subst 1,,$(A)), $(subst 2,,$(B)))

$(warning first=$(first), second=$(second), third= $(third))

 

 

Output :

 

makefile:3: A=1, B=1

makefile:7: res_A=1, res_B=

makefile:15: first=, second=, third=

 

 

But, according to gmake manual:

 

$(or condition1[,condition2[,condition3...]])

The or function provides a “short-circuiting” OR operation. Each argument is expanded, in order. If an argument expands to a non-empty string the processing stops and the result of the expansion is that string. If, after all arguments are expanded, all of them are false (empty), then the result of the expansion is the empty string.

$(and condition1[,condition2[,condition3...]])

The and function provides a “short-circuiting” AND operation. Each argument is expanded, in order. If an argument expands to an empty string the processing stops and the result of the expansion is the empty string. If all arguments expand to a non-empty string then the result of the expansion is the expansion of the last argument.

 

I am not getting why it is returning empty string for all conditions.

As far as my knowledge it should return

 

first=

second = 1

third=1

 

am I correct ???????

 

I am not able to find out the reason for this response.

Can you help me in this problem ?

 

 

Thanks and Regards

Rakesh


--- On Fri, 6/6/08, Tim Murphy <address@hidden> wrote:
From: Tim Murphy <address@hidden>
Subject: Re: Help : how to use $(or condition ) & $(and condition ) in makefile
To: address@hidden
Date: Friday, June 6, 2008, 3:40 PM

Hi,

# 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:
ifneq ($(AandB),)
# do something . . . .
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:

ifneq ($(and $(call eq,$(A),2),$(call eq,$(B),4)),)
# do what you want to do when A=2 and B=4
# . . . .. . .
endif

Cheers,

Tim


2008/6/6 rakesh aggarwal <address@hidden>:
Hi sam,

Very very thanks for your valuable suggestion.

I have one debut that I am explaining through this example.

I have 2 variable (let assume A and B) which contain some value.

I want to test A==2 and B==4 using $(and condition) function.

How can I put this condition in function??

I want only different output for the situation when any of the condition is wrong (either A != 2 or B != 4) and both  are  right  (A ==2 and B==4 ).

result := $(and  condition )

$(warning   result=$(result))

Regards
Rakesh




--- On Thu, 6/5/08, Sam Ravnborg <address@hidden> wrote:
From: Sam Ravnborg <address@hidden>
Subject: Re: Help : how to use $(or condition ) & $(and condition ) in makefiles
To: "rakesh aggarwal" <address@hidden>
Cc: address@hidden
Date: Thursday, June 5, 2008, 11:28 PM

On Thu, Jun 05, 2008 at 05:36:56AM -0700, rakesh aggarwal wrote:
> Hi,

>
> I read the GNU make manual and found there are $(or condition ) and $(and
condition ) functions. ( at
http://www.gnu.org/software/make/manual/make.html#Conditional-Functions )

> But i didnt get in which format i have to put conditions in these
functions.

Notice that this is condition and not
expressions.

Sample:

havefile := $(if $(wildcard myfile.c), YES, NO)

$(warning HAVEFILE=$(HAVEFILE))


This will print
HAVEFILE=NO

if no myfile.c exist (because the $(wildcard myfile.c) expands to an empty

string

Sam


_______________________________________________
Bug-make mailing list
address@hidden
http://lists.gnu.org/mailman/listinfo/bug-make




--
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]