从大型 Makefile 变量创建文件

发布于 2024-07-13 22:28:33 字数 474 浏览 6 评论 0 原文

我在 Makefile 变量中有一个名为 OBJECTS 的对象列表,该变量对于命令缓冲区来说太大了。 因此,我使用以下方法创建一个列出对象的文件(以传递给 ar):

objects.lst:
    $(foreach OBJ,$(OBJECTS),$(shell echo "$(OBJ)">>$@))

虽然这有效,但速度非常慢(至少在 Cygwin 上),而且我不喜欢依赖 shell 命令和重定向。

另外, foreach 不适用于此目的 - 它在运行任何命令之前进行评估,这意味着我不能在附加之前例如 rm -f objects.lst

有没有更好的办法? 我不想使用增量归档,因为这会导致多个作业出现问题。

我唯一能想到的是用单独的脚本解析 Makefile 以读取对象列表或将对象列表存储在单独的文件中。 但这两种解决方案都有各自的问题。

I have a list of objects in a Makefile variable called OBJECTS which is too big for the command buffer. Therefore I'm using the following method to create a file listing the objects (to pass to ar):

objects.lst:
    $(foreach OBJ,$(OBJECTS),$(shell echo "$(OBJ)">>$@))

While this works it is extremely slow (on Cygwin at least) and I don't like relying on shell commands and redirection.

Additionlly foreach is not intended for this purpose - it is evaluated before any commands are run which means I can't for example rm -f objects.lst before appending.

Is there a better way? I don't want to use incremental archiving as that causes problems with multiple jobs.

The only thing I can think of is parsing the Makefile with a separate script to read the object list or storing the object list in a separate file. Both solutions have their own problems though.

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

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

发布评论

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

评论(4

夜深人未静 2024-07-20 22:28:33

尝试如下操作:

OBJECTS:=a b c d
objects.lst:
        echo > $@ <<EOF      $(OBJECTS)

即利用 shell 中内置的 < 功能。 它没有任何最大长度限制。

Try something like:

OBJECTS:=a b c d
objects.lst:
        echo > $@ <<EOF      $(OBJECTS)

i.e. make use of the <<EOF functionality that is built into the shell. It does not have any max-length limitations.

梦忆晨望 2024-07-20 22:28:33

在下面的示例中,我还用一个简单的 Perl 脚本替换了 echo,以将参数拆分为新行,但这就是它的要点。

objects.lst:
    echo $(wordlist 1,99,$(OBJECTS))>$@
    echo $(wordlist 100,199,$(OBJECTS))>>$@
    echo $(wordlist 200,299,$(OBJECTS))>>$@
    echo $(wordlist 300,399,$(OBJECTS))>>$@
    ...

In the following example I also replaced echo with a simple Perl script to split the arguments onto new lines but this is the jist of it..

objects.lst:
    echo $(wordlist 1,99,$(OBJECTS))>$@
    echo $(wordlist 100,199,$(OBJECTS))>>$@
    echo $(wordlist 200,299,$(OBJECTS))>>$@
    echo $(wordlist 300,399,$(OBJECTS))>>$@
    ...
甜`诱少女 2024-07-20 22:28:33

像这样的事情怎么样:

OBJECTS_AM=$(filter a% b% c% d% e% f% g% h% i% j% k% l% m%,$(OBJECTS))
OBJECTS_NZ=$(filter-out a% b% c% d% e% f% g% h% i% j% k% l% m%,$(OBJECTS))

objects.lst:
$(shell echo "$(OBJECTS_AM)">$@)
$(shell echo "$(OBJECTS_NZ)">>$@)

您可能需要再分割一两次,但这并没有那么糟糕,特别是因为文件名的分布不会经常改变。

How about something like this:

OBJECTS_AM=$(filter a% b% c% d% e% f% g% h% i% j% k% l% m%,$(OBJECTS))
OBJECTS_NZ=$(filter-out a% b% c% d% e% f% g% h% i% j% k% l% m%,$(OBJECTS))

objects.lst:
$(shell echo "$(OBJECTS_AM)">$@)
$(shell echo "$(OBJECTS_NZ)">>$@)

You might need to split it one or two more times, but it's not that bad, especially as the distribution of file names doesn't change all that often.

北渚 2024-07-20 22:28:33

这是 gnu make 的一个补丁,可以让您直接将变量写入文件。
它创建一个新的“writefile”函数,类似于现有的“info”函数,不同之处在于它采用文件名参数并写入文件:

https://savannah.gnu.org/bugs/?35384

Here's a patch to gnu make that lets you directly write a variable into a file.
It creates a new 'writefile' function, similar to the existing 'info' function, except it takes a filename argument and writes to the file:

https://savannah.gnu.org/bugs/?35384

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