I have this simple makefile, after running make
command I get output parser
that I runs like #: ./parser
but sometimes it also generate a.out
So when make doesn't generate a.out with last make
command then running make clean
gives warning that rm: can not remove a.out, No such file or directory
So I like my make clean
command also check if a.out exists then remove otherwise dont try to remove. How can I do it in makefile inside clean: ....
parser: header.h parser.c
gcc header.h parser.c -o parser
clean:
rm parser a.out
CodePudding user response:
The usual way of doing it is to remove by force:
clean:
rm -f parser a.out
From rm
manpage:
-f, --force
ignore nonexistent files and arguments, never prompt