Created
March 10, 2021 10:36
-
-
Save majest/7b0ed4d8a62a644f49ebd89af37f6353 to your computer and use it in GitHub Desktop.
How to load environemnt variables in Makefile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Makefile | |
This loads the env file and evaluates the export from it | |
so that those envs are available in environment and makefile itself. | |
It will try to load a file $path/.local.env | |
Good for the Makefile IF you DON'T use multiline vars | |
If you have multilines, use a different solution than loading env vars | |
via Makefile or `source .env` manually | |
``` | |
define setup_env | |
$(eval ENV_FILE := $(2)/.$(1).env) | |
@echo " - Setting up env $(ENV_FILE). Environment variables loaded" | |
$(eval export sed 's/=.*//' $(2)/.$(1).env) | |
$(eval include $(2)/.$(1).env) | |
endef | |
load-dev: ## Initialises dev environment | |
$(call setup_env,local,path) | |
``` | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment