D
D
DVoropaev2019-07-14 14:53:21
GNU Make
DVoropaev, 2019-07-14 14:53:21

How to make make not swear if there are no files?

I made this makefile, set the goal "clean":

# .PHONY: all clean
all: hello.o main.o
  gcc -o hello main.o hello.o
hello.o: hello.c
  gcc -o hello.o -c hello.c
main.o: main.c
  gcc -o main.o -c main.c
clean:
  -rm ./*.o 2>/dev/null

But it complains if there are no files to delete:
$ make all
gcc -o hello.o -c hello.c
gcc -o main.o -c main.c
gcc -o hello main.o hello.o

$ make clean
rm ./*.o 2>/dev/null

$ make clean
rm ./*.o 2>/dev/null
makefile:9: recipe for target 'clean' failed
make: [clean] Error 1 (игнорирование)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
rustler2000, 2019-07-15
@DVoropaev

It's not make that swears, but rm
Add -f to rm and everything will be ok

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question