Can GNU make execute a rule whenever an error occurs?

筅森魡賤 提交于 2019-12-03 01:44:35

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

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 ...

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!