Search code examples
gnuautoconfm4

how to check return value of shell cmd in autotools configure


I would like to run a shell command during the configure process- if the return value of this operation is 0, I would like to use it. Otherwise, I want to exit with error message.

I wrote something like this:

LOC=$(perl -MExtUtils::Embed -e perl_inc | sed 's/[ \t]*-I//')
RC=$?
AS_IF([ test $RC != 0 ], [AC_MSG_ERROR([Can't find module MExtUtils::Embed in perl. Try installing perl 5.8.8 or above])],)

This won't work. RC always get the value 0, even when the command fails.

Does anyone knows how to do it right?

Thanks


Solution

  • The problem is that your pipe always succeeds, because sed will succeed regardless of what perl does. One approach would be to simply delay the invocation of sed:

    LOC=$( perl -MExtUtils::Embed -e perl_inc )
    AS_IF([ test $? != 0 ], [AC_MSG_ERROR([...])])
    LOC=$( echo "$LOC" | sed 's/[ \t]*-I//' )
    

    On the other hand, it looks like perl_inc is commands to perl rather than the name of a file, so it might be easier to simply add the substitution from sed into your perl.

    On the third hand, you should probably just use AX_PROG_PERL_MODULES to see if the desired module is installed.