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.

The another command doesn't show up

cat Makefile

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

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

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

The output is:


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 use this as reference How to list all targets in make?

enter image description here

  • 1
    What are you expecting [^$#\\\/t=]* to match? right now, it's excluding notther I think? Commented Mar 30, 2020 at 21:20
  • 2
    Please show the actual makefile. The makefile that you show would not produce the output that you show. Also explain the purpose of your last code fragment.
    – Kusalananda
    Commented Mar 31, 2020 at 8:45
  • @Kusalananda - this is the make file , I will add a picture
    – NSS
    Commented Mar 31, 2020 at 8:57
  • @Kusalananda - I've added the picture to the post, please have a look.
    – NSS
    Commented Mar 31, 2020 at 9:01
  • @NinaS, I can't run your picture through your commands, so it is useless as a test case.
    – vonbrand
    Commented Mar 31, 2020 at 12:18

1 Answer 1

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

In my character set are backslash and tab, in your set are backslash, slash and "t".

And "another" contains a "t" ;-)

Credits to steeldriver

  • Why does this list Makefile as a target, though?
    – nsheff
    Commented Mar 2, 2021 at 22:37
  • @nsheff "Not a target" built-in, try make -qp | grep -1 Makefile
    – Polluks
    Commented Mar 3, 2021 at 21:32

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .