Append date and time to an environment variable in linux makefile
46,558
Solution 1
you can use this:
LOGFILE=$(LOGPATH) `date +'%y.%m.%d %H:%M:%S'`
NOTE (from comments):
it will cause LOGFILE to be evaluated every time while used. to avoid that:
LOGFILE=$(LOGPATH)$(shell date)
Solution 2
You need to use the $(shell operation) command in make. If you use operation
, then the shell command will get evaluated every time. If you are writing to a log file, you don't want the log file name to change every time you access it in a single make command.
LOGPATH = logs
LOGFILE = $(LOGPATH)/$(shell date --iso=seconds)
test_logfile:
echo $(LOGFILE)
sleep 2s
echo $(LOGFILE)
This will output:
echo logs/2010-01-28T14:29:14-0800
logs/2010-01-28T14:29:14-0800
sleep 2s
echo logs/2010-01-28T14:29:14-0800
logs/2010-01-28T14:29:14-0800
Solution 3
you can use "date" command
Author by
ng5000
Updated on November 10, 2020Comments
-
ng5000 over 3 years
In my Makefile I want to create an environment variable using the current date and time. Pseudo code:
LOG_FILE := $LOG_PATH + $SYSTEM_DATE + $SYSTEM_TIME
Any help appreciated - thanks.