无法编辑make文件中的字符串

时间:2015-06-20 16:56:01

标签: shell makefile

我在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生成空字符串。

有人可以帮忙吗?

1 个答案:

答案 0 :(得分:1)

这里有一个概念性问题:您正在将函数混合在shell中运行的代码中。在运行shell脚本之前,FILE=$(notdir $(i))之类的内容将一次扩展,而不是在shell脚本内的每次循环迭代中。

相反,通常做的是扩展您想要在目标之外迭代的事物列表,即启动@for的事物。 foreach功能可以帮助您。

最后,正是针对这些问题编写了remake。它有一个调试器。所以你可以停下目标&​​#34; All"并写出将要运行的代码。然后更清楚的是像" 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

在上面的例子中尝试了一些事情,我看到重拍&#34;设置&#34;命令有一个SEGV的错误,我将在某个时候查看。(在remake-4.1 + dbg1.1中修复了错误)