diff --git a/knowledge base/gnu userland/make.md b/knowledge base/gnu userland/make.md index 4aa24e1..22e21f4 100644 --- a/knowledge base/gnu userland/make.md +++ b/knowledge base/gnu userland/make.md @@ -13,6 +13,12 @@ override override_me ?= default_value +# Load env files. +# If prefixed with '-' it does not error should any of the files not exist. +include .env +-include .env.local .env.extra + + # export variables for all programs to see # only exported in the commands' sub-shells export @@ -39,11 +45,6 @@ previous_target: next_target: -# load env files --include .env --include .env.local - - # conditionals ifeq "${shell uname}" "Darwin" expiration_date = ${shell date -v "+365d" "+%FT%TZ"} @@ -82,7 +83,12 @@ apply: plan ${tf_plan_file} ## Load .env files in the Makefile -Use this at top of a Makefile to export all variables in `.env`: +Use one of those at the top of a Makefile to include and make available all variables in `.env`: + +```makefile +include .env +-include .env.local .env.extra +``` ```makefile ifneq (,$(wildcard ./.env)) @@ -91,15 +97,17 @@ ifneq (,$(wildcard ./.env)) endif ``` -`ifneq` + `wildcard` is a typical way to check a file exists.
+`ifneq` + `wildcard` is a typical way to check a file exists. + `include .env` imports `.env` into the Makefile variables.
+If prefixed with '-' (`-include`), it does not error nor warning should any of the included files not exist. + `export` without parameters exports all variables set until now. - - ## Further readings - [Conditional syntax] +- [Include] ### Sources @@ -112,6 +120,7 @@ endif [conditional syntax]: https://www.gnu.org/software/make/manual/html_node/Conditional-Syntax.html +[include]: https://www.gnu.org/software/make/manual/html_node/Include.html [how to load and export variables from an .env file in makefile?]: https://stackoverflow.com/questions/44628206/how-to-load-and-export-variables-from-an-env-file-in-makefile#70663753