Look at this makefile, it has some sort of primitive progress indication (could have been a progress bar).
Please give me suggestions/comments on it!
# BUILD is initially undefined ifndef BUILD # max equals 256 x's sixteen := x x x x x x x x x x x x x x x x MAX := $(foreach x,$(sixteen),$(sixteen)) # T estimates how many targets we are building by replacing BUILD with a special string T := $(shell $(MAKE) -nrRf $(firstword $(MAKEFILE_LIST)) $(MAKECMDGOALS) \ BUILD="COUNTTHIS" | grep -c "COUNTTHIS") # N is the number of pending targets in base 1, well in fact, base x :-) N := $(wordlist 1,$T,$(MAX)) # auto-decrementing counter that returns the number of pending targets in base 10 counter = $(words $N)$(eval N := $(wordlist 2,$(words $N),$N)) # BUILD is now defined to show the progress, this also avoids redefining T in loop BUILD = @echo $(counter) of $(T) endif # dummy phony targets .PHONY: all clean all: target @echo done clean: @rm -f target *.c # dummy build rules target: a.c b.c c.c d.c e.c f.c g.c @touch $@ $(BUILD) %.c: @touch $@ $(BUILD)
All suggestions welcome!
This one is less intrusive and more awesome.
Nice trick! (-:
But not really scalable for growing projects that are distributed across many directories with lots of makefiles.
I'd be more inclined to have logging sprinkled through the [Mm]akefiles* in your project and use that to keep track of progress.
Just a thought. BTW Thanks for sharing this.
Edit: Just had a thought. This could be useful in a modified form to display a throbber to show progress while a long task proceeds, e.g unpacking a large distribution tarball instead of just specifying the -v option to the tar command. Still a bit of sugar coating but a bit of fun aswell. (-:
cheers,
Rob
There wasn't really a question so this is less of a standalone answer and more of an extension to Giovanni Funchai's solution. This question is the first google result for "GNU Make Progress" so I ended up here looking for how to do this.
As pointed out by Rob Wells, the solution doesn't work for <10%, but the technique can be extended with the print formatting done by a helper script in whatever language you feel is portable enough for your build. For example, using a python helper script:
echo_progress.py
:And the modified
Makefile
:yields:
One could even print a fancy progress bar with unicode characters.
Modified
echo_progress.py
:Which would result in something like this:
during progress and:
upon completion.
This is a slight modification to @GiovanniFunchal's excellent answer.
So I wanted to understand this better and make it work for < 10% so I dug into the documentation and learned more about expr.
I got rid of the
: '.*\(....\)$$'
part. It would return the last 4 characters of the innerexpr
command, but would fail if it was less than 4. And now it works for sub 10%!And here is the comment free version:
Hope that helps.