在构建任何目标后(即将退出之前)强制Makefile执行脚本 [英] Force Makefile to execute script after building any target (just before exiting)

查看:594
本文介绍了在构建任何目标后(即将退出之前)强制Makefile执行脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在make退出时执行一个shell命令,而不管它建立了什么目标.好像make没有直接执行此操作的方法.但是,这里有一个示例,无论启动目标是什么,make都会在启动时执行shell命令:

I'd like to execute a shell command when make exits, regardless of whatever target it built. Seems like make doesn't have a way to do this directly. However, here's an example of having make execute a shell command upon startup, regardless of the target:

强制Makefile在构建目标之前执行脚本

在退出前是否有任何类似的技巧可以使一次shell命令执行?我可以将命令放在每个目标的底部,但是a)它会多次执行,b)难看且难以管理.

Is there any similar hack have make execute a shell command once just before exiting? I could put the command at the bottom of every target, but a) it would get executed multiple times, and b) that is ugly and difficult to manage.

推荐答案

正如janos所说,make并没有内置任何工具.您可以使用他建议的包装纸.另外,如果您愿意忍受一定数量的"bleah",请使用递归将其推送到makefile中.看起来可能是这样的:

As janos says, there is no facility built into make to do it. You can use a wrapper such as he suggests. You an also, if you're willing to live with some amount of "bleah", push that into your makefile using recursion. It would look something like this, perhaps:

ifdef RECURSING

    ... normal makefile goes here ...

else

.DEFAULT all:
        @$(MAKE) RECURSING=true $@ ; r=$$? ; \
         <extra shell command here>; \
         exit $$r

endif

这篇关于在构建任何目标后(即将退出之前)强制Makefile执行脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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