Skip to content

Instantly share code, notes, and snippets.

@dreknix
dreknix / Template Makefile
Last active June 18, 2023 16:30
Template for Makefiles with '.env' file, precondition check and automatic help.
#!/usr/bin/env make
ENV_FILE:=./.env$(if $(FOO),_$(FOO),)
ifneq (,$(wildcard ${ENV_FILE}))
include ${ENV_FILE}
VARS:=$(shell sed -ne 's/ *\#.*$$//; /./ s/=.*$$// p' .env )
$(foreach v,$(VARS),$(eval $(shell echo export $(v)="$(shell echo $($(v)) | sed "s/^'//")")))
else
$(error Environment file '${ENV_FILE}' not found)