Reputation: 583
I want something like this (date (from shell) in the target filename)
bakfile=mybackup.$(date +%Y%m%d).tar
$(bakfile):
tar -cf $@ /source-dir
Or maybe with the date in the target spec?
mybackup.$(date +%Y%m%d).tar:
tar -cf $@ /source-dir
Upvotes: 0
Views: 402
Reputation: 100836
A makefile is not a shell script. A makefile can contain shell scripts, but you can't just write shell operations directly anywhere in a makefile and expect it to work like the shell.
I recommend:
date := $(shell date +%Y%m%d)
then use the variable $(date)
wherever you want the date string. Running it multiple times is a race condition risk, if you run it right around midnight the value might change between two different invocations.
Upvotes: 2
Reputation: 99094
You have to make a slightly greater effort, if you want to invoke shell commands from within a makefile:
bakfile=mybackup.$(shell date +%Y%m%d).tar
You can do it in the target name too, but I advise against that-- it's hard to read.
Upvotes: 0