对目标的仅订购先决条件强加订单 [英] Impose an order for Order-only-prerequisites of a target
问题描述
我有一个makefile片段:
I have a makefile snippet:
all: $(objects)
fresh: all | clean directory
directory: ;mkdir -p OutputDirectory
clean: ;rm $(objects); rm -rf OutputDirectory
在这里,我要确保在执行make fresh
-clean
时应以directory
开头,然后是all
.
Here, I want to ensure that when I do make fresh
- clean
should succeed by directory
which should be followed by all
.
从语义上讲,这里clean
仅作为订购的先决条件可能没有意义.将其假定为必须按一定顺序执行的order only dependency
.
Semantically, here it might not make sense for clean
to be order only prerequisite. Assume it to some order only dependency
that has to be executed in some order.
以下链接显示了类似的问题,但具有正常的依赖性: makefile-强制要求目标-堆栈溢出
The following link shows similar problem but for normal dependencies: makefile - Impose an order for the prerequisites of a target - Stack Overflow
推荐答案
在fresh
的配方中,您可以在同一makefile上两次递归地调用make
两次,以创建目标目录和all
目标:
In fresh
's recipe, you could call make
twice recursively on the same makefile, for the target that creates the directory and the all
target, respectively:
# At the very beginning of the makefile
CURRENT_MAKEFILE := $(lastword $(MAKEFILE_LIST))
# ...
.PHONY: all clean fresh
directory := OutputDirectory
all: $(objects)
fresh: clean
$(MAKE) -f $(CURRENT_MAKEFILE) $(directory)
$(MAKE) -f $(CURRENT_MAKEFILE) all
$(directory): ;mkdir -p $@
clean: ;rm -f $(objects); rm -rf $(directory)
这样,目标all
在目标$(directory)
之前,目标$(directory)
在目标clean
之前.
This way, the target all
is preceded by the target $(directory)
, which is in turn preceded by clean
.
这篇关于对目标的仅订购先决条件强加订单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!