[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: $(file ...) function and other tools writing to the same file
From: |
Martin Reinders |
Subject: |
Re: $(file ...) function and other tools writing to the same file |
Date: |
Mon, 14 Mar 2016 14:53:18 +0100 |
User-agent: |
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:31.0) Gecko/20100101 Thunderbird/31.7.0 |
On 14.03.16 14:43, Paul Smith wrote:
> On Mon, 2016-03-14 at 14:32 +0100, Martin Reinders wrote:
>> $ cat Makefile
>> all:
>> /bin/echo "LINE FROM ECHO COMMAND" > file.txt
>> $(file >>file.txt,LINE FROM FILE FUNCTION)
>
>> I expected that the echo command writes one line to the file, and the
>> $(file ...) function appends another line. But as one can see, the
>> file contains the output from the echo command only. It seems to me
>> that the echo command is executed _after_ executing the $(file ...)
>> function.
>
>> Perhaps I am misunderstanding something completely? Any insight is
>> highly appreciated.
>
> The thing you're missing is that GNU make will always expand the ENTIRE
> recipe, before it starts ANY part of the recipe. So, all variables and
> functions, including $(file ...), will be expanded first, then make will
> start to run the recipe lines. So the $(file ...) function happens
> before the echo command, as you've seen.
>
That makes perfect sense, thank you very much!