Skip to content

Instantly share code, notes, and snippets.

@mirzap
Forked from bbl/make_variable_check.md
Created August 30, 2022 19:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mirzap/47c2b72027b514259331a5ac32033693 to your computer and use it in GitHub Desktop.
Save mirzap/47c2b72027b514259331a5ac32033693 to your computer and use it in GitHub Desktop.
Makefile check if variable is defined

Check if variable is defined in a Makefile

Using ifndef

ifndef MY_FLAG
$(error MY_FLAG is not set)
endif

Using custom function

check_defined = \
    $(strip $(foreach 1,$1, \
        $(call __check_defined,$1,$(strip $(value 2)))))
__check_defined = \
    $(if $(value $1),, \
      $(error Undefined $1$(if $2, ($2))))
      
install:
	$(call check_defined, var1)
	$(call check_defined, var2)
	# do stuff here..
	
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment