Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a logical OR operator for the 'ifneq'?

Tags:

makefile

Is there a logical OR operator for the 'ifneq ... endif' statement?

That is, I'd not like to execute some statements if variable 'var1' or 'var2' is defined. Something like this:

ifneq ($(WNDAP660),y) OR $(WNADAP620),y))
...
endif

I've tried ifneq ($(WNDAP660),$(filter $(WNADAP620),y y)), but it is not working.

like image 301
Nachiket Jagade Avatar asked Nov 28 '11 13:11

Nachiket Jagade


People also ask

How do you write if condition in Makefile?

Syntax of ConditionalsThe text-if-true may be any lines of text, to be considered as part of the makefile if the condition is true. If the condition is false, no text is used instead. If the condition is true, text-if-true is used; otherwise, text-if-false is used instead.

What are logical operators in JavaScript?

Logical operators are used to determine the logic between variables or values.


2 Answers

Try this one:

ifeq ($(filter y,$(WNDAP660) $(WNADAP620)),)
...
endif
like image 157
Eldar Abusalimov Avatar answered Oct 23 '22 13:10

Eldar Abusalimov


Is there a logical OR operator for the 'ifneq'

NO. Posix Make is anemic. There's no logical OR for any of them. See, for example, Logical AND, OR, XOR operators inside ifeq ... endif construct condition on the GNU make mailing list. They have been requested for decades (literally).

Posix make is nearly useless, and one of the first things you usually do on a BSD system is install the GNU Make (gmake) port so you can compile libraries and programs.

If you are using GNU Make, then you have other options.

One alternative is to use shell math to simulate a circuit. For example, the following is from Crypto++'s GNUmakefile:

IS_DARWIN = $(shell uname -s | $(EGREP) -i -c "darwin")
GCC42_OR_LATER = $(shell $(CXX) -v 2>&1 | $(EGREP) -i -c "^gcc version (4\.[2-9]|[5-9])")
CLANG_COMPILER = $(shell $(CXX) --version 2>&1 | $(EGREP) -i -c "clang")

# Below, we are building a boolean circuit that says "Darwin && (GCC 4.2 || Clang)"
MULTIARCH_SUPPORT = $(shell echo $$(($(IS_DARWIN) * ($(GCC42_OR_LATER) + $(CLANG_COMPILER)))))
ifneq ($(MULTIARCH_SUPPORT),0)
  CXXFLAGS += -arch x86_64 -arch i386
else
  CXXFLAGS += -march=native
endif

When building such a circuit, use -c for grep and egrep to count hits. Then use non-0 and 0 values. That's in case something has a value of, say, 2. That's why the test above is ifneq ($(MULTIARCH_SUPPORT),0) (if not equal to 0).

Another alternative is to use GNU Make Standard Library. It adds the following operators: not, and, or, xor, nand, nor, xnor to the CVS version.

like image 36
jww Avatar answered Oct 23 '22 13:10

jww