Question

Using gmake v3.80, how can I create a rule that ORs together two things. I'm starting with this code:

ifeq "$(BUILD_ARCH)" "lnx86_22"
TEST_ARCH := i86
endif
ifeq "$(BUILD_ARCH)" "linux_24_i86"
TEST_ARCH := i86
endif

And would like to combine the two ifeq(s) into a single if that ORs the two conditions together, perhaps something like this?

ifeq "$(BUILD_ARCH)" "lnx86_22" OR "$(BUILD_ARCH)" "linux_24_i86"
TEST_ARCH := i86
endif

What is the actual syntax that would allow me to do this?

Was it helpful?

Solution

You can use $(filter ...) for that. Like this:

ifneq (,$(filter $(BUILD_ARCH),lnx86_22 linux_24_i86))
TEST_ARCH := i86
endif

Another option would be to use constructed variable names:

lnx86_22_ARCH :=     i86
linux_24_i86_ARCH := i86
    ...

TEST_ARCH := $($(BUILD_ARCH)_ARCH)

ifeq (,$(TEST_ARCH))
$(error Failed, unknown arch $(BUILD_ARCH))
Failed, unknown arch $(BUILD_ARCH)
endif

If you are able to upgrade to newer versions of GNU make there are other options available.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top