发生错误时,Makefile是否可以执行代码?

Jac*_*ing 12 makefile

在我的Makefile中,我有一些代码可以检查网络连接.此代码需要相当长的时间才能运行,我只想在另一个目标无法构建时运行它.

当前的Makefile

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
Run Code Online (Sandbox Code Playgroud)

执行顺序:

if not network:
    # exit with error
if not files:
    # exit with error
if not all:
    # exit with error
Run Code Online (Sandbox Code Playgroud)

期望的Makefile

在上面的例子中,我希望network目标是"制造"的,只有当files目标未能"制造"时.

执行顺序:

if not files:
    if not network:
        # exit with error
if not all:
    # exit with error
Run Code Online (Sandbox Code Playgroud)

bob*_*ogo 19

递归制作是你的朋友,我很害怕.

.PHONY: all
all:
    ${MAKE} files || ${MAKE} network
Run Code Online (Sandbox Code Playgroud)

如果make files成功,您的工作就完成了,退出代码就成功了.失败时,退出代码是make network.