help-make
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: getting the value of a make variable into a file


From: Michael Stahl
Subject: Re: getting the value of a make variable into a file
Date: Fri, 08 Apr 2011 13:28:46 +0200
User-agent: Thunderbird 2.0.0.23 (X11/20090910)

On 07/04/2011 21:34, Adam Kellas wrote:
> Is there by any chance a clever way of getting the value of a variable
> into a file without exposing it to a shell? Eg some variant of
> 
> foo:
>         @echo $(var) > file
> 
> I have some text which is potentially quite convoluted with single and
> double quotes and backslashes and literal $ and so on. It needs to get
> into a file and I'm fighting with shell and make escaping rules to
> make it work. But if there's some cute trick which can avoid all that
> and, from within make, open the file and write $(var) to it, I'd be
> grateful to know it.
> 
> Thanks in advance,
> AK

that's a very good question.
we would also like a convenient solution for this, for different reasons:
our variables tend to contain values that are larger than the command line
length limit on certain platforms.

the ugly hack we currently use to work around this is here:
http://svn.services.openoffice.org/opengrok/xref/Current%20%28trunk%29/solenv/gbuild/Tempfile.mk

one advantage of our old dmake tool that we are currently replacing with
GNU make is that it had a built-in function for this purpose.

$(mktmp foo $(bar) baz)
this would create a new temp file, expand all the parameters of the mktmp
("foo $(bar) baz") and then write the result to the temp file.
the path of the temp file is returned.
in this case, the temp file is automatically removed.

$(mktmp)
this would create a new temp file, and return its path.
the temp file is not automatically removed.

as you can see this is much nicer and probably also much faster than the
Tempfile.mk hack, which basically chops up the string into chunks, and
invokes a shell to write each chunk.
a similar function in GNU make (not necessarily with the same semantics)
would be much appreciated.

regards,
 michael

-- 
"The secret to creativity is knowing how to hide your sources."
 -- Albert Einstein




reply via email to

[Prev in Thread] Current Thread [Next in Thread]