我想通过修改到NMAKE文件与系统时间/当地时间.exe文件重命名。可有一个建议书或引用的NMAKE commmands?在微软网页提供的参考不包括什么,我找...
下面的Makefile将工作:
# Create the macro DATE_TIME from the environment variables %DATE% and %TIME%
!if [echo %DATE%_%TIME% > date_time.tmp] == 0
DATE_TIME = \
!include date_time.tmp # get macro value from first line of temporary file
DATE_TIME = $(DATE_TIME::=+) # replace colons with "+"
DATE_TIME = $(DATE_TIME: =0) # replace spaces with "0"
!if [del date_time.tmp] # clean up temporary file
!endif
!endif
foo.exe: bar
foo.exe:
@echo Info: Building target $@ from $**, because $? is newer (or non-existent)
@type nul > $@
copy $@ "$*_$(DATE_TIME).exe"
bar:
输出是:
>nmake -nologo
Info: Building target foo.exe from bar, because bar is newer (or non-existent)
copy foo.exe "foo_07-Feb-2019_21+08+48.11.exe"
1 file(s) copied.
说明:环境变量%DATE%和%TIME%是不寻常的,它们的值可以在每次看他们的时间变化;看来这会导致他们与nmake
接口是有问题的。而作为一个小问题,%TIME%含有冒号,这当然不能是文件名的一部分。作为另一个问题,的%DATE%和%TIME%的格式不固定的:他们可以依赖于用户的选择。
给定溶液的捕获%DATE%和%TIME%的值在一个临时文件,然后设置一个nmake
宏使用!include
该文件的第一行的值。冒号,然后通过“+”,或任何你想要更换。
对于相关的问题,请参见Computed macro names。
并按照你的第二个问题,即你如何找到“书或引用的NMAKE commmands?”,看到我的回答Wildcard for files in sub-directory in NMAKE。
更新1:我原来的答复工作,但在此之前上午10时在我的机器上创建一个空间的文件名。因此,答案已经更新到解决这个问题。 (也许是一个更好的变通才是睡觉,直到上午10时在早晨!)
更新#2:另一种方法是不使用NMAKE宏,只是使用环境变量。这是较短的。 (I最初是由NMAKE打印输出误导。)
但需要做两次换人在%TIME%
,一个取代的空间和另一个替换冒号,平添了几分复杂的。是需要call
呼叫延迟变量扩展。
下面的Makefile:
foo.exe: bar
foo.exe:
@echo Info: Building target $@ from $**, because $? is newer (or non-existent)
@type nul > $@
call set XXX=%%DATE%%_%%TIME: =0%%& call copy $@ "$*_%%XXX::=+%%.exe"
bar:
得到:
>nmake -nologo
Info: Building target foo.exe from bar, because bar is newer (or non-existent)
call set XXX=%DATE%_%TIME: =0%& call copy foo.exe "foo_%XXX::=+%.exe"
1 file(s) copied.
有:
>dir /O-D
Volume in drive C has no label.
Volume Serial Number is xxxxxx
Directory of C:xxxxxx
08-Feb-2019 08:19 AM <DIR> ..
08-Feb-2019 08:19 AM <DIR> .
08-Feb-2019 08:19 AM 0 foo_08-Feb-2019_08+19+22.08.exe
08-Feb-2019 08:19 AM 0 foo.exe
08-Feb-2019 08:18 AM 196 Makefile
3 File(s) 196 bytes
2 Dir(s) 12,517,236,736 bytes free