2015-06-20 73 views
-1

我在make文件下面的代码:不能make文件编辑字符串

All:CheckOutFolder 
echo "Starting Build"; 
@for entry in ${DIR};          \ 
do               \ 
    for i in $${entry}/*.[cs];        \ 
    do              \ 
    echo "Bulding $${i}";         \ 
    arm-none-eabi-gcc ${OPT} $${i} -c -o ${OUT}/${${$${i}##*/}:-1}.o; \ 
    done             \ 
done 

的问题是,${${$${i}##*/}:-1}.o产生空字符串。

任何人都可以帮忙吗?

+0

你不应该问同样的问题两次,而是编辑你的其他问题“在makefile中操纵字符串”。 – Jens

回答

1

这里有一个概念上的问题:你在shell中运行的代码中混合Make函数。诸如FILE=$(notdir $(i))之类的东西将在shell脚本运行之前扩展一次,而不是在shell脚本中的每个循环迭代中。

相反,通常所做的就是展开你想在目标之外迭代的东西列表,这个东西开始于@forforeach函数可以帮助你。

最后,remake写入这些类型的问题。它有一个调试器。因此,您可以停止目标“全部”并写出可以运行的代码。然后更清楚的是像“notdir”和“substr”这样的函数不会出现在运行的shell代码中。

remake -X Makefile All 
GNU Make 4.1+dbg0.91 
... 
Updating goal targets.... 
remake: Nothing to be done for 'Makefile'. 
-> (/tmp/Makefile:2) 
All: 
remake<0> write 
File "/tmp/All.sh" written. 

现在看/tmp/All.sh:

#!/bin/sh 
#/tmp/Makefile:2 
#cd /tmp 
echo "Starting Build"; 
@for entry in ;          \ 
    do               \ 
     for i in ${entry}/*.[cs];        \ 
     do              \ 
     echo "Bulding ${i}";         \ 
     FILE=;       \ 
     FILE= ;          \ 
     echo "";           \ 
     arm-none-eabi-gcc ${i} -c -o /; \ 
     done             \ 
    done 

在上述例子尝试一些东西, 我看到翻拍的“设置”命令有错误,SEGVs,我有时会进行调查。 (错误修复在remake-4.1 + dbg1.1中)

+0

我编辑了我的代码,你能告诉我为什么'$ {$ {$$ {i} ## * /}: - 1} .o'只生成名为“.o”的文件 –

+0

我觉得更有意思的是,如果你可以通过使用重拍来告诉自己。试试看,让我知道那是怎么回事。 'eval','expand'和'print'命令在这里是你的朋友。 – rocky