How to check return value from the shell directive

Tuxdude picture Tuxdude · Sep 12, 2011 · Viewed 28.3k times · Source

In my Makefile, I need to test if the current directory is an SVN repo or not and if it is not I want to indicate an error using the $(error) directive in Makefile.

So I plan to use the return value of $(shell svn info .) but I'm not sure how to get this value from within the Makefile.

Note: I'm not trying to get the return value in a recipe, but rather in the middle of the Makefile.

Right now I'm doing something like this, which works just because stdout is blank when it is an error:

SVN_INFO := $(shell svn info . 2> /dev/null)
ifeq ($(SVN_INFO),)
    $(error "Not an SVN repo...")
endif

I'd still like to find out if it is possible to get the return value instead within the Makefile.

Answer

eriktous picture eriktous · Sep 13, 2011

How about using $? to echo the exit status of the last command?

SVN_INFO := $(shell svn info . 2> /dev/null; echo $$?)
ifeq ($(SVN_INFO),1)
    $(error "Not an SVN repo...")
endif