在 Makefile 中,.env
文件通常用于存储环境变量的配置。通过 include .env
命令,Makefile 可以将 .env
文件的内容引入当前的 Makefile,这样就可以在 Makefile 中直接使用这些环境变量了。
export
语句在 shell 环境中用来导出一个环境变量,使其可以在子 shell 中生效。在 Makefile 中,如果你使用了 export
来定义环境变量,那么这些变量将会在 Makefile 执行时被导出,并且可以在 Makefile 内部使用这些环境变量。
例如:
# .env 文件内容示例
DJANGO_SECRET_KEY=your_secret_key
DATABASE_URL=postgres://user:pass@localhost/dbname
# Makefile 使用 .env 文件
include .env
# Makefile 内部使用环境变量
echo $DJANGO_SECRET_KEY # 输出 your_secret_key
echo $DATABASE_URL # 输出 postgres://user:pass@localhost/dbname
在这个例子中,.env
文件中的变量被引入到 Makefile 中,并且通过 export
语句导出了这些变量,所以在 Makefile 内部可以直接访问这些变量。