[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Evaluating a variable only once after a recipe has run
From: |
Kaz Kylheku (gmake) |
Subject: |
Re: Evaluating a variable only once after a recipe has run |
Date: |
Sat, 18 Apr 2020 06:35:24 -0700 |
User-agent: |
Roundcube Webmail/0.9.2 |
On 2020-04-18 05:55, R. Diez wrote:
Even if it were available, you
would not want to run expensive shell commands to define a variable
that is actually never used if the user did not specify a makefile
target that needs it.
I will rephrase the question just in case it is not clear. I want GNU
Make to run recipe A, and then use the result of recipe A to compute
the value of a makefile variable, but only once. Other recipes that
follow should use that value without evaluating the variable
definition again.
That's typically the job of a configure script. A configure
script can rely on special targets in the Makefile for doing some of
its probing. It deposits its results in an include makefile
like "config.make".
Instead of trying to uses the execution of a target recipe to try to
calculate this optimized variable (which isn't how make works,
and will likely be fruitless) you can calculate it using a conditional
expression which looks for the presence of that target in
$(MAKECMDGOALS).
THAT_VAR := $(if $(filter that-target,$(MAKECMDGOALS)),$(shell ...))
In fact MAKECMDGOALS can even be tested with ifeq/ifneq to conditionally
include makefile text:
ifneq($(filter that-target,$(MAKECMDGOALS)),)
# chunk of makefile syntax here
THAT_VAR := $(subst ... $(shell ...))
endif
- Evaluating a variable only once after a recipe has run, R. Diez, 2020/04/18
- Re: Evaluating a variable only once after a recipe has run,
Kaz Kylheku (gmake) <=
- Re: Evaluating a variable only once after a recipe has run, R. Diez, 2020/04/18
- Re: Evaluating a variable only once after a recipe has run, Kaz Kylheku (gmake), 2020/04/18
- Re: Evaluating a variable only once after a recipe has run, R. Diez, 2020/04/18
- Re: Evaluating a variable only once after a recipe has run, R. Diez, 2020/04/18
- Re: Evaluating a variable only once after a recipe has run, Paul Smith, 2020/04/18
- Re: Evaluating a variable only once after a recipe has run, R. Diez, 2020/04/18
- Re: Evaluating a variable only once after a recipe has run, Paul Smith, 2020/04/18
Re: Evaluating a variable only once after a recipe has run, Paul Smith, 2020/04/18