每当发生错误时,GNU都能使规则执行吗? [英] Can GNU make execute a rule whenever an error occurs?

查看:72
本文介绍了每当发生错误时,GNU都能使规则执行吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这与可能略有不同.

我希望每当发生错误(独立于给定目标;不更改每个目标的规则,因为其他答案似乎暗示||运算符)时制定规则或特殊目标.

I'd like a rule or special target that is made whenever an error occurs (independent of the given target; without changing the rule for every target as the other answer seems to imply with the || operator).

dmake 中,有特殊目标 > .ERROR ,只要检测到错误情况,就会执行 . GNU make是否有类似的东西?

In dmake there is special target .ERROR that is executed whenever an error condition is detected. Is there a similar thing with GNU make?

(我仍在使用GNU make 3.81,但在新的GNU make 4.0的文档中也没有找到任何东西)

(I'm still using GNU make 3.81, but I didn't find anything in the documentation of the new GNU make 4.0 either)

推荐答案

Gnu不显式支持它,但是有种方法可以破解几乎所有内容.如果任何制造失败,则制造返回1.这意味着,如果第一个make失败,则可以在命令行上使用错误规则重新运行make:

Gnu doesn't support it explicitly, but there's ways to hack almost anything. Make returns 1 if any of the makes fail. This means that you could, on the command line, rerun make with your error rule if the first make failed:

make || make error_targ

当然,我假设您只是想将添加的复杂性放入makefile本身中.在这种情况下,您可以创建一个递归的make文件:

Of course, I'll assume you just want to put the added complexity within the makefile itself. If this is the case, you can create a recursive make file:

all: 
     $(MAKE) normal_targ || $(MAKE) error_targ

normal_targ:
      ... normal make rules ...

error_targ:
      ... other make rules ...

这将使makefile尝试构建normal_targ,如果失败,它将运行error_targ.对于没有经验的人来说,读取makefile有点困难,但是它将所有逻辑放在一个地方.

This will cause the makefile to try to build normal_targ, and iff it fails, it will run error_targ. It makes it a bit harder to read the makefile for the inexperienced, but it puts all the logic in one place.

这篇关于每当发生错误时,GNU都能使规则执行吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆