« Back to Index

Make: Check if Makefile target is called with a required input arg

View original Gist on GitHub

Tags: #Makefile #make

Makefile

# Check that given variables are set and all have non-empty values,
# die with an error otherwise.
#
# PARAMS:
#   1. Variable name(s) to test.
#   2. (optional) Error message to print.
#
# EXAMPLE:
# @:$(call check_defined, ENV_REGION, you must set ENV_REGION=usc1|awsuse2)
#
check_defined = \
    $(strip $(foreach 1,$1, \
        $(call __check_defined,$1,$(strip $(value 2)))))
__check_defined = \
    $(if $(value $1),, \
        $(error Undefined $1$(if $2, ($2))$(if $(value @), \
                required by target `$@')))