3

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
tekumara
  • 8,357
  • 10
  • 57
  • 69

1 Answers1

-1

Move the assignment inside the recipe

test:
    FILES=$$(ls) ;\
    echo $$FILES one ;\
    echo $$FILES two
user657267
  • 20,568
  • 5
  • 58
  • 77