今天在写Makefile时,忽然遇到了一个问题,如何把几个字符串无缝的连接起来?我自然而然的想到了使用 +=。比如:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
laolang@laolang:~
/code/gongda/data_java/test
$
cat
test
.mk
1 one:=123
2 two:=345
3 three:=567
4
5 final+=$(one)
6 final+=$(two)
7 final+=$(three)
8
9 list:
10 @
echo
-n
"0"
11 @
echo
-n $(final)
12 @
echo
"0"
laolang@laolang:~
/code/gongda/data_java/test
$
laolang@laolang:~
/code/gongda/data_java/test
$
make
-f
test
.mk
123 345 567
laolang@laolang:~
/code/gongda/data_java/test
$
|
这显示不是我想要的结果,我想要的结果是输出:01233455670
但是它给我多了几个空格,于是我又查在shell script中如何做到这样无缝的连接字符串,于是我找到了如下例子:
1
2
3
4
5
|
[root@localhost sh]
# var1=/etc/
[root@localhost sh]
# var2=yum.repos.d/
[root@localhost sh]
# var3=${var1}${var2}
[root@localhost sh]
# echo $var3
/etc/yum
.repos.d/
|
于是我的test.mk成了:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
laolang@laolang:~
/code/gongda/data_java/test
$
make
-f
test
.mk
01233455670
laolang@laolang:~
/code/gongda/data_java/test
$
cat
test
.mk
1 one:=123
2 two:=345
3 three:=567
4
5 final:=$(one)$(two)$(three)
#关键行
6
7 list:
8 @
echo
-n
"0"
9 @
echo
-n $(final)
10 @
echo
"0"
laolang@laolang:~
/code/gongda/data_java/test
$
make
-f
test
.mk
01233455670
//
现在达到了我想要的效果
laolang@laolang:~
/code/gongda/data_java/test
$
|
FROM: http://my.oschina.net/iamhere/blog/356842