I have a Makefile with 2 ifdef conditions that perform same action when that particular config is selected.
#ifdef A
//perform C
#endif /* A */
#ifdef B
//perform C
#endif /* B */
#ifdef A || B
//perform C
#endif
Last code block is not working. What is the right way to execute it in Makefile?
asked Mar 7, 2022 at 7:32
qwerty
1651 gold badge2 silver badges10 bronze badges
2 Answers 2
#ifdef and #endif are not make conditionals. You probably want:
ifdef A
# whatever if make variable A is defined
AB := defined
endif
ifdef B
# whatever if make variable B is defined
AB := defined
endif
ifeq ($(AB),defined)
# whatever if the make variable A or B is defined
endif
Note that ifdef A is not the same as ifneq ($(A),). So, if you want to test these variables not for definition but for emptiness, you probably want:
ifneq ($(A),)
# whatever if the value of make variable A is non-empty
endif
ifneq ($(B),)
# whatever if the value of make variable B is non-empty
endif
ifneq ($(A)$(B),)
# whatever if the value of make variable A or B is non-empty
endif
answered Mar 7, 2022 at 9:36
Renaud Pacalet
30.8k3 gold badges42 silver badges60 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
Here's one way to do it using a variant of the technique I proposed in a comment:
# De Morgan's Law: (!a && !b) == !(a || b)
ifndef A
ifndef B
NEITHER_A_NOR_B_DEFINED :=
endif
endif
ifndef NEITHER_A_NOR_B_DEFINED
# Perform C
endif
answered Mar 7, 2022 at 11:54
Andreas
5,3334 gold badges23 silver badges45 bronze badges
Comments
Explore related questions
See similar questions with these tags.
#are comments. Should probably fix that.undefineit in nestedifndef A/ifndef B, then follow up with aifdef PERFORM_Cthat performs C. Not great, just my 2 cents.