Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

gmake ifeq and complex boolean expression

69 views
Skip to first unread message

Noob

unread,
Nov 19, 2009, 11:50:51 AM11/19/09
to
Hello,

(I'm using gmake.)

Consider the following code.

ifeq $FOO 1
CFLAGS += -DBAR
endif

ifeq $FOO 2
CFLAGS += -DBAR
endif

ifeq $FOO 3
CFLAGS += -DBAR
endif

Is there a way to collapse the three separate tests into an OR
expression? Something like

if FOO==1 || FOO==2 || FOO==3
CFLAGS += -DBAR
endif

Regards.

Ben Bacarisse

unread,
Nov 19, 2009, 12:14:38 PM11/19/09
to
Noob <ro...@127.0.0.1> writes:

As you know, not like that. You /could/ do:

ifneq (,$findstring($FOO,1 2 3))

but that does not scale well.

--
Ben.

Rainer Weikusat

unread,
Nov 19, 2009, 12:22:55 PM11/19/09
to
Noob <ro...@127.0.0.1> writes:
> Consider the following code.
>
> ifeq $FOO 1
> CFLAGS += -DBAR
> endif
>
> ifeq $FOO 2
> CFLAGS += -DBAR
> endif
>
> ifeq $FOO 3
> CFLAGS += -DBAR
> endif
>
> Is there a way to collapse the three separate tests into an OR
> expression? Something like
>
> if FOO==1 || FOO==2 || FOO==3
> CFLAGS += -DBAR
> endif

One possiblity would be to use the shell. Untested example:

ifeq $(shell test $(FOO) = 1 -o $(FOO) = 2 -o $(FOO) = 2 && echo 1) 1
CFLAGS += -DBAR
endif

Måns Rullgård

unread,
Nov 19, 2009, 1:17:24 PM11/19/09
to
Rainer Weikusat <rwei...@mssgmbh.com> writes:

FOO = ; rm -rf /

Be careful with the shell.

--
M�ns Rullg�rd
ma...@mansr.com

0 new messages