是否有一种简单的方法可以将包含本地配置的文件自动加载到 Makefile
中? ?
我有一个文件,.env
,包含 key=value
每行成对:
var1=val1
var2=val2
目前我正在将每个变量导入我的
Makefile
像这样手动: var1=$$(grep '^var1=' .env | cut -d= -f2-)
当添加更多变量时,这感觉很笨拙并且容易出错。
我还尝试向
Makefile
添加一个额外的目标。阅读 .env
的每一行并将其传递给 export
,但在一个目标中导出的值对其他目标不可用。我希望在
make
中有一个内置功能可以执行此操作,但我一直无法找到它的文档。
最佳答案
假设您的包含文件完全由有效的 make 分配组成,那么 include
directive很可能是你想要的。
The include directive tells make to suspend reading the current makefile and read one or more other makefiles before continuing. The directive is a line in the makefile that looks like this:
include filenames…
filenames can contain shell file name patterns.
关于makefile - 在 Makefile 中加载 .env 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30300830/