I have a non-recursive make file that defines helper functions that can be used to build libraries, etc.
define make-library
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)))