我正在使用 NMake 制作联编文件。我有一些实用程序可以运行以将一个文件转换为 CPP 文件。该实用程序需要在 session 期间设置特定的 Windows 环境变量。我可以在 Makefile 中设置这个变量,还是需要创建一个批处理脚本来在调用 NMake 之前设置变量?
最佳答案
使用 !if [set ...]
trick :
!if [set myvar=1]
!endif
# Macro values are fine, too, of course:
MYVAL=preprocessed
!if [set myvar=$(MYVAL)]
!endif
# Proof that myvar has really become an env. var. (see the output):
myvar=This is propagated to the env now!
mymacro=(But this isn't, of course.)
# This handy form works, too:
!if [set myA=1] || [set myB=2]
!endif
# But this will *NOT* make myX an env. var., if it hasn't been set yet:
!if [set myX=$(myX)]
!endif
myX=So you'll not see this...
all:
set my
输出:
D:\tmp>nmake -f test.mak
Microsoft (R) Program Maintenance Utility Version 14.21.27702.2
Copyright (C) Microsoft Corporation. All rights reserved.
set my
myA=1
myB=2
myvar=This is propagated to the env now!
关于windows - 如何使用 NMake 设置环境变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38381422/