gnu make:如何处理用$(文件)创建的文件列表?

发布于 2025-01-28 23:01:12 字数 502 浏览 1 评论 0原文

在制造变量中有一个文件列表。一个命令行的文件列表太长。列表可以写入带有$(文件)make函数的文件中。 $(文件)始终附加一个newline,因此列表文件最终将包含一个分离的文件名列表和newline。 问题:如何在配方中使用bash命令处理这件事? 我尝试了一些常见的解决方案:

while read -r -d ' ' l; do echo $l; done <listfile

这不会处理最后一个文件,因为之后没有空间。可以在创建文件之前附加一个空间,但是NewLine将被解释为文件名,并且命令失败。

xargs -n 1 -d " " -i echo {} <listfile

同样的问题:结尾处的新线被解释为文件名。

由于这是Makefiles中的一项常见任务,因此应该有一个简单有效的解决方案。该解决方案应在cygwin/msys2/ezwinports下起作用,cr/lf应该无关紧要。有什么想法比用TR删除新线更好吗?

There is a file list in a make variable. The file list is too long for one command line. The list can be written into a file with the $(file) make function.
$(file) always appends a newline, so eventually the list file will contain a space separated list of filenames and a newline at the end.
Question: how can this be processed with bash commands in a recipe?
I tried some common solutions:

while read -r -d ' ' l; do echo $l; done <listfile

This won't process the last file, as there is no space after it. A space can be appended before creating the file, but then the newline will be interpreted as a filename and the command fails.

xargs -n 1 -d " " -i echo {} <listfile

Same issue: the newline at the end is interpreted as a filename.

Since this is quite a common task in makefiles, there should be a simple and efficient solution. The solution should work under Cygwin/MSYS2/EZWinPorts, CR/LF should not matter. Any ideas better than removing the newline with tr?

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

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

发布评论

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

评论(1

脱离于你 2025-02-04 23:01:12

一个可能的解决方案是使用Make创建一个Newline分离列表。我通过删除列表文件来做到这一点,然后

$(foreach f,$(file_list),$(file >>listfile,$f))

内部$(文件)函数应比调用外部工具更快 - 只要不需要称为300次。在单个$(文件)内实现$(foreach)可能会更有效,但是需要明确指定CR/LF,谁知道它对Xargs是否有益。这样,它应该在整个工具链中保持一致。
可以以这种方式处理文件列表:

xargs -a filelist -i do_something {}

用Cygwin和MSYS2进行测试。

A possible solution is creating a newline separated list with make. I did that with deleting the list file and then

$(foreach f,$(file_list),$(file >>listfile,$f))

The internal $(file) function should be faster than calling external tools - as long as it does not need to be called 300 times. Implementing the $(foreach) inside a single $(file) might be more efficient, but then the CR/LF would need to be specified explicitly, and who knows whether it's good for xargs. This way it should be consistent across the toolchain.
The file list can be processed this way:

xargs -a filelist -i do_something {}

Tested with Cygwin and MSYS2.

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