Subject: Re: [PATCH] Makefile: add help target

From: Ævar Arnfjörð Bjarmason <[email-masked]>
Date: Fri, 08 Apr 2022 17:44:44 +0200

On Fri, Apr 08 2022, Taylor Blau wrote:

> On Fri, Apr 08, 2022 at 07:45:24AM +0000, Elia Pinto wrote:
>> Add a help target to the Makefile to be able to run make help, in the same way
>> does the Makefiles self-generated by some build systems.
>>
>> The target list has been statically extracted from the git Makefile with a
>> script and the results have been filtered in an essentially arbitrary way to
>> leave the ones that i imagines most interesting and frequent for a developer.
>
> I could definitely see something like "make help" being helpful, since
> make itself doesn't have a convenient way to list all of a Makefile's
> targets.
>
> I worry about this list getting stale, though. If we add a new target,
> will we remember to update the "help" list here? It would be nice if we
> could dynamically generate this list, but I think that loses out on the
> filtering you've done here.

There's some nice suggestions at:
https://stackoverflow.com/questions/4219255/how-do-you-get-the-list-of-targets-in-a-makefile

I managed to get pretty close to this by massaging the various parsers
that were suggested there.

But I wonder if defining help as we go along wouldn't be the best and
least likely to break, and most likely to be kept up-to-date. I.e. some
variant of the comments added there.

Or better (maybe it's discussed in that SO thing, I didn't skim it all),
something like:

    HELP_all = the default target
    all::
    [...]

We could then even print a heading showing what target(s) we're running
by looking at MAKECMDGOALS.

Also, Elia's ad-hoc script here copied from StackOverflow looks awfully
similar to what I have in /usr/share/bash-completion/completions/make
installed with my OS. Available here:
https://github.com/scop/bash-completion/blob/master/completions/make

So maybe we could just make this an optional target that depended on
that widely-available bash completion?

That would also have the nice benefit that to the extent that the output
sucked we could maybe massage our Makefile a bit to make it better, and
then we'd not only benefit "make help" users, but anyone doing "make
<TAB>".