tags:

views:

295

answers:

3

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.

+1  A: 

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.

an0nym0usc0ward
A: 

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.

florin
Thanks for this, it inspired my own solution using wordlist, which ensures a consistent number of objects in each variable.
Martin Fido
A: 

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))>>$@
    ...
Martin Fido