views:

260

answers:

4

Hi,

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.

Can anyone give an example of doing this?

I tried the following but it is not the right syntax:

ifeq "$(shell svnversion --version | sed s/[^0-9\.]*://)" "1.4"
$error("Bad svnversion v1.4, please install v1.6")
endif

Thanks.

+1  A: 
$(error Bad svnversion v1.4...)
John Weldon
+2  A: 

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.
LiraNuna
A: 

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 
Beta
+1  A: 

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.

Chris Dodd
This isn't working, I get:/bin/sh: -c: line 0: unexpected EOF while looking for matching `)'/bin/sh: -c: line 1: syntax error: unexpected end of file
WilliamKF
@WilliamKF -- There's a spurious space after a \ at the end of a line that causes that problem. I also fixed the missing |
Chris Dodd