SOURCE_DIR := . .
BINARY_DIR := ./out .
source-dir-to-binary-dir = $(addprefix $(BINARY_DIR)/, \ .
$(patsubst $(SOURCE_DIR)/%,%,$1)) .
source-to-dependence = $(call source-dir-to-binary-dir, \ .
$(subst .c,.d,$(filter %.c,$1))) .
sources := src/main.c src/sub.c .
dependencies = $(call source-to-dependence,$(sources)) .
include $(dependencies) .
define create-one-dependency .
$2: $1 .
@$(GCC) -MM $(CFLAGS) $< | \ .
sed 's,\($(notdir $*)\.o\) *:,$(dir $@)\1 $@: ,' > $@.tmp .
@$(MV) $@.tmp $@ .
@echo create $@ ... .
endef .
define dependencies-rules .
$(foreach s,$(sources),$(call create-one-dependency,$s, \ .
$(call source-to-dependence, $s))) .
endef .
$(eval $(call dependencies-rules)) .
以上是Makefile代码~~ .
出问题了, .
make[1]:***没有规则创建out/src/main.d .
纳闷阿郁闷阿~~半天都没弄明白 . |