How can I write the contents of a makefile to a file without invoking a shell command? The problem is that the contents of the variable are possible longer than the shell allows the command (i.e. longer than the characters MAX_ARG_STRLEN (131072)).
In particular, in the makefile, I have a variable containing a long list of file names to process (including their absolute templates for assembly outside the source). Now I need to write these file names to a (temporary) file, which I can then transfer to another command.
So far, we had a rule like ( $COLLATED_FILES is a variable containing paths):
$(outdir)/collated-files.tely: $(COLLATED_FILES) $(LYS_TO_TELY) --name=$(outdir)/collated-files.tely --title="$(TITLE)" \ --author="$(AUTHOR)" $^
This breaks if COLLATED_FILES longer than 130,000 characters, we get an error message:
make[2]: execvp: /bin/sh: Argument list too long
As a solution, we are now trying to write the contents of the variable to a file and use this file in the $(LYS_TO_TELY) . Unfortunately, I have not yet found a way to do this without invoking the shell. My attempts include:
$(outdir)/collated-files.list: $(COLLATED_FILES) echo "" > $@ $(foreach f,$^,echo $f >> $@ ;)
But it also calls all echo once in the shell, so the shell command is just as long.
Is there a way to write the contents of $(COLLATED_FILES) to a file on disk without passing them on the command line to a shell command?
I also searched if I could pass the contents of the variable to the shell, but I could not find anything in that direction ...