diff options
| -rw-r--r-- | Makefile | 9 | ||||
| -rw-r--r-- | README.md | 46 | ||||
| -rw-r--r-- | local.env | 14 | ||||
| -rw-r--r-- | makext.mk | 7 | ||||
| -rw-r--r-- | second.env | 5 |
5 files changed, 76 insertions, 5 deletions
@@ -1,6 +1,7 @@ MEX_DESCRIPTION="This provides some additional tools for makefiles." MEX_LICENSE="Released under the BSD two-clause license, see the LICENSE file for more information." MEX_ASSURE="python3 ls tree clang" +MEX_ENVIRONMENT="local.env second.env" include makext.mk @@ -9,6 +10,14 @@ help: .help demo-assure: .assure @echo "All good, continuing..." +demo-envars: + @echo "Envrionment variables" + @echo " HOME: $(HOME)" + @echo " TERM: $(TERM)" + @echo " ENV: $(MEX_ENVIRONMENT)" + @echo " AUDIO_BUCKET: $(AUDIO_BUCKET)" + @echo " DB_HOST: $(DB_HOST)" + build-app: clean-cache # Build the application @echo "Building the application..." @@ -11,10 +11,11 @@ tasks. > meant to really be a task runner. Keep that in mind. However, dispite > that, I constantly find myself using it as such. -| Extension | Description | -|-----------|-----------------------------------------------------| -| .help | Displays all targets with a comment in help format. | -| .assure | Check for the existance of programs on a machine. | +| Extension | Description | +|-------------|-----------------------------------------------------| +| help | Displays all targets with a comment in help format. | +| assure | Check for the existance of programs on a machine. | +| environment | Loads environmental variables from other files. | Additional features: @@ -146,7 +147,7 @@ more information. ## Assure extension Often times project uses multiple programs and to ensure that these -programs are already installed before recipes are executed `assure` can +programs are already installed before recipes are executed `.assure` can be used. If programs are missing recipes can only partially be executed leaving project in a potentially broken state. @@ -164,6 +165,41 @@ build-app: .assure status code error 1. This will stop executing the recipe and therefore not execute anything in target `build-app`. +## Environment extension + +This extension helps loading of additional environmental files in your +project. The files should have environmental variables defined in the +usual way. Seperate each file by a space and that is about it. + +If a file is missing this will break the execution of make and exit with +status code 1. + +```env +API_KEY=abc123 +SECRET_KEY=def456 +``` + +By defining `MEX_ENVIRONMENT` variable you can provide additional files +and they will be loaded automatically. + +```make +MEX_ENVIRONMENT="local.env second.env" + +include makext.mk + +demo-envars: + @echo "Envrionment variables" + @echo " HOME: $(HOME)" + @echo " TERM: $(TERM)" + @echo " ENV: $(MEX_ENVIRONMENT)" + @echo " AUDIO_BUCKET: $(AUDIO_BUCKET)" + @echo " DB_HOST: $(DB_HOST)" +``` + +After that they can be used in your recipes like all the other variables +you have. They will however override variables the shell already has +defined. + ## Acknowledgement - https://stackoverflow.com/a/59087509 diff --git a/local.env b/local.env new file mode 100644 index 0000000..d02831b --- /dev/null +++ b/local.env @@ -0,0 +1,14 @@ +# Database settings +DB_HOST=localhost +DB_PORT=5432 +DB_NAME=mydatabase +DB_USER=myuser +DB_PASSWORD=mypassword + +# API keys +API_KEY=abc123 +SECRET_KEY=def456 + +# Other settings +DEBUG_MODE=true +LOG_LEVEL=info" @@ -15,6 +15,13 @@ ifeq ($(OS),Windows_NT) $(error makext does not support Windows operating system) endif +# Load environmental files from `MEX_ENVIRONMENT`. By default GNU make +# loads what is already in `env`. This extends it to other files. +ifdef MEX_ENVIRONMENT +TEMP_ENV_FILES=$(shell echo $(MEX_ENVIRONMENT) | tr ',' ' ') +$(foreach file,$(TEMP_ENV_FILES),$(eval include $(file))) +endif + # Help extension that lists all the targets with descriptions # and adds description and license information if data provided. .PHONY: .help diff --git a/second.env b/second.env new file mode 100644 index 0000000..616e146 --- /dev/null +++ b/second.env @@ -0,0 +1,5 @@ +# Audio storage settings +AUDIO_BUCKET=my_audio_bucket +AUDIO_ACCESS_KEY=my_access_key +AUDIO_SECRET_KEY=my_secret_key +AUDIO_REGION=us-west-1 |
