DIRS := A B
$(foreach i, $(DIRS), $(eval DIR-$(i) := $(wildcard $(i)/*.cpp)))
$(foreach i, $(DIRS), $(eval OBJ-$(i) := $(patsubst $(i)/%.cpp, $(i)/%.o, $(DIR-$(i)))))
define _build_cmd
$(OBJ-$(1)) : $(1)/%.o : $(1)/%.cpp
g++ -c -o $@ $<
endef
$(foreach i, $(DIRS), $(eval $(call _build_cmd, $(i))))
all: $(foreach i, $(DIRS), $(OBJ-$(i)))
g++ -o a.out $^
【 在 cleaf 的大作中提到: 】
: SUBDIRS=$(shell ls -l | grep ^d | awk '{print $$9}')
: #以下同根目录下的makefile的相同代码的解释
: CUR_SOURCE=${wildcard *.cpp}
: ...................
--
FROM 119.57.115.*