【发布时间】:2016-02-10 01:42:03
【问题描述】:
我在 C++ 项目中有一个 makefile(编译器:C++11)。如何在使用 makefile 命令删除特定文件之前检查它是否存在?
代码如下:
bin: charstack.h error.h
g++ -Wall -std=c++11 main.cpp charstack.cpp error.cpp -o bin
run:
./bin.exe
clean:
rm bin.exe
# This statement removes auto generated backups on my system.
cl:
rm charstack.h~ charstack.cpp~ main.cpp~ makefile~ error.h~ error.cpp~
我如何让 makefile 检查自动生成的 .~ 备份文件是否存在,然后再尝试在用户通过时删除它们
make cl
在命令行中?这里的目标是避免在运行“make cl”时将这些错误输出到终端:
rm: cannot remove `charstack.h~': No such file or directory
rm: cannot remove `charstack.cpp~': No such file or directory
rm: cannot remove `main.cpp~': No such file or directory
rm: cannot remove `error.h~': No such file or directory
rm: cannot remove `error.cpp~': No such file or directory
make: *** [cl] Error 1
【问题讨论】:
-
之前的标题更好。现在它 (a) 无法描述,并且 (b) 命名错误的技术。