1

I use the following code to get a makefile targets list which works OK for most cases, however when you use makefile like this you get only two targets and not all.

cat Makefile

command: ## Command description
    @echo "Execution log"

another-command: ## Command description
    @echo "Execution log"

command2: ## Command description
    @echo "Execution log" 

The output is:

command
command2

I don't understand why I don't getting the command another-command, This is the code

`make -qp | awk -F':' '/^[a-zA-Z0-9][^$#\\\/t=]*:([^=]|$)/ {split($1,A,/ /);for(i in A)print A[i]}' `;

What could be the problem ?

I tried with the solution purposed but it provide an error:

make -qp | grep '^[a-z0-9-]\+:'

NSS
  • 755
  • 1
  • 11
  • 30

1 Answers1

1

what could be the problem ?

The problem is that this regular expression:

/^[a-zA-Z0-9][^$#\\\/t=]*:([^=]|$)/

does not match target names with hyphens (-) in them. As an unrelated matter, awk is a clumsy tool for what you appear actually to be doing with it; grep would be simpler to use:

make -qp | grep '^[a-z0-9-]\+:'

, which produces output

command:
command2:
another-command:
John Bollinger
  • 160,171
  • 8
  • 81
  • 157
  • thanks, I run it and I got an error, how did you test it ? – NSS Mar 30 '20 at 13:41
  • I run it in child process and I got erorr while running it, do I miss something ? – NSS Mar 30 '20 at 20:04
  • @NinaS, I put a copy of your makefile in a directory, correcting the indentation to be with single tabs instead of multiple spaces. I made that the working directory of my interactive shell session, and executed the command given in the answer. – John Bollinger Mar 30 '20 at 22:19
  • Thank you, taking your code and run it as-is in the terminal it works, but when I try it with `childprocess (nodejs) I got error , something strange is that if I run my provious command in `terminal` I see the output in white and when running your command I see it in red (using zsh) maybe it's related ...any idea ? – NSS Mar 31 '20 at 08:25
  • @NinaS, the color difference is likely a result of switching from `awk` to `grep`. When recent enough GNU `grep` thinks its output is an interactive terminal, it attempts to highlight matches by coloring them red. I cannot speak to whatever error you may see if you do not present the error, but I do observe that this is the first mention of node being related to the issue. If the alternative command I've suggested resolves the problem for you when run directly from the command line, then this answers the question as posed. – John Bollinger Mar 31 '20 at 12:29