如何检查makefile中目标的存在

如何检查makefile中目标的存在,第1张

概述我想在 shell中运行某些 *** 作,具体取决于当前目录中的默认makefile是否包含某个目标. #!/bin/shmake -q some_targetif test $? -le 1 ; then true # do somethingelse false # do something else fi 这是有效的,因为如果目标不存在,GNU make会返回错误代码 我想在 shell中运行某些 *** 作,具体取决于当前目录中的默认makefile是否包含某个目标.

#!/bin/shmake -q some_targetif test $? -le 1 ; then    true # do somethingelse    false # do something else     fi

这是有效的,因为如果目标不存在,GNU make会返回错误代码2,否则返回0或1.问题是这种方式没有记录.这是男人的一部分:

-q,--question        ``Question mode''.  Do not run any commands,or  print  anything;        just  return  an exit status that is zero if the specifIEd targets        are already up to date,nonzero otherwise.

仅区分零/非零.这样做的正确方法是什么?

解决方法 您应该阅读 the GNU make manual而不是手册页:手册页只是摘要而不是完整的定义.手册说:

The exit status of make is always one of three values:0    The exit status is zero if make is successful2    The exit status is two if make encounters any errors. It will print messages     describing the particular errors.1    The exit status is one if you use the ‘-q’ flag and make determines that     some target is not already up to date.

由于尝试创建不存在的目标是一个错误,因此在这种情况下,您将始终获得退出代码2.

总结

以上是内存溢出为你收集整理的如何检查makefile中目标的存在全部内容,希望文章能够帮你解决如何检查makefile中目标的存在所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/1216060.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-05
下一篇 2022-06-05

发表评论

登录后才能评论

评论列表(0条)

保存