在我的Makefile文件中,我使用grep输出文件的内容,而在其他文件中找不到某些模式。但是,这仅在grep命令有某些输出时才有效,而在其他情况下则没有。我希望在运行它时不使用任何开关。这就是我的Makefile中的内容
all:
@(grep -v -e -define file1 | grep -v -e -libfile | grep -v -e pattern3 >> file2)
如果file1中的某些行不包含-define或-libfile,但在file1中的所有行中都具有这种模式,则此方法很好,因此grep不返回任何内容,那么make会因以下错误而失败:
Makefile.test:3: recipe for target 'all' failed
make: *** [all] Error 1
该命令在shell中可以正常工作,因此这与grep返回-1并终止make有关-有更好的方法吗?
答案 0 :(得分:0)
好吧,grep
定义为如果不匹配则以非0代码退出;从grep(1)手册页中:
Normally the exit status is 0 if a line is selected, 1 if no lines were selected, and 2 if an error occurred.
由于make会查看它所调用命令的退出状态以了解其是否成功,因此可以解释您看到的结果。
如果希望它总是成功,则可以使用true
后缀,如下所示:
@grep -v -e -define file1 | grep -v -e -libfile | grep -v -e pattern3 >> file2; true
(不需要括号:make已经在其自己的子外壳中调用了每个配方行)。