在makefile中打印时间戳

use*_*883 0 makefile gnu-make

我想测量make文件中每个构建项目的时间,我只是在下面尝试,为什么它不起作用?

mytest:
    $(info 'Now time is $(date --iso=seconds)')

日期不打印,只打印

'Now time is '
.有什么不对?

make --version GNU Make 3.81

tri*_*eee 5

没有make命名的功能date.如果要调用shell命令,则语法为$(shell date).

使用$(info)的配方是不是特别优雅; 该函数不会产生任何对传递给shell有用的东西.你可能只是寻找

mytest:
    date +"Now time is +%FT%T%z"
Run Code Online (Sandbox Code Playgroud)

(无法找到--iso-seconds正确的文件;从这个博客中获取定义:http://nixscripts.blogspot.com/2010/07/hidden-arguments-easter-egg-or-what.html)

......或者可能效率不高

mytest:
    printf 'Now time is %s\n' "$$(date --iso-seconds)"
Run Code Online (Sandbox Code Playgroud)

双美元符号从Make中逃脱美元符号,以便您通过命令替换到shell.

只是要指出显而易见的,不幸的是,Make使用的语法与shell的命令替换语法非常相似.在Make内部,您使用$(shell command)$$(command)传递command给shell.前者在纯Make片段(Makefile正确的变量定义等)中有意义; 后者仅适用于食谱.