-${DEPSDIR}%.d: ${SRCSDIR}%.cpp | ${DEPSBLDDIRS}
- ${Q1}echo "DEP: $@"
- ${Q2}${CXX} -MM ${CXXFLAGS} $< | sed 's,\(^.*\):,${OBJSDIR}\1 $@:,' > $@
+# be clever and escape the / chars in file paths
+# DON'T simply use another sed delimiter or it can't appear in the file paths
+${DEPSDIR}%.d: ${SRCSDIR}%.cpp | $$(dir $$@)
+ ${Q1}${PRNTFMT} "DEP" "$@"
+ ${Q2}${CXX} -MM ${CXXFLAGS} $< -I "${INCDIRS}" | \
+ sed 's/\(^.*\):/$(subst /,\/,${OBJSDIR}\1 $@):/' > $@