[英]Get GNU makefile targets from command
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.我使用下面的代码来获取一个 makefile 目标列表,它在大多数情况下都可以正常工作,但是当你像这样使用 makefile 时,你只会得到两个目标,而不是全部。
cat Makefile
猫
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我不明白为什么我没有得到命令
another-command
,这是代码
`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;作为一个不相关的问题,
awk
是一个笨拙的工具,用于处理您实际使用它所做的事情; grep
would be simpler to use: grep
会更简单:
make -qp | grep '^[a-z0-9-]\+:'
, which produces output , 产生输出
command:
command2:
another-command:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.