Skip to content

Instantly share code, notes, and snippets.

@bbl
Created July 13, 2019 12:10
Show Gist options
  • Star 13 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save bbl/bf4bf5875d0c705c4cd78d264f98a8b1 to your computer and use it in GitHub Desktop.
Save bbl/bf4bf5875d0c705c4cd78d264f98a8b1 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