views:

412

answers:

3

Hi

In my makefile I want to create an environment variable using the current date and time. Psuedo code:

LOG_FILE := $LOG_PATH + $SYSTEM_DATE + $SYSTEM_TIME

Any help appreciated - thanks.

+1  A: 

you can use "date" command

Himanshu
+1  A: 

you can use this:

LOGFILE=$(LOGPATH) `date +'%y.%m.%d %H:%M:%S'`
catwalk
Won't this cause LOGFILE to be evaulated everytime it is used. For example:LOGFILE=logs/`date +'%y.%m.%d-%H:%M:%S'`echo_logs: echo $(LOGFILE) sleep 5s echo $($LOGFILE)will print:echo logs/`date +'%y.%m.%d-%H:%M:%S'`logs/10.01.28-14:21:08sleep 5secho logs/`date +'%y.%m.%d-%H:%M:%S'`logs/10.01.28-14:21:13
Aaron
@Aaron: You are right; to avoid this one can use gnu make `shell` function instead of backticks: `LOGFILE=$(LOGPATH)$(shell date)`
catwalk
A: 

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
Aaron