1

我想在 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 ---
4

1 回答 1

2

你可以用内联文件做你想做的事。

# ---- 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。

于 2010-05-11T18:53:50.440 回答