2011-09-20 24 views
11

我正在創建一個項目並使用GNU Autoconf工具來進行配置和製作。我已經設置了所有的庫檢查和頭文件檢查,但似乎無法弄清楚如何檢查系統上是否存在可執行文件,如果不存在,就會失敗。Autoconf檢查程序,如果沒有發現失敗

我已經試過:

AC_CHECK_PROG(TEST,testprogram,testprogram,AC_MSG_ERROR(Cannot find testprogram.)) 

當我configure它運行和輸出:

Checking for testprogram... find: `testprogram. 15426 5 ': No such file or directory 

,但不會失敗。

回答

9

試試這個這是我剛剛從我的項目取消,它看起來的東西路徑稱爲quantlib-config

# borrowed from a check for gnome in GNU gretl: def. a check for quantlib-config 
AC_DEFUN(AC_PROG_QUANTLIB, [AC_CHECK_PROG(QUANTLIB,quantlib-config,yes)]) 
AC_PROG_QUANTLIB 
if test x"${QUANTLIB}" == x"yes" ; then 
    # use quantlib-config for QL settings 
    [.... more stuff omitted here ...] 
else 
    AC_MSG_ERROR([Please install QuantLib before trying to build RQuantLib.]) 
fi 
+0

感謝幫助,我用它創建了一個適合我需要的較短版本。 –

+0

是的,如果你只是需要救助,如果沒有找到二進制文件,那麼看起來不錯。 –

20

我發現這是最短的途徑。

AC_CHECK_PROG(FFMPEG_CHECK,ffmpeg,yes) 
if test x"$FFMPEG_CHECK" != x"yes" ; then 
    AC_MSG_ERROR([Please install ffmpeg before installing.]) 
fi 
3

上述類似,但出口的條件變量

AC_CHECK_PROG([ffmpeg],[ffmpeg],[yes],[no]) 
AM_CONDITIONAL([FOUND_FFMPEG], [test "x$ffmpeg" = xyes]) 
AM_COND_IF([FOUND_FFMPEG],,[AC_MSG_ERROR([required program 'ffmpeg' not found.])]) 
0

這裏絆倒在尋找這個問題的也能夠interact with automake優勢,我應該注意的是,如果你想讓你的程序只是看着在pathm運行時的測試是不夠的:

if ! which programname >/dev/null ; then 
    AC_MSG_ERROR([Missing programname] 
fi 
1

當使用AC_CHECK_PROG,這是我整個運行最簡潔的版本是:

AC_CHECK_PROG(BOGUS,[bogus],[bogus],[no]) 
test "$BOGUS" == "no" && AC_MSG_ERROR([Required program 'bogus' not found.]) 

當程序被丟失,該輸出將被生成:

./configure 
...cut... 
checking for bogus... no 
configure: error: Required program 'bogus' not found. 

或當與連接內置的autoconf程序檢查時,使用該代替:

AC_PROG_YACC 
AC_PROG_LEX 

test "$YACC" == ":" && AC_MSG_ERROR([Required program 'bison' not found.]) 
test "$LEX" == ":" && AC_MSG_ERROR([Required program 'flex' not found.])