Next: , Previous: , Up: Sample Sessions   [Contents][Index]


1.1.2 Sample GNU Remake Trace Sessions

Okay so now that we know what not to do, lets delve into things may be more helpful.

There are variants of the --debug command option that provide shorter and more-interesting information. One is called “basic” tracing. Another is the --just-print option.

Again here’s the sample Makefile:

1: # Makefile to show off tracing
2: .PHONY: all
3: all: foo
4:
5: foo:
6: 	@case $(MAKE) in \
7: 	*/remake|remake) echo "Enlightended!";; \
8: 	*/make|make) echo "This is what most folks use.";; \
9: 	esac
10: 	@bogus-command

In an unpatched GNU Make version 3.81 (and earlier) GNU Make, --just-print gives this:

$ make –just-print -f test1.mk
case make in \
*/remake|remake) echo "Enlightended!";; \
*/make|make) echo "This is what most folks use.";; \
esac
This is what most folks use.
bogus-command

Well, not much different from the original Makefile, except that information about where this gets run from is curiously missing. If there had been several targets that had commands, from the output it would not be possible to determine which command was associated with which target.

Here’s what we give instead:

$ remake –just-print -f test.mk1
##>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
case make in \
*/remake|remake) echo "Enlightended!";; \
*/make|make) echo "This is what most folks use.";; \
esac
##<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
This is what most folks use.
##>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
bogus-command
##<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

What’s different is that we separate the commands that are about to be run, such as case make in... from the output "This is what..." This may be a little bit subtle, but from the above output it is more apparent that there are two separate commands2 that are getting run from target foo: one at line 7 and another at line 10.

Now let’s try --debug=basic alluded to at the beginning of this section. In an unpatched GNU Make version 3.82, we get this:

$ make –debug=basic -f test1.mk
GNU Make 3.82
Built for i686-pc-linux-gnu
Copyright (C) 2010  Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Reading makefiles...
Updating goal targets....
 File `all' does not exist.
   File `foo' does not exist.
  Must remake target `foo'.
Invoking recipe from /tmp/test1.mk:6 to update target `foo'.
This is what most folks use.
make: bogus-command: Command not found
make: *** [foo] Error 127

The --debug=basic command-line switch also works in GNU Remake as well if that’s all you want..3

But now let’s try the new kind of trace we provide in this patched GNU Remake. We use the new option --trace. The short-form option format -x is the same as --trace and --trace=normal

/usr/local/bin/remake -x -f test1.mk
...
Reading makefiles...
Updating goal targets....
 /tmp/test1.mk:3	File `all' does not exist.
   /tmp/test1.mk:5	File `foo' does not exist.
  /tmp/test1.mk:5	Must remake target `foo'.
Invoking recipe from test1.mk:6 to update target `foo'.
##>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
case /tmp/../make in \
*/remake|remake) echo "Enlightened!";; \
*/make|make) echo "This is what most folks use.";; \
esac
##<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
This is what most folks use.
##>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
bogus-command
##<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
remake: bogus-command: Command not found
test1.mk:5: *** [foo] Error 127

#0  foo at /tmp/test1.mk:5
#1  all at /tmp/test1.mk:3
Command-line arguments:
	"/usr/local/bin/remake -x -f test1.mk"

In some ways this is just a combination of the enhanced--just-print option combined with the location-enhanced --debug=basic information.

What is completely new is the shell tracing information and information given when we hit an error. After the error and we report the return code (127), the stack of targets is listed. We were working on target foo on line 5 of file /tmp/test1.mk which was rebuilt because we were making target all on line 3 of file /tmp/test1.mk.

In other words, when we hit the error, the above trace gives what targets were in the process of getting considered at the error, and how the program was run.

One last subtlety that you might not have noticed is that we echoed the command bogus-command even though the original makefile had this set to be silent, in particular by preceding that command with an @.

When tracing as with --just-print, we override any silent execution making execution more verbose. This information is usually helpful in tracing.

Although I think that the above may be improved, it is far better than what has previously been available in GNU make. In my own experience, just adding that --trace or -x option is enough to let me find problems. No need to bring out the heavy artillery in a full-fledged debugger.

Still, it is nice to have additional power available, so read on...


Footnotes

(2)

or “jobs” in the terminology used when we used --debug

(3)

Actually the output is a little bit different here since we give a more context about the position when a fatal error is encountered.


Next: , Previous: , Up: Sample Sessions   [Contents][Index]