|
发表于 2009-6-11 09:34:49
|
显示全部楼层
Post by tongnaikun;1996359
result:=
all :
$(result) = $(subst a,A,how are you,china?)
echo -n "the result is:"
echo $(result)
.PHONY: all
运行make命令后显示如下:
= how Are you,chinA?
/bin/sh: =: not found
make: *** [all] Error 127
Makefile 中变量与一般脚本中的变量不一样, 它们更适合用宏替换的方式来理解. 楼主在 all: 的第一行中 '$(result) = ...' 是如何被处理的呢? 它就是替换成 ' = ...', 而不是按照楼主的期望,改变了 result 的值.
那么这种情况我们一般如何处理呢, 一般我们是用 shell 的环境变量来处理的
- all :
- @RESULT="$(subst a,A,how are you,china?)"; \
- echo -n "the result is:"; \
- echo $$RESULT;
- .PHONY: all
复制代码
或者
- result := $(subst a,A,how are you,china?)
- all :
- @echo -n "the result is:"
- @echo $(result)
- .PHONY: all
复制代码 |
|