曲径通幽论坛

标题: 关于 U-Boot Makefile 中的 $(@:_config=) 变量的说明 [打印本页]

作者: beyes    时间: 2011-1-21 18:24
标题: 关于 U-Boot Makefile 中的 $(@:_config=) 变量的说明
U-Boot 版本:1.1.6
在 U-Boot 的 Makefile 里有这么一个变量:
sbc2410x_config: unconfig
        @$(MKCONFIG) $(@:_config=) arm arm920t sbc2410x NULL s3c24x0
那这个变量是什么意思呢?下面先看一个 Makefile 文件的例子:
STRING = hello world
all:
        @echo $(STRING)
        @echo $(STRING:world=Makefile)
运行输出:
$ make
hello world
hello Makefile
由输出的第 2 行可以看到 world 替换成 Makefile 了! 也就是说,在 STRING 变量中匹配到 world 的字符串会被 '=' 号后面的字符串所替换。
从这里,可以看到变量的另外一种用法:
$(var:string1=string2)
其意是,将变量 var 中的匹配 string1 的字符串替换为字符串 string2 。
注意:string1 要是匹配到整个变量末尾的字符串,而不是中间的某部分,否则替换失败,变量仍然保持
比如说,当我们更改上面的 @echo $(STRING:world=Makefile) 改成 @echo $(STRING:wor=Makefile),那么输出:
$ make
hello world
hello world
由上面的示例,我们已经猜到 U-BOOT 中的 $(@:_config=) 的用法:
在 $(@:_config=) 中,$@ 表示所有的目标文件。也就是说,原先生成的目标文件的文件名末尾是 "_config" 字符串,而 '=' 号后为空,表示去掉 _config 这部分。
比如有 Makefile 文件内容如下:
hello_config: hello.o
        gcc -o $(@:_config=) $^
hello.o: hello.c
        gcc -Wall -c hello.c -o hello.o

make 后输出:
t$ ls
hello  hello.c  hello.h  hello.o  Makefile
从这里可见,原本要输出的目标文件 hello_config 的可执行文件被改名为 hello 。




欢迎光临 曲径通幽论坛 (http://www.groad.net/bbs/) Powered by Discuz! X3.2