MAKEFLAGS = --no-builtin-rules ifdef MKLIB_C_ENDPOINT $(error Cannot include two endpoint files. Already included $(MKLIB_C_ENDPOINT)) endif MKLIB_C_ENDPOINT := Executable.mk # ------------------------------------------------------------------ # Stuff common to makefiles that produce executables # ------------------------------------------------------------------ IMAGE_NAME = $(PROGRAM_NAME) MKLIB_C_PATH ?= $(error The 'MKLIB_C_PATH' variable needs to be set) include $(MKLIB_C_PATH)/Common.mk IMAGE_FILE = $(IMAGE_DIR)/$(IMAGE_NAME)$(_exe) LINKER_LIBS += $(EXTRA_LIBS) LINKER_DIRS += $(EXTRA_DIRS) LINKER ?= $(TOOL_BASE)g++ LINKER_PRE_OPTIONS = $(LINKER_DIRS:%=-L%) LINKER_POST_OPTIONS = $(LINKER_LIBS:%=-l%) $(LDFLAGS) define INTERNAL_LIB_TEMPLATE .PHONY: lib-$(1) # Make the library file depend on the phony target $$($(1)_LIB_BASE)/$$($(1)_LIB_REL): force # -- $($(1)_LIB_PRETTY) -- $(p1)$$(MAKE) -C $$($(1)_LIB_BASE) -f $$($(1)_LIB_MK) $$($(1)_LIB_REL) # The phony target is the one that triggers the recursive call to $(MAKE) LINKER_DIRS += $$(dir $$($(1)_LIB_BASE)/$$($(1)_LIB_REL)) LINKER_LIBS += $(1) INTERNAL_LIB_FILES += $$($(1)_LIB_BASE)/$$($(1)_LIB_REL) endef force: $(foreach internal_lib,$(INTERNAL_LIBS),$(eval $(call INTERNAL_LIB_TEMPLATE,$(internal_lib)))) image: $(IMAGE_FILE) $(IMAGE_FILE): $(OBJ_FILES) $(INTERNAL_LIB_FILES) # Linking $(notdir $@) $(p1)$(LINKER) $(LINKER_PRE_OPTIONS) -o $@ $(OBJ_FILES) $(LINKER_POST_OPTIONS)