tags:

views:

312

answers:

4
+2  Q: 

Debugging gnu make

Is there a command line way in make to find out which of the prerequisites of a target is not update?

Thanks.

+6  A: 
make -d

should give you more than enough information to debug your makefile.

Be warned: it will take some time and effort to analyze the output but loading the output into your favorite editor and doing searches will assist a lot.

You can greatly reduce the amount of debugging output if you specify the specific target you're interested in. So if you're only interested in the dodgy target, instead of just make -d which may make a hundred different things, try:

make clean
make -d dodgy

(assuming you have a clean target of course).

The make --debug is identical to make -d but you can also specify:

make --debug=FLAGS

where flags can be:

  • a for all debugging (same as make -d and make --debug).
  • b for basic debugging.
  • v for slightly more verbose basic debugging.
  • i for implicit rules.
  • j for invocation information.
  • m for information during makefile remakes.

It looks like make --debug=b is the best option for what you need, as shown in the following transcript:

pax@paxbox> cat makefile
c:a b
    touch c

pax@paxbox> touch a b ; make
touch c

pax@paxbox> make
make: 'c' is up to date.

pax@paxbox> touch a ; make --debug=b
GNU Make 3.81
Copyright (C) 2006  Free Software Foundation, Inc. Blah, blah, blah.
Reading makefiles...
Updating goal targets....
 Prerequisite 'a' is newer than target 'c'.
Must remake target 'c'.
touch c
Successfully remade target file 'c'.
paxdiablo
Another suggestion that if you want to get rid of built-in implicit rules, you may use `-r` flag alongside mere `-d`.
Pavel Shved
A: 

Are you looking for Make's "dry run"? It will print out what make is doing without actually doing so, allowing you to see what happens.

The flag is -n, use it like make -n.

LiraNuna
+3  A: 

Your question is a little unclear. If you want to see which prerequisite files have not been modified recently, use ls -l to see their modification time. If you want to see what make is doing, try this:

# Make will announce when it is making this target, and why.
sometarget: preq1 preq2 preq3
    @echo making $@
    @echo The following preqs are newer than the target: $?
    do_things
Beta
I was going to suggest $? as well
just somebody
Not really a command-line solution but useful nonetheless. You could possibly make it command-line based by only doing the echos only if an env-var is set.
paxdiablo
A: 

There's also GNU make with a debugger and better trace/error output http://bashdb.sf.net/remake screencast: http://showmedo.com/videotutorials/video?name=linuxBernsteinMakeDebug1&fromSeriesID=40

rocky