Reid Spencer | a5e2607 | 2005-07-17 00:50:40 +0000 | [diff] [blame^] | 1 | dnl Check for a standard program that has a bin, include and lib directory |
| 2 | dnl |
| 3 | dnl Parameters: |
| 4 | dnl $1 - prefix directory to check |
| 5 | dnl $2 - program name to check |
| 6 | dnl $3 - header file to check |
| 7 | dnl $4 - library file to check |
| 8 | AC_DEFUN([CHECK_STD_PROGRAM], |
| 9 | [m4_define([allcapsname],translit($2,a-z,A-Z)) |
| 10 | if test -n "$1" -a -d "$1" -a -n "$2" -a -d "$1/bin" -a -x "$1/bin/$2" ; then |
| 11 | AC_SUBST([USE_]allcapsname(),["USE_]allcapsname()[ = 1"]) |
| 12 | AC_SUBST(allcapsname(),[$1/bin/$2]) |
| 13 | AC_SUBST(allcapsname()[_BIN],[$1/bin]) |
| 14 | AC_SUBST(allcapsname()[_DIR],[$1]) |
| 15 | if test -n "$3" -a -d "$1/include" -a -f "$1/include/$3" ; then |
| 16 | AC_SUBST(allcapsname()[_INC],[$1/include]) |
| 17 | fi |
| 18 | if test -n "$4" -a -d "$1/lib" -a -f "$1/lib/$4" ; then |
| 19 | AC_SUBST(allcapsname()[_LIB],[$1/lib]) |
| 20 | fi |
| 21 | fi |
| 22 | ]) |
| 23 | |
| 24 | dnl Find a program via --with options, in the path, or well known places |
| 25 | dnl |
| 26 | dnl Parameters: |
| 27 | dnl $1 - program name |
| 28 | dnl $2 - header file name to check (optional) |
| 29 | dnl $3 - library file name to check (optional) |
| 30 | AC_DEFUN([FIND_STD_PROGRAM], |
| 31 | [m4_define([allcapsname],translit($1,a-z,A-Z)) |
| 32 | AC_MSG_CHECKING([for ]$1[ bin/lib/include locations]) |
| 33 | AC_ARG_WITH($1, |
| 34 | AS_HELP_STRING([--with-]$1[=DIR],[Specify that ]$1['s install prefix is DIR]), |
| 35 | $1[pfxdir=$withval],$1[pfxdir=nada]) |
| 36 | AC_ARG_WITH($1[-bin], |
| 37 | AS_HELP_STRING([--with-]$1[-bin=DIR],[Specify that ]$1[ binary are in DIR]), |
| 38 | $1[bindir=$withval],$1[bindir=nada]) |
| 39 | AC_ARG_WITH($1[-lib], |
| 40 | AS_HELP_STRING([--with-]$1[-lib=DIR],[Specify that ]$1[ libs are in DIR]), |
| 41 | $1[libdir=$withval],$1[libdir=nada]) |
| 42 | AC_ARG_WITH($1[-inc], |
| 43 | AS_HELP_STRING([--with-]$1[-inc=DIR],[Specify that ]$1[ includes are in DIR]), |
| 44 | $1[incdir=$withval],$1[incdir=nada]) |
| 45 | pfxvar=$1pfxdir |
| 46 | binvar=$1bindir |
| 47 | incvar=$1incdir |
| 48 | libvar=$1libdir |
| 49 | if test "${!pfxvar}" != "nada" ; then |
| 50 | CHECK_STD_PROGRAM(${!pfxvar},$1,$2,$3) |
| 51 | elif test "${!binvar}" != "nada" ; then |
| 52 | if test "${!libvar}" != "nada" ; then |
| 53 | if test "${!incvar}" != "nada" ; then |
| 54 | if test -d "${!binvar}" ; then |
| 55 | if test -d "${!incvar}" ; then |
| 56 | if test -d "${!libvar}" ; then |
| 57 | AC_SUBST(allcapsname(),${!binvar}/$1) |
| 58 | AC_SUBST(allcapsname()[_BIN],${!binvar}) |
| 59 | AC_SUBST(allcapsname()[_INC],${!incvar}) |
| 60 | AC_SUBST(allcapsname()[_LIB],${!libvar}) |
| 61 | AC_SUBST([USE_]allcapsname(),[1]) |
| 62 | AC_MSG_RESULT([found via --with options]) |
| 63 | else |
| 64 | AC_MSG_RESULT([failed]) |
| 65 | AC_MSG_ERROR([The --with-]$1[-libdir value must be a directory]) |
| 66 | fi |
| 67 | else |
| 68 | AC_MSG_RESULT([failed]) |
| 69 | AC_MSG_ERROR([The --with-]$1[-incdir value must be a directory]) |
| 70 | fi |
| 71 | else |
| 72 | AC_MSG_RESULT([failed]) |
| 73 | AC_MSG_ERROR([The --with-]$1[-bindir value must be a directory]) |
| 74 | fi |
| 75 | else |
| 76 | AC_MSG_RESULT([failed]) |
| 77 | AC_MSG_ERROR([The --with-]$1[-incdir option must be specified]) |
| 78 | fi |
| 79 | else |
| 80 | AC_MSG_RESULT([failed]) |
| 81 | AC_MSG_ERROR([The --with-]$1[-libdir option must be specified]) |
| 82 | fi |
| 83 | else |
| 84 | tmppfxdir=`which $1 2>&1` |
| 85 | if test -n "$tmppfxdir" -a -d "${tmppfxdir%*$1}" -a \ |
| 86 | -d "${tmppfxdir%*$1}/.." ; then |
| 87 | tmppfxdir=`cd "${tmppfxdir%*$1}/.." ; pwd` |
| 88 | CHECK_STD_PROGRAM($tmppfxdir,$1,$2,$3) |
| 89 | AC_MSG_RESULT([found in PATH at ]$tmppfxdir) |
| 90 | else |
| 91 | checkresult="yes" |
| 92 | checkvar="USE_"allcapsname() |
| 93 | CHECK_STD_PROGRAM([/usr],$1,$2,$3) |
| 94 | if test -z "${!checkvar}" ; then |
| 95 | CHECK_STD_PROGRAM([/usr/local],$1,$2,$3) |
| 96 | if test -z "${!checkvar}" ; then |
| 97 | CHECK_STD_PROGRAM([/sw],$1,$2,$3) |
| 98 | if test -z "${!checkvar}" ; then |
| 99 | CHECK_STD_PROGRAM([/opt],$1,$2,$3) |
| 100 | if test -z "${!checkvar}" ; then |
| 101 | CHECK_STD_PROGRAM([/],$1,$2,$3) |
| 102 | if test -z "${!checkvar}" ; then |
| 103 | checkresult="no" |
| 104 | fi |
| 105 | fi |
| 106 | fi |
| 107 | fi |
| 108 | fi |
| 109 | AC_MSG_RESULT($checkresult) |
| 110 | fi |
| 111 | fi |
| 112 | ]) |