How to force an error in a gnumake file

后端 未结 3 1220
南旧
南旧 2020-12-13 12:15

I want to detect a condition in my makefile where a tool is the wrong version and force the make to fail with an error message indicating the item is not the right version.<

相关标签:
3条回答
  • 2020-12-13 12:35

    From the manual:

    $(error Bad svn version v1.4, please install v1.6)
    

    This will result make to a fatal error:

    $ make
    Makefile:2: *** Bad svn version v1.4, please install v1.6.  Stop.
    
    0 讨论(0)
  • 2020-12-13 12:37

    While $(error... works, sometimes its easier to use a rule that fails

    test_svn_version:
            @if [ $$(svn --version --quiet | \
                    perl -ne '@a=split(/\./); \
                              print $$a[0]*10000 + $$a[1]*100 + $$a[2]') \
                  -lt 10600 ]; \
            then \
                echo >&2 "Svn version $$(svn --version --quiet) too old; upgrade to v1.6";
                false; \
            fi
    

    Then you make test_svn_version a prerequisite of your top level target.

    0 讨论(0)
  • 2020-12-13 12:42

    The conditional needs some attention too.

    ifeq ($(shell svnversion --version | sed s/[^0-9\.]*://), 1.4) 
        $(error Bad svnversion v1.4, please install v1.6)
    endif 
    
    0 讨论(0)
提交回复
热议问题