18

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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Nachiket Jagade
  • 255
  • 1
  • 3
  • 12
  • 1
    You probably want an AND rather than an OR, don't you? If you wrote `y != WNDAP660 || y != WNADAP620`, then at least one and possibly both alternatives will be true, so the action will always be taken. – Jonathan Leffler Nov 28 '11 at 15:27
  • Possible duplicate of [Makefile ifeq logical or](http://stackoverflow.com/questions/7656425/makefile-ifeq-logical-or) – Ciro Santilli OurBigBook.com Jun 24 '16 at 16:56
  • Older duplicate: *[Complex conditions check in Makefile](http://stackoverflow.com/questions/5584872/complex-conditions-check-in-makefile)*. – Peter Mortensen Jun 27 '16 at 11:09

4 Answers4

11

Try this one:

ifeq ($(filter y,$(WNDAP660) $(WNADAP620)),)
...
endif
Eldar Abusalimov
  • 24,387
  • 4
  • 67
  • 71
4

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.

jww
  • 97,681
  • 90
  • 411
  • 885
3

Crude but effective:

ifneq ($(WNDAP660),y) 
 ifneq ($(WNADAP620),y)
 ...
 endif
endif
Beta
  • 96,650
  • 16
  • 149
  • 150
-2

I've test the following code, which works well

ifeq ($(var1),value1) or ($(var2), value2)
   #do something here
endif
kathy zhou
  • 62
  • 3