Automatic Variables in Conditional Expression Tests: GNU Make

I'm kinda stuck here. We have two makefiles (a requirement that I cannot change)

  • defs.mk: contains the names of the source files and their additional flag compilation (except for standard flags), for example:
C_FILES = c / src / main / rule_main.c
rule_main_OPTIONAL_FLAG = + w127
rule_main_DEBUG = TRUE
  • Makefile: It contains all the rules.

Now I want to add a tool so that I can define flags for specific files (and an additional debug flag for a specific file) as in:

CUSTOM_DEBUG_FLAG = $($(basename $(notdir $@))_DEBUG) ## rule_main_DEBUG macro from defs.mk
ifeq ($(CUSTOM_DEBUG_FLAG),TRUE)
  do something
endif

But this does not work, because the extension of automatic variables is not supported in conditional expressions. Is there any other way to do this?

+5
source share
1 answer

:

SPECIFIC_FLAGS=$(if $(findstring $(CUSTOM_FLAG),TRUE),$(IF_TRUE),$(IF_FALSE))

, :

debug_defs=$(if $(findstring $(1),file1 file2),-DDEBUG,-DNDEBUG)

%.o: src/$$(notdir %).c
    @cc -c $(CFLAGS) $(call debug_defs,$(notdir $(basename $@))
+5

All Articles