14

在我的 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

执行顺序:

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

所需的 Makefile

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

执行顺序:

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

1 回答 1

23

恐怕递归make是你的朋友。

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

如果make files成功,则您的工作已完成,退出代码为成功。失败时,退出代码为make network.

于 2013-03-22T11:54:33.610 回答