Makefile Backup Target

Goal: I'm trying to create a PHONY target inside my Makefile so that when I run the command "make backup",
It will move all the files that end in "~" into the specified backup folder.

Here is my code currently, and I'll explain the problem after:

1
2
3
4
5
6
.PHONY: backup
backup:
    @mkdir -p ./backup/include    #make folder (don't complain if it already exists)
    @mkdir -p ./backup/src        #make folder (don't complain if it already exists)
    @mv -fu *.h~ ./backup/include #move header file backups into desired folder
    @mv -fu *.cpp~ ./backup/src   #move source file backups into desired folder 


Problem: This works great, BUT ONLY if a file "*.h~" and "*.cpp~" file already exist in Makefile's current directory. I would like this target to move the files if it can, and just be quiet if there are no files to move..

Error Message:
mv: cannot stat `*.h~': No such file or directory


*I'm on linux(ubuntu) and so my shell is "bash"

Appreciate the help, I’ve been stuck on this all night trying all kinds of commands from if statements to the "find" command. Just thought I’d finally ask for some assistance :)
¿what does the '@' at the start of the line?

http://www.gnu.org/software/make/manual/html_node/Errors.html#Errors
starting with - it will still output that there was an error, but it will continue with the recipe.

Another possibility is a bash loop.

Or you could use git instead.
Last edited on
¿what does the '@' at the start of the line?

hides the command so that it doesn't echo in the console

thanks dude, that’s exactly what i needed :)
Topic archived. No new replies allowed.