Skip to content

Instantly share code, notes, and snippets.

@bbl
Created July 13, 2019 12:10
Show Gist options
  • Select an option

  • Save bbl/bf4bf5875d0c705c4cd78d264f98a8b1 to your computer and use it in GitHub Desktop.

Select an option

Save bbl/bf4bf5875d0c705c4cd78d264f98a8b1 to your computer and use it in GitHub Desktop.

Revisions

  1. bbl created this gist Jul 13, 2019.
    26 changes: 26 additions & 0 deletions make_variable_check.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,26 @@
    # Check if variable is defined in a Makefile

    ### Using `ifndef`

    ```make
    ifndef MY_FLAG
    $(error MY_FLAG is not set)
    endif
    ```

    ### Using custom function

    ```make
    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..

    ```