Assign variable once when first used in Makefile [duplicate]
up vote
2
down vote
favorite
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 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 |
up vote
2
down vote
favorite
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 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 at 14:23
add a comment |
up vote
2
down vote
favorite
up vote
2
down vote
favorite
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 at 2:38
tekumara
5,06264058
5,06264058
marked as duplicate by Renaud Pacalet, Community♦ Nov 21 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 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 at 14:23
add a comment |
1
A longer writeup is here: make.mad-scientist.net/deferred-simple-variable-expansion
– MadScientist
Nov 18 at 14:23
1
1
A longer writeup is here: make.mad-scientist.net/deferred-simple-variable-expansion
– MadScientist
Nov 18 at 14:23
A longer writeup is here: make.mad-scientist.net/deferred-simple-variable-expansion
– MadScientist
Nov 18 at 14:23
add a comment |
1 Answer
1
active
oldest
votes
up vote
-1
down vote
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
up vote
-1
down vote
Move the assignment inside the recipe
test:
FILES=$$(ls) ;
echo $$FILES one ;
echo $$FILES two
add a comment |
up vote
-1
down vote
Move the assignment inside the recipe
test:
FILES=$$(ls) ;
echo $$FILES one ;
echo $$FILES two
add a comment |
up vote
-1
down vote
up vote
-1
down vote
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 at 7:21
user657267
17.2k52958
17.2k52958
add a comment |
add a comment |
1
A longer writeup is here: make.mad-scientist.net/deferred-simple-variable-expansion
– MadScientist
Nov 18 at 14:23