It is very easy to achive that in make:
# Makefile
include .$(PWD)/.env
That's all. You can now access your env vars in make targets:
# Makefile
include .$(PWD)/.env
dummy-target:
@echo $(SOME_ENV_VAR)
Sub-make
If want to you pass all your environment variables into Sub-make
you should export
them:
# Makefile
ENV := $(PWD)/.env
# Environment variables for project
include $(ENV)
# Export all variable to sub-make
export
Multiple Files
You can use multiple env files and their names can be anything:
# Variables
# -------------------------------------------------------------------------------------
VENV := $(PWD)/.venv
ENV := $(PWD)/.env
ENVS := $(PWD)/.envs
# Environment variables for project
include $(ENV)
# Local environment variables for db
include $(ENVS)/.postgres
include $(ENVS)/.redis
# Export all variable to sub-make
export
All done.
Top comments (1)
Downside to this is that
.env
syntax is not a subset of theMakefile
syntax because there are certain symbols allowed in.env
, which make requires to be escaped. For example the symbols:#
and$
.Also the fact that make treats tab as special means that it will attempt to interpret tabs as meaningful inside
.env
files