Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 406
WilliamKF Avatar asked Dec 08 '09 03:12

WilliamKF


People also ask

How do you throw an error in Makefile?

For that, you can define err_mesg = your multiline error mesage ... endef , and then, $(error $(err_mesg)) . Make will keep and output err_mesg as it was written.

What is Makefile target?

A simple makefile consists of “rules” with the following shape: target … : prerequisites … recipe … … A target is usually the name of a file that is generated by a program; examples of targets are executable or object files. A target can also be the name of an action to carry out, such as ' clean ' (see Phony Targets).


2 Answers

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. 
like image 51
LiraNuna Avatar answered Sep 29 '22 17:09

LiraNuna


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.

like image 37
Chris Dodd Avatar answered Sep 29 '22 18:09

Chris Dodd