On Tue, Sep 28, 2010 at 10:38:04PM +0200, Michael J Gruber wrote:
+help:
+ @awk '/^# Help:/ { l=substr($$0,8); \
+ getline; \
+ j=index(l,":"); \
+ print substr(l,1,j-1), substr($$0,1,index($$0,":")), substr(l,j+2); \
+ }' <Makefile | sort | while read category target text; \
+ do \
+ test "$$category" = "$$currcat" || printf "$$category targets:\n"; \
+ currcat="$$category"; \
+ printf " %-20s%s\n" "$$target" "$$text"; \
+ done
Surely this is why we have perl?
help:
@perl -n0777 \
-e 'push @{$$h{$$1}}, [$$3, $$2] while /^# Help: (.*?): (.*)\n(.*?):/mg;' \
-e 'for (sort keys(%h)) {' \
-e ' print "$$_:\n";' \
-e ' printf(" %-20s%s\n", @$$_) for (@{$$h{$$_}});' \
-e '}' Makefile
Note that mine will actually print the targets in a heading in the order
in which they appear in the Makefile, which I consider slightly more
useful (especially in that we can tweak the order easily). It would also
be easy to sort the headers in some more meaningful way, but here I just
did it lexically.
-Peff