问题
I want to measure the time for each of build item in make file, i just try below, why does it not work?
mytest: $(info 'Now time is $(date --iso=seconds)')
The date is not printed, just printed
'Now time is '. What can be wrong?
make --version
GNU Make 3.81
回答1:
There is no make
function named date
. If you want to invoke a shell command, the syntax is $(shell date)
.
Using $(info)
in a recipe is not particularly elegant; the function doesn't produce anything which is useful to pass to a shell. You are probably looking simply for
mytest:
date +"Now time is +%FT%T%z"
(Could not find --iso-seconds
documented properly; grabbed the defintion from this blog: http://nixscripts.blogspot.com/2010/07/hidden-arguments-easter-egg-or-what.html)
... or perhaps somewhat less efficiently
mytest:
printf 'Now time is %s\n' "$$(date --iso-seconds)"
where the double dollar sign escapes the dollar sign from Make so that you pass through a command substitution to the shell.
Just to point out the obvious, it is unfortunate that Make uses a syntax which is so similar to the shell's command substitution syntax. Inside Make, you use $(shell command)
or $$(command)
to pass command
to the shell. The former makes sense in pure Make snippets (variable definitions in the Makefile
proper, etc); the latter is only available in recipes.
来源:https://stackoverflow.com/questions/37722572/print-timestamp-in-makefile