Non-recursive make: include makefile segment in loop

I have a non-recursive make file that defines helper functions that can be used to build libraries, etc.

define make-library
    # build lib from *.cpp in current dir...
endef

Each library / binary information is defined in a separate makefile segment with a name module.mkthat calls these helper functions

$(eval $(call make-library, my_lib))

The make file looks for the source tree for the makefile segments and includes

modules := $(shell find . -name module.mk | xargs echo)
include $(modules)

Problem:

I define the default set CPPFLAGSat the top of the makefile:

CPPFLAGS += -m64 -std=c++11 -Wall -Wextra -Werror -Wno-system-headers

They are selectively updated depending on the assembly option, etc.:

ifeq "$(BUILD)" "debug"
    CPPFLAGS += $(DEBUG_FLAGS)
endif

they are used for every purpose where it is required:

$(OBJ_DIR)/%.o: $(SRC_DIR)/%.cpp
    @$(CXX) $(CPPFLAGS) -I$(BASE_DIR) -I. -o $@ -c $(filter %.cpp,$^)

The problem is that sometimes I want to override CPPFLAGSin a module:

CPPFLAGS += -Wno-unused-but-set-variable
$(eval $(call make-library, my_lib))

CPPFLAGS, .

:

, $(modules) , reset CPPFLAGS . reset .

- :

$(foreach module,$(modules),$(eval \
    CPPFLAGS := DEFAULT_CPPFLAGS \
    include $module))

:

, , , , , - , , ?

:

, , module.mk LOCAL_FLAGS, make-library?

LOCAL_FLAGS := -Wno-unused-but-set-variable
$(eval $(call make-library, my_lib, $(LOCAL_FLAGS)))
+4
2

per-makefile, . / .. .

, .

, , reset module.mk.

$ cat foo/module.mk
oCPPFLAGS:=$(CPPFLAGS)
CPPFLAGS+=something local

target: CPPFLAGS:=$(CPPFLAGS)
target:
        some_cmd $(CPPFLAGS)

FOO:=$(oFOO)

, , .

$ cat Makefile
$(foreach module,$(modules),$(eval CPPFLAGS := DEFAULT_CPPFLAGS)$(eval include $(module)))
$(eval CPPFLAGS := DEFAULT_CPPFLAGS)

$ cat foo/module.mk
target: CPPFLAGS:=$(CPPFLAGS)
target:
        some_cmd $(CPPFLAGS)

- , / . , - (, ).

+1

prorab this_* CFLAGS, CFLAGS . , , this_* :

$(foreach var,$(filter this_%,$(.VARIABLES)),$(eval $(var) := ))

prorab-clear-this-vars = $(foreach var,$(filter this_%,$(.VARIABLES)),$(eval $(var) := ))

$(eval $(prorab-clear-this-vars))
0

Source: https://habr.com/ru/post/1570936/


All Articles