git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCHv2] Makefile: implement help target

From
Michael J Gruber <git@drmicha.warpmail.net>
Date
Sep 29, 2010, 07:03 UTC
Message-ID
<4CA2E4C7.305@drmicha.warpmail.net>
In-Reply-To
<20100929051640.GA26324@sigill.intra.peff.net>
Jeff King venit, vidit, dixit 29.09.2010 07:16:
Show 15 quoted lines
> 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?
I don't speak perl.

Honestly, this is slowly going on my nerves. Maybe it's because I'm reading too many "can't we do it this way" responses in one go and without being coffeinated, and without seeing how "different" is better. [I've been heeding all advise on portability and readability, as you can see.]

So far we've been using neither awk nor perl in the Makefile, but sed.
> help:
> 	@perl -n0777 \
> 	  -e 'push @{$$h{$$1}}, [$$3, $$2] while /^# Help: (.*?): (.*)\n(.*?):/mg;' \

On top of everything else, you're even slashing mg! (See, I'm less grumpy already...)

Show 5 quoted lines
> 	  -e 'for (sort keys(%h)) {' \
> 	  -e '  print "$$_:\n";' \
> 	  -e '  printf("    %-20s%s\n", @$$_) for (@{$$h{$$_}});' \
> 	  -e '}' Makefile
> 
How portable are the regexps and the array/dictionary push?
> 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).

I don't think Makefile order would be useful. If you know exactly what you're looking for you need no sorting, you can just search for that term. (I would do a 'grep -A20 "^target:" Makefile' or hit "/^target" in my vim but I'm sure there's a different way of doing it in perl...)

If you're trying to find your way around you guess a generic term and look for that, and that's easier to do when the categories are sorted alphabetically.

Michael
Previous: Jeff KingNext: Jeff King
Message 18 of 24 in “Makefile: Add help target”
  1. Makefile: Add help targetStephen Boyd, Sep 28, 2010
  2. Junio C HamanoSep 28, 2010
  3. Sverre RabbelierSep 28, 2010
  4. Andreas EricssonSep 28, 2010
  5. Makefile: implement help targetMichael J Gruber, Sep 28, 2010
  6. Sverre RabbelierSep 28, 2010
  7. Zbyszek SzmekSep 28, 2010
  8. Ævar Arnfjörð BjarmasonSep 28, 2010
  9. Junio C HamanoSep 28, 2010
  10. Michael J GruberSep 28, 2010
  11. Ævar Arnfjörð BjarmasonSep 28, 2010
  12. [PATCHv2] Makefile: implement help targetMichael J Gruber, Sep 28, 2010
  13. Sverre RabbelierSep 28, 2010
  14. Jakub NarebskiSep 28, 2010
  15. Brandon CaseySep 28, 2010
  16. Michael J GruberSep 29, 2010
  17. Jeff KingSep 29, 2010
  18. Michael J GruberSep 29, 2010
  19. Jeff KingSep 29, 2010
  20. Junio C HamanoSep 29, 2010
  21. [PATCHv3] Makefile: implement help targetMichael J Gruber, Sep 29, 2010
  22. Junio C HamanoSep 29, 2010
  23. Michael J GruberSep 30, 2010
  24. yj2133011Sep 29, 2010

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.