Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create a file from a large Makefile variable

Tags:

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.

like image 233
Martin Fido Avatar asked Dec 20 '25 09:12

Martin Fido


2 Answers

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.

like image 174
an0nym0usc0ward Avatar answered Dec 24 '25 12:12

an0nym0usc0ward


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))>>$@
    ...
like image 32
Martin Fido Avatar answered Dec 24 '25 11:12

Martin Fido



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!