Re: Deferred->immediate variable reassignment trick.

Paul Smith <[email protected]>
Newsgroups gmane.comp.gnu.make.general
Organization GNU's Not UNIX!
Message-ID <[email protected]>
On Tue, 2023-06-20 at 11:46 -0700, Kaz Kylheku wrote:
> I used a trick in a makefile along the following pattern. It works
> fine.  I'm just circulating it for any comments/discussion. 
> 
>   # Delayed evaluation on purpose: 
> 
>   IMPORTANT_VAR = $(shell $CODE_TO_CALCULATE_IMPORTANT_VAR) 
> 
>   # Force lazy variable to be eager: 
> 
>   IMPORTANT_VAR := $(IMPORTANT_VAR) 
> 
> The requirements being hit here are: 
> 
> 1. We want the user to be able to override IMPORTANT_VAR from the
> command line. When the user overrides IMPORTANT_VAR, the shell
> command must not be executed. 
> 
> 2. We don't want every substitution of $(IMPORTANT_VAR) to be running
> the shell command.

I don't understand how this is different than just:

    IMPORTANT_VAR := $(IMPORTANT_VAR)

If the user specifies an override of the variable on the command line
then the value in the makefile will never be used, so the shell command
will never be invoked.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.