我正在使用NMake创建一个makefile。我有一些实用程序可以将一个文件转换为CPP文件。该实用程序需要在会话期间设置特定的Windows环境变量。我可以在Makefile中设置这个变量,还是我需要创建一个批处理脚本来设置变量才能调用NMake?
答案 0 :(得分:0)
继承调用ENVAR
时存在的环境变量nmake
作为同名的nmake
宏。如果您更改了ENVVAR
中的值
makefile,如:
ENVAR=newval
然后环境变量ENVAR
假定命令的值为newval
由makefile运行。目标:
foo:
echo "%ENVAR%"
将回复newval
。
但您无法创建这样的环境变量ENVAR
。所以你呢
必须至少创建之前要使用的环境变量
调用nmake
答案 1 :(得分:0)
使用!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!