blob: 7660663a1a2b5e0c7fd79dee437ae70e72161aef [file] [log] [blame]
Reid Spencere7e3c212005-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 Spencer012d35a2005-07-17 05:30:33 +000027dnl $1 - program's executable name
Reid Spencere7e3c212005-07-17 00:50:40 +000028dnl $2 - header file name to check (optional)
29dnl $3 - library file name to check (optional)
Reid Spencer012d35a2005-07-17 05:30:33 +000030dnl $4 - alternate (long) name for the program
Reid Spencere7e3c212005-07-17 00:50:40 +000031AC_DEFUN([FIND_STD_PROGRAM],
32[m4_define([allcapsname],translit($1,a-z,A-Z))
Reid Spencer012d35a2005-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 Spencere7e3c212005-07-17 00:50:40 +000035AC_ARG_WITH($1,
Reid Spencer012d35a2005-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 Spencere7e3c212005-07-17 00:50:40 +000039AC_ARG_WITH($1[-bin],
Reid Spencer012d35a2005-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 Spencere7e3c212005-07-17 00:50:40 +000042 $1[bindir=$withval],$1[bindir=nada])
43AC_ARG_WITH($1[-lib],
Reid Spencer012d35a2005-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 Spencere7e3c212005-07-17 00:50:40 +000046 $1[libdir=$withval],$1[libdir=nada])
47AC_ARG_WITH($1[-inc],
Reid Spencer012d35a2005-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 Spencere7e3c212005-07-17 00:50:40 +000050 $1[incdir=$withval],$1[incdir=nada])
51pfxvar=$1pfxdir
52binvar=$1bindir
53incvar=$1incdir
54libvar=$1libdir
55if test "${!pfxvar}" != "nada" ; then
56 CHECK_STD_PROGRAM(${!pfxvar},$1,$2,$3)
57elif test "${!binvar}" != "nada" ; then
58 if test "${!libvar}" != "nada" ; then
59 if test "${!incvar}" != "nada" ; then
60 if test -d "${!binvar}" ; then
61 if test -d "${!incvar}" ; then
62 if test -d "${!libvar}" ; then
63 AC_SUBST(allcapsname(),${!binvar}/$1)
64 AC_SUBST(allcapsname()[_BIN],${!binvar})
65 AC_SUBST(allcapsname()[_INC],${!incvar})
66 AC_SUBST(allcapsname()[_LIB],${!libvar})
67 AC_SUBST([USE_]allcapsname(),[1])
68 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"
98 checkvar="USE_"allcapsname()
99 CHECK_STD_PROGRAM([/usr],$1,$2,$3)
100 if test -z "${!checkvar}" ; then
101 CHECK_STD_PROGRAM([/usr/local],$1,$2,$3)
102 if test -z "${!checkvar}" ; then
103 CHECK_STD_PROGRAM([/sw],$1,$2,$3)
104 if test -z "${!checkvar}" ; then
105 CHECK_STD_PROGRAM([/opt],$1,$2,$3)
106 if test -z "${!checkvar}" ; then
107 CHECK_STD_PROGRAM([/],$1,$2,$3)
108 if test -z "${!checkvar}" ; then
109 checkresult="no"
110 fi
111 fi
112 fi
113 fi
114 fi
115 AC_MSG_RESULT($checkresult)
116 fi
117fi
118])