tags:

views:

39

answers:

3

Hi, I'm making a Makefile that moves an output file (foo.o) to a different directory (baz).

The output file moves as desired to the directory. However since make won't recompile the output file if I type 'make' again, mv gets an error when it tries to move the non-existent empty file to the directory baz.

So this is what I have defined in my rule 'make all' after all compilation:

-test -e "foo.o" || mv -f foo.o ../baz

Unfortunately, I'm still getting errors. Any help would be greatly appreciated. Thanks!

A: 
   -test -e "foo.o" || if [ -f foo.o ]; then mv -f foo.o ../baz; fi;

That should work

A: 

Something like

test -e "foo.o" && mv -f foo.o ../baz

should work: the operator should be && instead of ||.

You can experiment with this by trying these commands:

test -e testfile && echo "going to move the file"
test -e testfile || echo "going to move the file"
Richard Fearn
A: 
+@[ -d $(dir $@) ] || mkdir -p $(dir $@)

is what I use to silently create a folder if it does not exist. For your problem something like this should work

-@[ -e "foo.o" ] && mv -f foo.o ../baz
Charles
i still get an ignored error when using this but was the best solution so far. thanks
Sam
yes you will still get the silent ignore error from make, which I dont quite agree with as @ should make it completely silent.
Charles
@ does not affect the output from make of from the command, it only tells make not to print the invokation itself.
JesperE