:
define req
$(subst ..,__,$(dir build-$(TARGET)$(build_dir_ext)/$(1)))%.o: $(dir $1)%.cpp
mkdir -p $$(dir $$(subst ..,__,$$@))
$$(CXX) -MM $$(CXXFLAGS) $$< -MT $$(subst ..,__,$$@) > $$(patsubst %.o,%.d,$$(subst ..,__,$$@))
$$(CXX) $$(CXXFLAGS) $$< -c -o $$(subst ..,__,$$@)
endef
$(eval $(foreach x,$(OBJ),$(call req,$(x))))
make , "" , "__" ".." , , src
build
. "" , .
, ...
EDIT 1: Why replace ".."
Think of the following source tree:
./sourcepool/lib1/src/one.cpp
./sourcepool/project/build
If your Makefile is on the go. / sourcepool / project, and one of the OBJs is "../lib1/src/one.o", the Makefile should create an equivalent path in the assembly directory. That is, if ".." is used, it is impossible, because then the path is no longer built, but one depth is higher. If you replace .. with __, the result is as follows:
./sourcepool/project/build/__/lib1/src/one.o
This allows you to not copy or associate all used dirs with the local project and build a file tree.