@josh You want to do this for a specific invocation of a makefile, or statically?
The latter seems quite hard to do reliably, even if you assume limited logic triggering the recursion.
If the former, the infrastructure for tools like https://github.com/rizsotto/Bear or scan-build could be helpful?
Depending on what dependencies you're looking for, it could also be worth to look at compiler/linker generated dynamic dependencies.
@josh Similar to the longstanding support in compilers (via -M -MP) linkers recently-ish got support for emitting those dependencies via --dependency-file=.
Of course using just the generated dependencies will often miss a lot of dependencies just in the makefile...
@josh On second thought, depending on the build definition, just using make -s -p might do the trick, with a bit of parsing of the output? Dealing with targets that print output even with -s could be a bit annoying.