在makefile中打印时间戳 [英] Print timestamp in makefile
问题描述
我想测量make文件中每个构建项目的时间,我只是在下面尝试,为什么它不起作用?
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)')
不打印日期,仅打印
'Now time is '
.有什么问题吗?
make --version
GNU Make 3.81
make --version
GNU Make 3.81
推荐答案
没有名为date
的make
函数.如果要调用shell命令,语法为$(shell date)
.
There is no make
function named date
. If you want to invoke a shell command, the syntax is $(shell date)
.
在食谱中使用$(info)
并不是特别优雅;该函数不会产生任何对传递给shell有用的东西.您可能只是在寻找
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"
(找不到正确记录的--iso-seconds
;从此博客中获取了定义:
(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)"
其中双美元符号从Make逃脱了美元符号,以便您通过命令替换到达外壳.
where the double dollar sign escapes the dollar sign from Make so that you pass through a command substitution to the shell.
仅指出显而易见的一点,不幸的是,Make使用的语法与Shell的命令替换语法非常相似.在Make内部,使用$(shell command)
或$$(command)
将command
传递给外壳.前者在纯Make片段中是有意义的(Makefile
适当的变量定义,等等);后者仅在配方中可用.
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.
这篇关于在makefile中打印时间戳的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!