AND && in ifeq in makefile

Hi,

Can anybody help mw how to use 2 conditinal directives in makefile (with AND=&&), so far none of my tries succedded.
Getting this warning like below. I thought that C's && will work, but alas, played with (), spaces and etc..

and I have only GNU Make 3.80

ifeq ($(VAR1),15) && ($(VAR2),32)
MOD_CFLAGS1 += -m64
endif
*** Extraneous text after `ifeq' directive

Tx all

I assume from your syntax you are talking gmake which is different than some of the default versions of make that I've come across. I had a quick read through the manual (url at end) and I don't believe that gmake supports complex expressions. I thought maybe nested if statements, given you want ANDing rather than ORing, but that seems no good too. The only way I was able to do something like you want was to 'shell out' to do the test.

Here's an example:

SHELL = /usr/bin/ksh
ifeq ($(shell [[ $(V1) == 15 && $(V2) == 16 ]] && echo true ),true)
    v2=true
else
    v2=false
endif

verify:
    @echo $(v2)

To test I ran these commands:

V2=18 V1=15 gmake verify    # should print false
V2=16 V1=15 gmake verify    # should print true

Make sure that your SHELL variable is set to a shell that supports the double bracket syntax (Korn shell and bash should both work).

GNU `make'

tx, Adama. It's bit much for me, how to make it work syntax wise, can I still do nested if.

No, I don't believe that nested ifs are supported.

This is what you need based on your original post.

SHELL = /usr/bin/ksh

ifeq ($(shell [[ $(VAR1) == 15 && $(VAR2) == 32 ]] && echo true ),true)
   MOD_CFLAGS1 += -m64
endif

Thanks, all dear friends ! It all works and after some gnu upgrade it also works with nested

ifeq ($(VAR1),15) 
   ifeq ($(VAR2),32)         MOD_CFLAGS1 += -m64
   endif
endif
## and without specifiin shell, I have it like 
-bash-3.00$ echo $SHELL
/bin/bash

1 Like