Assign variable once when first used in Makefile [duplicate]
This question already has an answer here:
How to get “at most once” semantics in variable assignments?
2 answers
How do I only invoke a make shell
function once in a variable expansion, and only when the variable is first used? I don't want to use :=
to expand at declaration time (ie: simple expansion) because the expansion is expensive and only some of my targets need the variable.
I tried using conditional variable assignment but it invokes the shell every time, for example, the following invokes shell ls
twice:
.PHONY: test
FILES ?= $(warning Invoking the shell)$(shell ls)
test:
echo $(FILES) one
echo $(FILES) two
makefile gnu-make
marked as duplicate by Renaud Pacalet, Community♦ Nov 21 '18 at 6:54
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
This question already has an answer here:
How to get “at most once” semantics in variable assignments?
2 answers
How do I only invoke a make shell
function once in a variable expansion, and only when the variable is first used? I don't want to use :=
to expand at declaration time (ie: simple expansion) because the expansion is expensive and only some of my targets need the variable.
I tried using conditional variable assignment but it invokes the shell every time, for example, the following invokes shell ls
twice:
.PHONY: test
FILES ?= $(warning Invoking the shell)$(shell ls)
test:
echo $(FILES) one
echo $(FILES) two
makefile gnu-make
marked as duplicate by Renaud Pacalet, Community♦ Nov 21 '18 at 6:54
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
1
A longer writeup is here: make.mad-scientist.net/deferred-simple-variable-expansion
– MadScientist
Nov 18 '18 at 14:23
add a comment |
This question already has an answer here:
How to get “at most once” semantics in variable assignments?
2 answers
How do I only invoke a make shell
function once in a variable expansion, and only when the variable is first used? I don't want to use :=
to expand at declaration time (ie: simple expansion) because the expansion is expensive and only some of my targets need the variable.
I tried using conditional variable assignment but it invokes the shell every time, for example, the following invokes shell ls
twice:
.PHONY: test
FILES ?= $(warning Invoking the shell)$(shell ls)
test:
echo $(FILES) one
echo $(FILES) two
makefile gnu-make
This question already has an answer here:
How to get “at most once” semantics in variable assignments?
2 answers
How do I only invoke a make shell
function once in a variable expansion, and only when the variable is first used? I don't want to use :=
to expand at declaration time (ie: simple expansion) because the expansion is expensive and only some of my targets need the variable.
I tried using conditional variable assignment but it invokes the shell every time, for example, the following invokes shell ls
twice:
.PHONY: test
FILES ?= $(warning Invoking the shell)$(shell ls)
test:
echo $(FILES) one
echo $(FILES) two
This question already has an answer here:
How to get “at most once” semantics in variable assignments?
2 answers
makefile gnu-make
makefile gnu-make
asked Nov 18 '18 at 2:38
tekumaratekumara
5,14774058
5,14774058
marked as duplicate by Renaud Pacalet, Community♦ Nov 21 '18 at 6:54
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
marked as duplicate by Renaud Pacalet, Community♦ Nov 21 '18 at 6:54
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
1
A longer writeup is here: make.mad-scientist.net/deferred-simple-variable-expansion
– MadScientist
Nov 18 '18 at 14:23
add a comment |
1
A longer writeup is here: make.mad-scientist.net/deferred-simple-variable-expansion
– MadScientist
Nov 18 '18 at 14:23
1
1
A longer writeup is here: make.mad-scientist.net/deferred-simple-variable-expansion
– MadScientist
Nov 18 '18 at 14:23
A longer writeup is here: make.mad-scientist.net/deferred-simple-variable-expansion
– MadScientist
Nov 18 '18 at 14:23
add a comment |
1 Answer
1
active
oldest
votes
Move the assignment inside the recipe
test:
FILES=$$(ls) ;
echo $$FILES one ;
echo $$FILES two
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Move the assignment inside the recipe
test:
FILES=$$(ls) ;
echo $$FILES one ;
echo $$FILES two
add a comment |
Move the assignment inside the recipe
test:
FILES=$$(ls) ;
echo $$FILES one ;
echo $$FILES two
add a comment |
Move the assignment inside the recipe
test:
FILES=$$(ls) ;
echo $$FILES one ;
echo $$FILES two
Move the assignment inside the recipe
test:
FILES=$$(ls) ;
echo $$FILES one ;
echo $$FILES two
answered Nov 18 '18 at 7:21
user657267user657267
17.3k53160
17.3k53160
add a comment |
add a comment |
1
A longer writeup is here: make.mad-scientist.net/deferred-simple-variable-expansion
– MadScientist
Nov 18 '18 at 14:23