I am running compgen -c make
in BASH on mac and am getting the following return values:
makepqg
makepqg
makepqg
make
makeinfo
makepqg
makepqg
But what I want and should? be getting (and do get when completing) is:
foo
bar
biz
baz
Which represent my various PHONY make rules that do automatic things.
How does one generate this list from the SHELL, generally, with the executable tool compgen
?
(this is the ideal question because, from python3, subprocess
is not able to simulate the interaction, and I'll have to do something more involved)
This is different than the duplicate candidate, "How do I get the targets in make (paraphrased)" in that I don't think the (non-working) command is a good answer, and this question is about compgen
and make
rather than make
and the inner workings of make
:
make -p no_targets__
| awk -F':' '/^[a-zA-Z0-9][^\$$#\/\\t=]*:([^=]|$$)/ {split(\$$1,A,/ /);for(i in A)print A[i]}' "
| grep -v '__\$$' "
| sort
But can I get to some kind of a solution for my high level purpose using regexes?
In my opinion, no, because compgen is easy and memorable, whereas this kludge is hard and introduces drag on any code I'd pile on top.
Also, the duplicate allows for changes to be made to the makefile.
In my case, the make file must be considered a given, or what I am doing will be less useful.
So, more specifically, given any makefile, is there a solution involving tools outside of make that can look into make and get make to output a list of its recipes as it would for bash completion.
In other words: can this be done for ANY makefile (without loss of generality) without requiring write permissions on the makefile, and without simulating the tab-tab using a tty simulator?