blob: c789df8e641d96e67928ba3c2421692f39448682 [file] [log] [blame]
Reid Spencera5e26072005-07-17 00:50:40 +00001dnl Check for a standard program that has a bin, include and lib directory
2dnl
3dnl Parameters:
4dnl $1 - prefix directory to check
5dnl $2 - program name to check
6dnl $3 - header file to check
7dnl $4 - library file to check
8AC_DEFUN([CHECK_STD_PROGRAM],
9[m4_define([allcapsname],translit($2,a-z,A-Z))
10if 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
21fi
22])
23
24dnl Find a program via --with options, in the path, or well known places
25dnl
26dnl Parameters:
Reid Spencer72f71e12005-07-17 05:30:33 +000027dnl $1 - program's executable name
Reid Spencera5e26072005-07-17 00:50:40 +000028dnl $2 - header file name to check (optional)
29dnl $3 - library file name to check (optional)
Reid Spencer72f71e12005-07-17 05:30:33 +000030dnl $4 - alternate (long) name for the program
Reid Spencera5e26072005-07-17 00:50:40 +000031AC_DEFUN([FIND_STD_PROGRAM],
32[m4_define([allcapsname],translit($1,a-z,A-Z))
Reid Spencer72f71e12005-07-17 05:30:33 +000033m4_define([stdprog_long_name],ifelse($4,,translit($1,[ !@#$%^&*()-+={}[]:;"',./?],[-]),translit($4,[ !@#$%^&*()-+={}[]:;"',./?],[-])))
34AC_MSG_CHECKING([for ]stdprog_long_name()[ bin/lib/include locations])
Reid Spencera5e26072005-07-17 00:50:40 +000035AC_ARG_WITH($1,
Reid Spencer72f71e12005-07-17 05:30:33 +000036 AS_HELP_STRING([--with-]stdprog_long_name()[=DIR],
37 [Specify that the ]stdprog_long_name()[ install prefix is DIR]),
38 $1[pfxdir=$withval],$1[pfxdir=nada])
Reid Spencera5e26072005-07-17 00:50:40 +000039AC_ARG_WITH($1[-bin],
Reid Spencer72f71e12005-07-17 05:30:33 +000040 AS_HELP_STRING([--with-]stdprog_long_name()[-bin=DIR],
41 [Specify that the ]stdprog_long_name()[ binary is in DIR]),
Reid Spencera5e26072005-07-17 00:50:40 +000042 $1[bindir=$withval],$1[bindir=nada])
43AC_ARG_WITH($1[-lib],
Reid Spencer72f71e12005-07-17 05:30:33 +000044 AS_HELP_STRING([--with-]stdprog_long_name()[-lib=DIR],
45 [Specify that ]stdprog_long_name()[ libraries are in DIR]),
Reid Spencera5e26072005-07-17 00:50:40 +000046 $1[libdir=$withval],$1[libdir=nada])
47AC_ARG_WITH($1[-inc],
Reid Spencer72f71e12005-07-17 05:30:33 +000048 AS_HELP_STRING([--with-]stdprog_long_name()[-inc=DIR],
49 [Specify that the ]stdprog_long_name()[ includes are in DIR]),
Reid Spencera5e26072005-07-17 00:50:40 +000050 $1[incdir=$withval],$1[incdir=nada])
Reid Spencer675267e2005-07-25 20:25:08 +000051eval pfxval=\$\{$1pfxdir\}
52eval binval=\$\{$1bindir\}
53eval incval=\$\{$1incdir\}
Reid Spencercc2665d2006-08-14 23:15:03 +000054eval libval=\$\{$1libdir\}
Reid Spencer675267e2005-07-25 20:25:08 +000055if test "${pfxval}" != "nada" ; then
56 CHECK_STD_PROGRAM(${pfxval},$1,$2,$3)
57elif test "${binval}" != "nada" ; then
58 if test "${libval}" != "nada" ; then
59 if test "${incval}" != "nada" ; then
60 if test -d "${binval}" ; then
61 if test -d "${incval}" ; then
62 if test -d "${libval}" ; then
63 AC_SUBST(allcapsname(),${binval}/$1)
64 AC_SUBST(allcapsname()[_BIN],${binval})
65 AC_SUBST(allcapsname()[_INC],${incval})
66 AC_SUBST(allcapsname()[_LIB],${libval})
Reid Spencer9977ea62006-08-14 23:19:57 +000067 AC_SUBST([USE_]allcapsname(),["USE_]allcapsname()[ = 1"])
Reid Spencera5e26072005-07-17 00:50:40 +000068 AC_MSG_RESULT([found via --with options])
69 else
70 AC_MSG_RESULT([failed])
71 AC_MSG_ERROR([The --with-]$1[-libdir value must be a directory])
72 fi
73 else
74 AC_MSG_RESULT([failed])
75 AC_MSG_ERROR([The --with-]$1[-incdir value must be a directory])
76 fi
77 else
78 AC_MSG_RESULT([failed])
79 AC_MSG_ERROR([The --with-]$1[-bindir value must be a directory])
80 fi
81 else
82 AC_MSG_RESULT([failed])
83 AC_MSG_ERROR([The --with-]$1[-incdir option must be specified])
84 fi
85 else
86 AC_MSG_RESULT([failed])
87 AC_MSG_ERROR([The --with-]$1[-libdir option must be specified])
88 fi
89else
90 tmppfxdir=`which $1 2>&1`
91 if test -n "$tmppfxdir" -a -d "${tmppfxdir%*$1}" -a \
92 -d "${tmppfxdir%*$1}/.." ; then
93 tmppfxdir=`cd "${tmppfxdir%*$1}/.." ; pwd`
94 CHECK_STD_PROGRAM($tmppfxdir,$1,$2,$3)
95 AC_MSG_RESULT([found in PATH at ]$tmppfxdir)
96 else
97 checkresult="yes"
Reid Spencer675267e2005-07-25 20:25:08 +000098 eval checkval=\$\{"USE_"allcapsname()\}
Reid Spencera5e26072005-07-17 00:50:40 +000099 CHECK_STD_PROGRAM([/usr],$1,$2,$3)
Reid Spencer675267e2005-07-25 20:25:08 +0000100 if test -z "${checkval}" ; then
Reid Spencera5e26072005-07-17 00:50:40 +0000101 CHECK_STD_PROGRAM([/usr/local],$1,$2,$3)
Reid Spencer675267e2005-07-25 20:25:08 +0000102 if test -z "${checkval}" ; then
Reid Spencera5e26072005-07-17 00:50:40 +0000103 CHECK_STD_PROGRAM([/sw],$1,$2,$3)
Reid Spencer675267e2005-07-25 20:25:08 +0000104 if test -z "${checkval}" ; then
Reid Spencera5e26072005-07-17 00:50:40 +0000105 CHECK_STD_PROGRAM([/opt],$1,$2,$3)
Reid Spencer675267e2005-07-25 20:25:08 +0000106 if test -z "${checkval}" ; then
Reid Spencera5e26072005-07-17 00:50:40 +0000107 CHECK_STD_PROGRAM([/],$1,$2,$3)
Reid Spencer675267e2005-07-25 20:25:08 +0000108 if test -z "${checkval}" ; then
Reid Spencera5e26072005-07-17 00:50:40 +0000109 checkresult="no"
110 fi
111 fi
112 fi
113 fi
114 fi
115 AC_MSG_RESULT($checkresult)
116 fi
117fi
118])