Makefile 1.1 KB

1234567891011121314151617181920212223242526272829
  1. # This demonstrates a method for providing progress information during
  2. # a package build. It accurately takes into account the count of
  3. # outstanding jobs to be done. I.e. if only a few of the total
  4. # targets need updating, it will print only that number. The hope
  5. # would be to use a mechanism simpler than cmake's, while still be
  6. # accurate and useful. It seems to be relatively fast, needing only
  7. # two shell invocations plus a number of variable eval's.
  8. SOURCES := 1.c 2.c 3.c 4.c 5.c 6.c 7.c 8.c 9.c 10.c 11.c 12.c 13.c
  9. COUNT = 0
  10. ifndef TOTAL
  11. # If every recipe produced a single line during `make -n` then we could
  12. # simply pipe through `wc -l`. But counting occurences of a unique
  13. # marker is more robust, and not much more costly.
  14. PROGRESS_MARK := ++progress-mark++
  15. TOTAL := $(shell $(MAKE) -n TOTAL=$(PROGRESS_MARK) $(MAKECMDGOALS) | grep --count -F -- $(PROGRESS_MARK))
  16. endif
  17. WIDTH := $(shell printf "%s" $(TOTAL) | wc -c)
  18. PROGRESS = $(eval COUNT = $(shell expr $(COUNT) + 1)) printf "[%$(WIDTH)d/%d]" $(COUNT) $(TOTAL);
  19. all: $(SOURCES)
  20. $(SOURCES):
  21. @$(PROGRESS)echo " GEN $@"; touch $@; sleep `expr $$RANDOM % 2`
  22. clean:
  23. rm -f $(SOURCES)