I found that the best answer cannot be used as a requirement, except for other PHONY goals. When used as a dependency for a target that is a real file, using check-env will force that target to rebuild.
Other answers are global (for example, a variable is required for all purposes in the Makefile) or use a shell, for example, if ENV was absent, make will complete regardless of the target.
The solution I found for both problems:
ndef = $(if $(value $(1)),,$(error $(1) not set)) .PHONY: deploy deploy: $(call ndef,ENV) echo "deploying $(ENV)" .PHONY: build build: echo "building"
The output looks like
$ make build echo "building" building $ make deploy Makefile:5: *** ENV not set. Stop. $ make deploy ENV="env" echo "deploying env" deploying env $
value has some frightening warnings, but for this simple use, I think this is the best choice.
23jodys Apr 02 '18 at 21:53 2018-04-02 21:53
source share