我在 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.
发布评论
评论(4)
尝试如下操作:
即利用 shell 中内置的
< 功能。 它没有任何最大长度限制。
Try something like:
i.e. make use of the
<<EOF
functionality that is built into the shell. It does not have any max-length limitations.在下面的示例中,我还用一个简单的 Perl 脚本替换了 echo,以将参数拆分为新行,但这就是它的要点。
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..
像这样的事情怎么样:
您可能需要再分割一两次,但这并没有那么糟糕,特别是因为文件名的分布不会经常改变。
How about something like this:
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.
这是 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