发生错误时,Makefile只能执行代码吗? [英] Can a Makefile execute code ONLY when an error has occurred?

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

问题描述

在我的Makefile中,我有一些代码可以检查网络连接.这段代码要花相当长的时间才能运行,我只想在其他目标无法建立时运行它.

In my Makefile, I have some code that checks for network connectivity. This code takes a decent amount of time to run and I would only like to run it if another target fails to build.

all: files network
    # compile files

files:
    # get files from network resources

network:
    # check for network connectivity
    # echo and return an error if it's not available

执行顺序:

if not network:
    # exit with error
if not files:
    # exit with error
if not all:
    # exit with error

所需的Makefile

在上面的示例中,仅当files目标无法获得"made"时,我才希望network目标是"made".

Desired Makefile

In the above example, I would like the network target to be "made", only if the files target fails to get "made".

执行顺序:

if not files:
    if not network:
        # exit with error
if not all:
    # exit with error

推荐答案

在这里,递归make是您的朋友.

Recursive make is your friend here I'm afraid.

.PHONY: all
all:
    ${MAKE} files || ${MAKE} network

如果make files成功,则说明您的工作已完成,并且退出代码成功.失败时,退出代码是make network的退出代码.

If make files succeeds, your work is done and the exit code is success. On failure, the exit code is that for make network.

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

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