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-]\\+:'
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:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.