从 bash 脚本调用 make 不会

发布于 2024-10-04 04:07:57 字数 640 浏览 2 评论 0原文

我正在编写一个 shell 脚本,它迭代一组变量,根据当前迭代值逐行编辑源文件,然后重新制作,最后调用刚刚编译的二进制文件。执行后,旧线路将恢复。

下面是一个片段:

#!/bin/sh
for i in 0..4; do
    perl -i -pe "s/.*/{SUBS[$i]}/ if $. == ${LINE[$i]}" ${SOURCE}
    make
    ./bin/myTool
    perl -i -pe "s/.*/\/\/{SUBS[$i]}/ if $. == ${LINE[$i]}" ${SOURCE}
done

基本上,我在 C++ 源文件中有大约 10 个互斥的 #define,并且我正在试验每个的效果。由于我很懒,我想让它成为一个自动化过程,但我陷入了困境。

有时,shell 会说:

`make: Nothing to be done for 'all'`

现在,我尝试在每个 perl 指令之前和之后对文件进行 diff,并且文件确实显示正确......我无法理解为什么会发生这种情况以及如何使其行为正确。

有什么想法吗?

先感谢您。

I'm writing a shell script which iterates over a set of variables, edits a source file line by line according to the current iteration value, then remakes, and finally calls the just compiled binary. After execution the old line is restored.

Here is a snippet:

#!/bin/sh
for i in 0..4; do
    perl -i -pe "s/.*/{SUBS[$i]}/ if $. == ${LINE[$i]}" ${SOURCE}
    make
    ./bin/myTool
    perl -i -pe "s/.*/\/\/{SUBS[$i]}/ if $. == ${LINE[$i]}" ${SOURCE}
done

Basically I have about 10 mutually exclusive #define in a C++ source file, and I'm experimenting the effects of each. Since I'm lazy I'd like to make it an automated process, and here I stuck.

Sometimes it happens that the shell says:

`make: Nothing to be done for 'all'`

Now, I tried to diff the file before and after every perlinstruction and the files do appear correct... I can't figure why this happens and how to make it behave correct.

Any idea?

Thank you in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

妄想挽回 2024-10-11 04:07:57

它可能循环得太快,以至于 make 无法区分每次迭代。删除制造产品或在循环开始或结束时添加 2 秒的延迟。

It's probably looping too quickly for make to tell each iteration apart. Either remove the make products or add a delay of 2 seconds at the beginning or end of the loop.

难如初 2024-10-11 04:07:57

Make 仅检查目标时间戳是否比源时间戳更年轻。这是它知道需要更新哪些内容的唯一方法。因此,如果循环迭代花费的时间少于一秒,那么 make 将不知道任何内容发生了变化。

您可以在每次迭代的顶部进行清理,也可以像 Ignacio Vazquez-Abrams 指出的那样添加延迟。

Make only checks if the target timestamp is younger than the source timestamp. That's the only way it can know what needs to be updated. So, if you loop iterations take less than a second then make won't know that anything has changed.

You can either clean up at the top of each iteration or add a delay as Ignacio Vazquez-Abrams has noted.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文