English 中文(简体)
How to force an error in a gnumake file
原标题:

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.

最佳回答

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.
问题回答

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.

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 




相关问题
makefile: how to show line numbers for debugging?

Is there a way to have make display the line number where it declares an error? The -d switch doesn t seem to cut it. Updated: Example output: Reaping winning child 0x08aa8648 PID 9381 /bin/sh: ...

What is the reasoning behind the Makefile whitespace syntax?

I m revisiting Python after Michael Sparks s excellent walk through of Peter Norvig s Python spell checker at the SO DevDay in London. One of the points he highlighted was how clean Python is to look ...

Debugging GNU make

Is there a command line way in make to find out which of the prerequisites of a target is not updated?

How to add an all rule to this Makefile?

I want to just type make all and have the following Makefile do everything it s supposed to do: LEX = lex YACC = yacc CC = gcc calcu: y.tab.o lex.yy.o $(CC) -o calcu y.tab.o lex.yy.o -ly -lfl ...

How to discover number of *logical* cores on Mac OS X?

How can you tell, from the command line, how many cores are on the machine when you re running Mac OS X? On Linux, I use: x=$(awk /^processor/ {++n} END {print n+1} /proc/cpuinfo) It s not ...

Using extern in C doesn t work as expected

I have created two files: tunables.h #ifndef TUNABLES_H #define TUNABLES_H void tunables_load_conservative(); void tunables_load_aggressive(); extern int timer_x; #endif /*TUNABLES_H */ and ...

热门标签