gnu make - Using variables in Makefile -
gnu make - Using variables in Makefile -
here simple makefile.
filename=test.`date +"%y.%m.%d %h:%m:%s"`.txt test: @echo ${filename} @sleep 2s @echo ${filename} the output of make test
test.2013.02.18 15:30:23.txt test.2013.02.18 15:30:25.txt the problem filename beingness calculated each time used. want calculated 1 time , same while script running. doing wrong?
gnu create has 2 flavours of variables. have used recursively-expanded variable, want simply-expanded variable. see http://www.gnu.org/software/make/manual/html_node/flavors.html#flavors
with current makefile, variable contains exact text test. , every time reference text gets substituted verbatim, , makefile equivalent to:date +"%y.%m.%d %h:%m:%s".txt
test: @echo test.`date +"%y.%m.%d %h:%m:%s"`.txt @sleep 2s @echo test.`date +"%y.%m.%d %h:%m:%s"`.txt seen should obvious shell runs date command twice.
to behaviour want, need set simply-expanded variable , need run shell command @ point define it, can't utilize backticks because shell metacharacters create ignores them, utilize make's shell function instead:
filename := test.$(shell date +"%y.%m.%d %h:%m:%s").txt makefile gnu-make
Comments
Post a Comment