[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Writing contents of large variable into a file
From: |
John Graham-Cumming |
Subject: |
Re: Writing contents of large variable into a file |
Date: |
Fri, 18 Feb 2005 10:48:35 -0500 |
On Fri, 2005-02-18 at 10:56 +0100, address@hidden wrote:
> Unfortunately I could not figure out how to write the content of JAVA_SRCS
> into a file without running into the shell limit:
>
> make: execvp: /bin/sh.exe: Argument list too long
> make: *** [compile] Error 127
So imagine that what you want to do is this:
$(shell echo $(TOO_LONG) > long_file)
But can't because you hit a limit in the shell.
A slow way to handle this would be
$(shell rm -f long_file)$(foreach w,$(TOO_LONG),$(shell echo -n
"$w " >> long_file))
But that's very slow because there's a shell invocation per word in
TOO_LONG. So the right way to do this is to write a function that
breaks the long list of words at a fixed point and writes out lines to
the file iteratively.
Like this (in GNU Make 3.80 and above):
write-var-to-file=$(strip $(shell rm -f $1)$(eval __a :=)$(foreach
w,$($2),$(if $(filter $3,$(words $(__a))),$(shell echo -n "$(strip
$(__a)) " >> $1)$(eval __a:=))$(eval __a +=$w))$(shell echo $(__a)
>> $1))
write-var-to-file has three arguments: the name of the file to be
written, the name of the variable to write and the number of words to
gather up before writing to the file.
e.g. $(call write-var-to-file,long_file,TOO_LONG,200)
would write out the contents of TOO_LONG performing a shell echo every
200 words to a file call long_file.
John.
--
John Graham-Cumming
Home: http://www.jgc.org/
Work: http://www.electric-cloud.com/
POPFile: http://getpopfile.org/
GNU Make Standard Library: http://gmsl.sf.net/