Can make warn me, when I use unset variables?

后端 未结 2 1059
暗喜
暗喜 2021-02-13 18:03

Is there a way to tell make to complain when I use unset variables? Something similar to set -u in bash?

I have just spent twenty minutes debugging my Makef

相关标签:
2条回答
  • 2021-02-13 18:35

    Yes, there is a way:

    make --warn-undefined-variables
    

    I've just tested it with make version 3.81

    EDIT:

    You can also set it in your makefile, to protect yourself in the future from silly mistakes. To do it just put this somewhere near the top of your makefile (this will be passed to recursive make processes too):

    MAKEFLAGS=--warn-undefined-variables
    
    0 讨论(0)
  • 2021-02-13 18:38

    Here is how one can do it to make make fail immediately:

    ifndef PSWD
    $(error PSWD is undefined)
    endif
    
    0 讨论(0)
提交回复
热议问题