[Gllug] GNU make expert question: write variable value to a file

Stig Brautaset gllug at brautaset.org
Sun Mar 2 09:28:28 UTC 2003


On Mar 02 2003, Pete wrote:
> On Sat, Mar 01, 2003 at 06:12:33PM +0000, rich at annexia.org wrote:
> > How do I write the value of a makefile variable to a named file?
> 
> file: Makefile
> 	echo "$foo" > $@

Nah. That's why it's an expert question I guess :) 

First, that's not how you dereference multi-character variables in
Makefiles. You use $(foo). I suspect you knew that by the way :)

If he has a variable defined like so:

define foo
hello
world
endef

Then it is a compound definition which will be expanded literally on use
like so:

file: Makefile
	echo "hello
	world"

Resulting in _two_ errors, because make starts a new shell for each
line. Thus, you get error for missing quote on the line containing echo,
and "no command" and/or missing quote for the second line too. Leaving
out the quotes doesn't make it much better; this results in `hello'
being echo'd out correctly, but the line `hello' is interpreted as a
command and you get a `make: world: Command not found' error.

I wasn't able to solve the problem without exporting the variable and
printing it from a script either :( 

Stig
-- 
brautaset.org

-- 
Gllug mailing list  -  Gllug at linux.co.uk
http://list.ftech.net/mailman/listinfo/gllug




More information about the GLLUG mailing list