Abort makefile if variable not set

后端 未结 5 1219
栀梦
栀梦 2020-12-22 16:11

How could I abort a make/makefile execution based on a makefile\'s variable not being set/valued?

I came up with this, but works only if caller doesn\'t explicitly r

5条回答
  •  不思量自难忘°
    2020-12-22 16:35

    For simplicity and brevity:

    $ cat Makefile
    check-%:
            @: $(if $(value $*),,$(error $* is undefined))
    
    bar:| check-foo
            echo "foo is $$foo"
    

    With outputs:

    $ make bar
    Makefile:2: *** foo is undefined. Stop.
    $ make bar foo="something"
    echo "foo is $$foo"
    foo is something
    

提交回复
热议问题