首次在Makefile

时间:2018-11-18 02:38:10

标签: makefile gnu-make

如何仅在变量扩展中仅在首次使用变量时调用一次make shell函数?我不想在声明时使用:=进行扩展(即简单扩展),因为扩展非常昂贵,而且只有一些目标需要变量。

我尝试使用条件变量赋值,但是它每次都会调用shell,例如,以下两次调用shell ls

.PHONY: test

FILES ?= $(warning Invoking the shell)$(shell ls)

test:
    echo $(FILES) one
    echo $(FILES) two

1 个答案:

答案 0 :(得分:-1)

将任务移到食谱中

test:
    FILES=$$(ls) ;\
    echo $$FILES one ;\
    echo $$FILES two