Create a file from a large Makefile variable

I have a list of objects in a Makefile variable named OBJECTS that is too large for the command buffer. Therefore, I use the following method to create a file listing objects (to go to ar):

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

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

Complementary foreach is not intended for this purpose - it is evaluated before any commands are run, which means that I cannot, for example, rm -f objects.lstbefore adding.

Is there a better way? I do not want to use incremental archiving, as this causes problems with multiple jobs.

The only thing I can think of is parsing the Makefile using a separate script to read a list of objects or store a list of objects in a separate file. Both solutions have their own problems.

+3
source share
4 answers

In the following example, I also replaced echo with a simple Perl script to split the arguments into new lines, but that is its essence.

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

Try something like:

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

i.e. use the functionality <<EOFbuilt into the shell. It has no restrictions on the maximum length.

+1
source

- :

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)">>$@)

, , , , .

0

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

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

0
source

Source: https://habr.com/ru/post/1702707/


All Articles