Makefile-仅当文件不存在时才进行依赖 [英] Makefile - Make dependency only if file doesn't exist
问题描述
就像标题中所说的,我只想在某个文件不存在时进行依赖,而不是每次更新时都进行依赖.
Like the title says, I would like to make a dependency only if a certain file does not exist, NOT every time it updates.
我有一个根目录(一个带有makefile的目录),在其中有一个名为"example"的子目录.在我的根目录中,有四个.h文件(functions.h,parser.h,node.h和exception.h),如果这些.h文件不存在,我希望将其复制到"example"子目录中在示例"中.
I have a root directory (the one with the makefile) and in it a sub-directory called "example". In my root directory are four .h files (functions.h, parser.h, node.h, and exception.h) which I would like to copy to the "example" sub-directory if those .h files do not already exist in "examples".
不幸的是,我不能仅仅建立标准的依赖项来检查示例"中的头文件,因为每次我将头文件从根目录复制到示例"时,示例"中的头文件都将被视为已更新并将每次我运行make时,都会触发该依赖项.我想让我的makefile仅在示例"中不存在头文件的情况下才将头文件从根目录复制到示例".
Unfortunately I can not just make a standard dependency to check for the header files in "example" because each time I copy the header files from root to "example", the header files in "example" will be considered updated and will trigger that dependency each time I run make. I would like for a way to have my makefile copy the header files from the root directory to "example" only if they do not exist in "example".
推荐答案
这是仅订购的先决条件/依赖项用于:
但是,有时候,您希望对要调用的规则施加特定的顺序,但如果执行了其中一个规则,则不必强制更新目标.在这种情况下,您要定义仅订购的先决条件.可以通过在先决条件列表中放置管道符号(
|
)来指定仅订购的先决条件.右侧的所有先决条件仅是订购.
Occasionally, however, you have a situation where you want to impose a specific ordering on the rules to be invoked without forcing the target to be updated if one of those rules is executed. In that case, you want to define order-only prerequisites. Order-only prerequisites can be specified by placing a pipe symbol (
|
) in the prerequisites list: any prerequisites to the left of the pipe symbol are normal; any prerequisites to the right are order-only.
在您的情况下:
examples/%.h : | %.h
cp $| $@
另请参见:不显示仅订购的先决条件在$^
或$+
中.
See also: Order-only prerequisites do not show up in $^
or $+
.
这篇关于Makefile-仅当文件不存在时才进行依赖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!