# makefile
SHELL:=/bin/bash
PATH:=/path/to/new/programs:$(PATH)
my_var:=$(shell which program)
rule:
echo $(my_var)
which program
#output
$: make rule
echo
which program
/path/to/program
# prints nothing
我已经尝试了所有方法,实际上还记得在我之前创建 makefile 时如何让它工作。它正在变成一个泥潭——我需要做的就是在安装它之前检查它是否存在。
最佳答案
如果您不在 makefile 中设置 SHELL
变量,显式 which
是否有效?
设置SHELL
变量只会影响配方。它不用于 $(shell ...)
函数。您可以使用:
my_var := $(shell /bin/bash -c 'which function')
但是在我的系统上,即使使用默认 shell 也可以使用 which
。也许您的系统有所不同。
当然要注意哪个
找到程序,而不是函数...
关于c++ - 制作 : variable fails to assign from shell call,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50727687/