禁止生成规则错误输出 [英] Suppress make rule error output
问题描述
我有一个创建目录的规则
I have an rule that creates a directory
bin:
-mkdir $@
但是,第一次生成目录后,我会收到以下输出:
However after the first time the directory has been generated, I receive this output:
mkdir bin
mkdir: cannot create directory `bin': File exists
make: [bin] Error 1 (ignored)
有什么方法可以仅在目录不存在时运行规则,还是在目录已存在时禁止输出?
Is there some way I can only run the rule if the directory doesn't exist, or suppress the output when the directory already exists?
推荐答案
处理目录创建的传统方法是使用依赖于它的图章文件并创建dir作为副作用.制作distclean
或任何真正干净"的目标时,请删除该图章文件:
The traditional way to handle directory creation is to use a stamp file that is depended on and creates the dir as a side effect. Remove the stamp file when making distclean
or whatever your "really clean" target is:
bin/.dirstamp:
mkdir -p $(DIRS)
touch $@
bin/foo: bin/.dirstamp
$(MKFOO) -o $@
distclean:
rm -rf bin
这样做的原因如下:每当创建/删除bin
中的文件时,将更新包含目录的mtime.如果目标依赖于bin
,则下次make
运行时,它将重新创建不需要的文件.
The reason for this is as follows: whenever a file in bin
is created/removed, the mtime of the containing directory is updated. If a target depends on bin
, then the next time make
runs, it will then recreate files that it doesn't need to.
这篇关于禁止生成规则错误输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!