我想在b.mak makefile中获取名为$(MYVAR)_SOME_SUFFIX的变量的值。 相反,我得到“b.mak(2):致命错误U1001:语法错误:宏中的非法字符'$'”
# ---- a.mak ----
all :
set MYVAR=SOME_PREFIX
nmake -f b.mak
#--- END ---
# ---- b.mak ----
all:
@echo $($(MYVAR)_SOME_SUFFIX)
#--- END ---
答案 0 :(得分:2)
您可以使用inline files完成所需的操作。
# ---- piotr1.mak ----
all :
nmake -nologo -f piotr2.mak MYVAR=BBB
#--- END ---
# ---- piotr2.mak ----
AAA_SETTING=17
BBB_SETTING=24
AVAR=$(MYVAR)_SETTING
all:
# create and invoke a temporary cmd file
@<<myecho.cmd
@echo off
setlocal
REM insert nMAKE macros into environment of the command
set AAA_SETTING=$(AAA_SETTING)
set BBB_SETTING=$(BBB_SETTING)
REM now echo the value of whichever env var is named by the
REM nmake macro, AVAR.
echo %$(AVAR)%
endlocal
<<
#--- END ---
当我运行nmake -f piotr1.mak
时,我得到了呼叫控制台的预期值:24。