bug-make
[Top][All Lists]
Advanced

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

Re: $(file) function bug or not?


From: Paul Smith
Subject: Re: $(file) function bug or not?
Date: Tue, 28 Jan 2014 10:13:18 -0500

On Tue, 2014-01-28 at 15:50 +0100, Gisle Vanem wrote:
> I'm trying to understand if my use of the $(file..) function is correct or 
> not. Based on tests/scripts/function/file, I cooked up this little file.mak:

It's not correct.  Or rather, the use of $(file ...) is correct, but not
the surrounding rules.

> .PHONY: file_test
> file_test:
>   rm file.out
>   $(file > file.out, "Hello")
>   $(file >> file.out, "world")
>   @echo 'abspath file.out: $(abspath file.out).'

This won't work, because you're mixing make syntax with shell syntax.
Remember it's not _make_ that's running the rm or the echo, it's the
shell.  And the shell is invoked AFTER all the make variables and
functions are expanded by make.

So first make expands the recipe, which includes the $(file ...)
function and creates the file.  The function expands to the empty
string.

Then make invokes the shell with the results of the expansion, which are
the rm and echo commands (and some empty strings which are ignored).

So, the rm is running AFTER the file is created, and deleting it.




reply via email to

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