When a project depends on some other project which has its own makefile, recursive make is used like this:
LIBDIR := path/to/lib
LIBNAME := library.a
LIBPATH := $(LIBDIR)/$(LIBNAME)
$(LIBPATH):
$(MAKE) -C $(LIBDIR) $(LIBNAME)
However the obvious problem with this is that make is unable to determine the dependencies of the $(LIBPATH) because it's defined in the recursive makefile in $(LIBDIR).
What I'm currently doing is using a .PHONY target to force the check if the sub-project needs rebuilding:
$(LIBPATH): always_build
$(MAKE) -C $(LIBDIR) $(LIBNAME)
.PHONY: always_build
While this allow me to trigger rebuild when it needed it still needs to walk through a lot of directories and invoke make a lot of times, just to find out nothing needs to be done.
Is there a way to get the dependencies out of the sub-makefile so I can add them as a dependencies of the $(LIBPATH) so the sub-makefile is only invoked when it really need to be invoked?