TRG += target target_COMPILE_SET = debug opt target_debug_CSRC = ad.c target_debug_CSRC += bd.c target_debug_CSRC += cd.c target_opt_CSRC = ao.c target_opt_CSRC += bo.c target_opt_CSRC += co.c target_debug_FLAGS0 = td_flg target_opt_FLAGS0 = to_flg target_debug_FLAGS1 = td_flg target_opt_FLAGS1 = to_flg target_MCU = mcu .PHONY: all all: target_debug target_opt define build_target $(info marker1 $(0) ** $(1) ** $(2)) ifneq ($$(strip $$($(1)_VAR1)),) $(1)_$(2)_FLAGS0 += $$($(1)_VAR1) endif $(1)_$(2)_FLAGS1 += $$($(1)_VAR1) $(1)_$(2)_TRE = $$(foreach file,$$($(1)_$(2)_CSRC:%.c=%.o),$(1)/$$(file)) $(1)_$(2): @echo P0 $(1) $(2) -- $($(1)_$(2)_CSRC) -- $$($(1)_$(2)_TRE) @echo P1 $(1)_VAR1=$$($(1)_VAR1) @echo P2 $(1)_$(2)_FLAGS0=$$($(1)_$(2)_FLAGS0) @echo P3 $(1)_$(2)_FLAGS1=$$($(1)_$(2)_FLAGS1) endef define asdrubale $(info marker0 $(0) ** $(1)) $(1)_VAR1 = -param_$$($(1)_MCU) $(foreach z,$($(1)_COMPILE_SET),$(eval $(call build_target,$(1),$(z)))) endef $(foreach t,$(TRG),$(eval $(call asdrubale,$(t))))