I've inherited a major mess of a makefile network that was itself inherited from another project, with makefiles included all over the place. I'm trying to make a simple change without gutting the whole thing (tempting though that is, I just don't have the time right now).

Is there any way to coax a full makefile out of gmake, i.e., with all the included files already included? I know how to get the database dumped, but that's just about as hard to follow with all the extraneous junk that gets loaded in.

  • I wonder whether this makes sense in general, since makefiles can be generated dynamically (from the contents) then included. – vinc17 Jul 11 '14 at 20:22
  • Good point, but they don't have to be generated dynamically (such as the "major mess of a makefile network" mentioned above), plus it can still come in handy to find where an explicit target might be hiding. – Joe Sewell Jul 14 '14 at 15:54

Remake has some very interesting debug output.


Not sure if that works recursively, but what about something like:

strace -e trace=open make | grep -i makefile
  • You should add -f to strace for following childs on fork ... – maxschlepzig Nov 26 '14 at 15:37

It seems that make doesn't provide any easy way to do that, but perhaps it will be sufficient for you to grep all the include directives from all makefiles like this:

find . -iname 'Makefile' -print0 | xargs -0 grep '^include'
  • Nice try, but it doesn't give me the full picture, as it doesn't show me what the first target in the mess is. It also doesn't take into account nested includes, especially when they named no include file 'Makefile' or any standard equivalent, and they threw them all over the directory tree. – Joe Sewell Jul 16 '14 at 20:11
  • Then I don't know an easy way to do that. It seems you are a programmer, so perhaps a suitable way for you is to modify the source code of the make and add a message which is printed when an include directive is processed. – Dmitry Jul 16 '14 at 20:22

What you're looking for is an equivalent of cc -E for make. I'm not aware of such an equivalent. Using external tools will help in many, but not all cases, due to secondary expansion.

But maybe this might get you one step closer. At the end of the initial Makefile, add this rule:

.PHONY: printMakefiles
        echo $(MAKEFILE_LIST)

You can now find out which Makefiles were included by running

make printMakefiles

Please note that this is not 100% reliable, as there could be conditional include.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.