Imported Upstream version 1.7.6p1
[debian/sudo] / aclocal.m4
1 dnl Local m4 macros for autoconf (used by sudo)
2 dnl
3 dnl Copyright (c) 1994-1996, 1998-2005, 2007-2011
4 dnl     Todd C. Miller <Todd.Miller@courtesan.com>
5 dnl
6 dnl XXX - should cache values in all cases!!!
7 dnl
8 dnl checks for programs
9
10 dnl
11 dnl check for sendmail in well-known locations
12 dnl
13 AC_DEFUN([SUDO_PROG_SENDMAIL], [AC_MSG_CHECKING([for sendmail])
14 found=no
15 for p in "/usr/sbin/sendmail" "/usr/lib/sendmail" "/usr/etc/sendmail" "/usr/ucblib/sendmail" "/usr/local/lib/sendmail" "/usr/local/bin/sendmail"; do
16     if test -f "$p"; then
17         found=yes
18         AC_MSG_RESULT([$p])
19         SUDO_DEFINE_UNQUOTED(_PATH_SUDO_SENDMAIL, "$p")
20         break
21     fi
22 done
23 if test X"$found" != X"yes"; then
24     AC_MSG_RESULT([not found])
25 fi
26 ])dnl
27
28 dnl
29 dnl check for vi in well-known locations
30 dnl
31 AC_DEFUN([SUDO_PROG_VI], [AC_MSG_CHECKING([for vi])
32 found=no
33 for editor in "/usr/bin/vi" "/bin/vi" "/usr/ucb/vi" "/usr/bsd/vi" "/usr/local/bin/vi"; do
34     if test -f "$editor"; then
35         found=yes
36         AC_MSG_RESULT([$editor])
37         SUDO_DEFINE_UNQUOTED(_PATH_VI, "$editor")
38         break
39     fi
40 done
41 if test X"$found" != X"yes"; then
42     AC_MSG_RESULT([not found])
43 fi
44 ])dnl
45
46 dnl
47 dnl check for mv in well-known locations
48 dnl
49 AC_DEFUN([SUDO_PROG_MV], [AC_MSG_CHECKING([for mv])
50 found=no
51 for p in "/usr/bin/mv" "/bin/mv" "/usr/ucb/mv" "/usr/sbin/mv"; do
52     if test -f "$p"; then
53         found=yes
54         AC_MSG_RESULT([$p])
55         SUDO_DEFINE_UNQUOTED(_PATH_MV, "$p")
56         break
57     fi
58 done
59 if test X"$found" != X"yes"; then
60     AC_MSG_RESULT([not found])
61 fi
62 ])dnl
63
64 dnl
65 dnl check for bourne shell in well-known locations
66 dnl
67 AC_DEFUN([SUDO_PROG_BSHELL], [AC_MSG_CHECKING([for bourne shell])
68 found=no
69 for p in "/bin/sh" "/usr/bin/sh" "/sbin/sh" "/usr/sbin/sh" "/bin/ksh" "/usr/bin/ksh" "/bin/bash" "/usr/bin/bash"; do
70     if test -f "$p"; then
71         found=yes
72         AC_MSG_RESULT([$p])
73         SUDO_DEFINE_UNQUOTED(_PATH_BSHELL, "$p")
74         break
75     fi
76 done
77 if test X"$found" != X"yes"; then
78     AC_MSG_RESULT([not found])
79 fi
80 ])dnl
81
82 dnl
83 dnl Where the log file goes, use /var/log if it exists, else /{var,usr}/adm
84 dnl
85 AC_DEFUN([SUDO_LOGFILE], [AC_MSG_CHECKING(for log file location)
86 if test -n "$with_logpath"; then
87     AC_MSG_RESULT($with_logpath)
88     SUDO_DEFINE_UNQUOTED(_PATH_SUDO_LOGFILE, "$with_logpath")
89 elif test -d "/var/log"; then
90     AC_MSG_RESULT(/var/log/sudo.log)
91     SUDO_DEFINE(_PATH_SUDO_LOGFILE, "/var/log/sudo.log")
92 elif test -d "/var/adm"; then
93     AC_MSG_RESULT(/var/adm/sudo.log)
94     SUDO_DEFINE(_PATH_SUDO_LOGFILE, "/var/adm/sudo.log")
95 elif test -d "/usr/adm"; then
96     AC_MSG_RESULT(/usr/adm/sudo.log)
97     SUDO_DEFINE(_PATH_SUDO_LOGFILE, "/usr/adm/sudo.log")
98 else
99     AC_MSG_RESULT(unknown, you will have to set _PATH_SUDO_LOGFILE by hand)
100 fi
101 ])dnl
102
103 dnl
104 dnl Where the timestamp files go.
105 dnl
106 AC_DEFUN([SUDO_TIMEDIR], [AC_MSG_CHECKING(for timestamp file location)
107 timedir="$with_timedir"
108 if test -z "$timedir"; then
109     for d in /var/db /var/lib /var/adm /usr/adm; do
110         if test -d "$d"; then
111             timedir="$d/sudo"
112             break
113         fi
114     done
115 fi
116 AC_MSG_RESULT([$timedir])
117 SUDO_DEFINE_UNQUOTED(_PATH_SUDO_TIMEDIR, "$timedir")
118 ])dnl
119
120 dnl
121 dnl Where the I/O log files go, use /var/log/sudo-io if
122 dnl /var/log exists, else /{var,usr}/adm/sudo-io
123 dnl
124 AC_DEFUN([SUDO_IO_LOGDIR], [
125     AC_MSG_CHECKING(for I/O log dir location)
126     if test "${with_iologdir-yes}" != "yes"; then
127         iolog_dir="$with_iologdir"
128     elif test -d "/var/log"; then
129         iolog_dir="/var/log/sudo-io"
130     elif test -d "/var/adm"; then
131         iolog_dir="/var/adm/sudo-io"
132     else
133         iolog_dir="/usr/adm/sudo-io"
134     fi
135     if test "${with_iologdir}" != "no"; then
136         SUDO_DEFINE_UNQUOTED(_PATH_SUDO_IO_LOGDIR, "$iolog_dir")
137     fi
138     AC_MSG_RESULT($iolog_dir)
139 ])dnl
140
141 dnl
142 dnl SUDO_CHECK_TYPE(TYPE, DEFAULT)
143 dnl XXX - should require the check for unistd.h...
144 dnl
145 AC_DEFUN([SUDO_CHECK_TYPE],
146 [AC_REQUIRE([AC_HEADER_STDC])dnl
147 AC_MSG_CHECKING(for $1)
148 AC_CACHE_VAL(sudo_cv_type_$1,
149 [AC_EGREP_CPP($1, [#include <sys/types.h>
150 #include <stdio.h>
151 #if STDC_HEADERS
152 #include <stdlib.h>
153 #endif
154 #if HAVE_UNISTD_H
155 #include <unistd.h>
156 #endif], sudo_cv_type_$1=yes, sudo_cv_type_$1=no)])dnl
157 AC_MSG_RESULT($sudo_cv_type_$1)
158 if test $sudo_cv_type_$1 = no; then
159   AC_DEFINE($1, $2, [Define if your system lacks the $1 type.])
160 fi
161 ])
162
163 dnl
164 dnl Check for size_t declation
165 dnl
166 AC_DEFUN([SUDO_TYPE_SIZE_T],
167 [SUDO_CHECK_TYPE(size_t, int)])
168
169 dnl
170 dnl Check for ssize_t declation
171 dnl
172 AC_DEFUN([SUDO_TYPE_SSIZE_T],
173 [SUDO_CHECK_TYPE(ssize_t, int)])
174
175 dnl
176 dnl Check for dev_t declation
177 dnl
178 AC_DEFUN([SUDO_TYPE_DEV_T],
179 [SUDO_CHECK_TYPE(dev_t, int)])
180
181 dnl
182 dnl Check for ino_t declation
183 dnl
184 AC_DEFUN([SUDO_TYPE_INO_T],
185 [SUDO_CHECK_TYPE(ino_t, unsigned int)])
186
187 dnl
188 dnl check for working fnmatch(3)
189 dnl
190 AC_DEFUN([SUDO_FUNC_FNMATCH],
191 [AC_MSG_CHECKING([for working fnmatch with FNM_CASEFOLD])
192 AC_CACHE_VAL(sudo_cv_func_fnmatch,
193 [rm -f conftestdata; > conftestdata
194 AC_TRY_RUN([#include <fnmatch.h>
195 main() { exit(fnmatch("/*/bin/echo *", "/usr/bin/echo just a test", FNM_CASEFOLD)); }], [sudo_cv_func_fnmatch=yes], [sudo_cv_func_fnmatch=no],
196   [sudo_cv_func_fnmatch=no])
197 rm -f core core.* *.core])
198 AC_MSG_RESULT($sudo_cv_func_fnmatch)
199 AS_IF([test $sudo_cv_func_fnmatch = yes], [$1], [$2])])
200
201 dnl
202 dnl check for isblank(3)
203 dnl
204 AC_DEFUN([SUDO_FUNC_ISBLANK],
205   [AC_CACHE_CHECK([for isblank], [sudo_cv_func_isblank],
206     [AC_TRY_LINK([#include <ctype.h>], [return (isblank('a'));],
207     sudo_cv_func_isblank=yes, sudo_cv_func_isblank=no)])
208 ] [
209   if test "$sudo_cv_func_isblank" = "yes"; then
210     AC_DEFINE(HAVE_ISBLANK, 1, [Define if you have isblank(3).])
211   else
212     AC_LIBOBJ(isblank)
213   fi
214 ])
215
216 dnl
217 dnl check unsetenv() return value
218 dnl
219 AC_DEFUN([SUDO_FUNC_UNSETENV_VOID],
220   [AC_CACHE_CHECK([whether unsetenv returns void], [sudo_cv_func_unsetenv_void],
221     [AC_RUN_IFELSE([AC_LANG_PROGRAM(
222       [AC_INCLUDES_DEFAULT
223         int unsetenv();
224       ], [
225         [return unsetenv("FOO") != 0;]
226       ])
227     ],
228     [sudo_cv_func_unsetenv_void=no],
229     [sudo_cv_func_unsetenv_void=yes],
230     [sudo_cv_func_unsetenv_void=no])])
231     if test $sudo_cv_func_unsetenv_void = yes; then
232       AC_DEFINE(UNSETENV_VOID, 1,
233         [Define to 1 if the `unsetenv' function returns void instead of `int'.])
234     fi
235   ])
236
237 dnl
238 dnl check putenv() argument for const
239 dnl
240 AC_DEFUN([SUDO_FUNC_PUTENV_CONST],
241 [AC_CACHE_CHECK([whether putenv has a const argument],
242 sudo_cv_func_putenv_const,
243 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT
244 int putenv(const char *string) {return 0;}], [])],
245     [sudo_cv_func_putenv_const=yes],
246     [sudo_cv_func_putenv_const=no])
247   ])
248   if test $sudo_cv_func_putenv_const = yes; then
249     AC_DEFINE(PUTENV_CONST, 1, [Define to 1 if the `putenv' has a const argument.])
250   fi
251 ])
252
253 dnl
254 dnl check for sa_len field in struct sockaddr
255 dnl
256 AC_DEFUN([SUDO_SOCK_SA_LEN], [
257     AC_CHECK_MEMBER([struct sockaddr.sa_len], 
258         [AC_DEFINE(HAVE_SA_LEN, 1, [Define if your struct sockadr has an sa_len field.])],    
259         [],
260         [ #include <sys/types.h>
261           #include <sys/socket.h>] 
262     )]
263 )
264 dnl
265 dnl check for max length of uid_t in string representation.
266 dnl we can't really trust UID_MAX or MAXUID since they may exist
267 dnl only for backwards compatibility.
268 dnl
269 AC_DEFUN([SUDO_UID_T_LEN],
270 [AC_REQUIRE([AC_TYPE_UID_T])
271 AC_MSG_CHECKING(max length of uid_t)
272 AC_CACHE_VAL(sudo_cv_uid_t_len,
273 [rm -f conftestdata
274 AC_TRY_RUN(
275 [#include <stdio.h>
276 #include <pwd.h>
277 #include <limits.h>
278 #include <sys/types.h>
279 #include <sys/param.h>
280 main() {
281   FILE *f;
282   char b[1024];
283   uid_t u = (uid_t) -1;
284
285   if ((f = fopen("conftestdata", "w")) == NULL)
286     exit(1);
287
288   (void) sprintf(b, "%lu", (unsigned long) u);
289   (void) fprintf(f, "%d\n", strlen(b));
290   (void) fclose(f);
291   exit(0);
292 }], sudo_cv_uid_t_len=`cat conftestdata`, sudo_cv_uid_t_len=10, sudo_cv_uid_t_len=10)
293 ])
294 rm -f conftestdata
295 AC_MSG_RESULT($sudo_cv_uid_t_len)
296 AC_DEFINE_UNQUOTED(MAX_UID_T_LEN, $sudo_cv_uid_t_len, [Define to the max length of a uid_t in string context (excluding the NUL).])
297 ])
298
299 dnl
300 dnl append a libpath to an LDFLAGS style variable
301 dnl
302 AC_DEFUN([SUDO_APPEND_LIBPATH], [
303     if test X"$with_rpath" = X"yes"; then
304         case "$host" in
305             *-*-hpux*)  $1="${$1} -L$2 -Wl,+b,$2"
306                         ;;
307             *)          $1="${$1} -L$2 -Wl,-R$2"
308                         ;;
309         esac
310     else
311         $1="${$1} -L$2"
312     fi
313     if test X"$blibpath" != X"" -a "$1" = "SUDO_LDFLAGS"; then
314         blibpath_add="${blibpath_add}:$2"
315     fi
316 ])
317
318 dnl
319 dnl Determine the mail spool location
320 dnl NOTE: must be run *after* check for paths.h
321 dnl
322 AC_DEFUN([SUDO_MAILDIR], [
323 maildir=no
324 if test X"$ac_cv_header_paths_h" = X"yes"; then
325 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT
326 #include <paths.h>],
327 [char *p = _PATH_MAILDIR;])], [maildir=yes], [])
328 fi
329 if test $maildir = no; then
330     # Solaris has maillock.h which defines MAILDIR
331     AC_CHECK_HEADERS(maillock.h, [
332         SUDO_DEFINE(_PATH_MAILDIR, MAILDIR)
333         maildir=yes
334     ])
335     if test $maildir = no; then
336         for d in /var/mail /var/spool/mail /usr/spool/mail; do
337             if test -d "$d"; then
338                 maildir=yes
339                 SUDO_DEFINE_UNQUOTED(_PATH_MAILDIR, "$d")
340                 break
341             fi
342         done
343         if test $maildir = no; then
344             # unable to find mail dir, hope for the best
345             SUDO_DEFINE_UNQUOTED(_PATH_MAILDIR, "/var/mail")
346         fi
347     fi
348 fi
349 ])
350
351 dnl
352 dnl private versions of AC_DEFINE and AC_DEFINE_UNQUOTED that don't support
353 dnl tracing that we use to define paths for pathnames.h so autoheader doesn't
354 dnl put them in config.h.in.  An awful hack.
355 dnl
356 m4_define([SUDO_DEFINE],
357 [cat >>confdefs.h <<\EOF
358 [@%:@define] $1 m4_if($#, 2, [$2], $#, 3, [$2], 1)
359 EOF
360 ])
361
362 m4_define([SUDO_DEFINE_UNQUOTED],
363 [cat >>confdefs.h <<EOF
364 [@%:@define] $1 m4_if($#, 2, [$2], $#, 3, [$2], 1)
365 EOF
366 ])
367
368 dnl
369 dnl Pull in libtool macros
370 dnl
371 m4_include([libtool.m4])
372 m4_include([ltoptions.m4])
373 m4_include([ltsugar.m4])
374 m4_include([ltversion.m4])
375 m4_include([lt~obsolete.m4])