update control to reflect move of primary repo to collab-maint
[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 check for utmp file
84 dnl
85 AC_DEFUN([SUDO_PATH_UTMP], [AC_MSG_CHECKING([for utmp file path])
86 found=no
87 for p in "/var/run/utmp" "/var/adm/utmp" "/etc/utmp"; do
88     if test -r "$p"; then
89         found=yes
90         AC_MSG_RESULT([$p])
91         SUDO_DEFINE_UNQUOTED(_PATH_UTMP, "$p")
92         break
93     fi
94 done
95 if test X"$found" != X"yes"; then
96     AC_MSG_RESULT([not found])
97 fi
98 ])dnl
99
100 dnl
101 dnl Where the log file goes, use /var/log if it exists, else /{var,usr}/adm
102 dnl
103 AC_DEFUN([SUDO_LOGFILE], [AC_MSG_CHECKING(for log file location)
104 if test -n "$with_logpath"; then
105     AC_MSG_RESULT($with_logpath)
106     SUDO_DEFINE_UNQUOTED(_PATH_SUDO_LOGFILE, "$with_logpath")
107 elif test -d "/var/log"; then
108     AC_MSG_RESULT(/var/log/sudo.log)
109     SUDO_DEFINE(_PATH_SUDO_LOGFILE, "/var/log/sudo.log")
110 elif test -d "/var/adm"; then
111     AC_MSG_RESULT(/var/adm/sudo.log)
112     SUDO_DEFINE(_PATH_SUDO_LOGFILE, "/var/adm/sudo.log")
113 elif test -d "/usr/adm"; then
114     AC_MSG_RESULT(/usr/adm/sudo.log)
115     SUDO_DEFINE(_PATH_SUDO_LOGFILE, "/usr/adm/sudo.log")
116 else
117     AC_MSG_RESULT(unknown, you will have to set _PATH_SUDO_LOGFILE by hand)
118 fi
119 ])dnl
120
121 dnl
122 dnl Where the timestamp files go.
123 dnl
124 AC_DEFUN([SUDO_TIMEDIR], [AC_MSG_CHECKING(for timestamp file location)
125 timedir="$with_timedir"
126 if test -z "$timedir"; then
127     for d in /var/db /var/lib /var/adm /usr/adm; do
128         if test -d "$d"; then
129             timedir="$d/sudo"
130             break
131         fi
132     done
133 fi
134 AC_MSG_RESULT([$timedir])
135 SUDO_DEFINE_UNQUOTED(_PATH_SUDO_TIMEDIR, "$timedir")
136 ])dnl
137
138 dnl
139 dnl Where the I/O log files go, use /var/log/sudo-io if
140 dnl /var/log exists, else /{var,usr}/adm/sudo-io
141 dnl
142 AC_DEFUN([SUDO_IO_LOGDIR], [
143     AC_MSG_CHECKING(for I/O log dir location)
144     if test "${with_iologdir-yes}" != "yes"; then
145         iolog_dir="$with_iologdir"
146     elif test -d "/var/log"; then
147         iolog_dir="/var/log/sudo-io"
148     elif test -d "/var/adm"; then
149         iolog_dir="/var/adm/sudo-io"
150     else
151         iolog_dir="/usr/adm/sudo-io"
152     fi
153     if test "${with_iologdir}" != "no"; then
154         SUDO_DEFINE_UNQUOTED(_PATH_SUDO_IO_LOGDIR, "$iolog_dir")
155     fi
156     AC_MSG_RESULT($iolog_dir)
157 ])dnl
158
159 dnl
160 dnl check for working fnmatch(3)
161 dnl
162 AC_DEFUN([SUDO_FUNC_FNMATCH],
163 [AC_MSG_CHECKING([for working fnmatch with FNM_CASEFOLD])
164 AC_CACHE_VAL(sudo_cv_func_fnmatch,
165 [rm -f conftestdata; > conftestdata
166 AC_TRY_RUN([#include <fnmatch.h>
167 main() { exit(fnmatch("/*/bin/echo *", "/usr/bin/echo just a test", FNM_CASEFOLD)); }], [sudo_cv_func_fnmatch=yes], [sudo_cv_func_fnmatch=no],
168   [sudo_cv_func_fnmatch=no])
169 rm -f core core.* *.core])
170 AC_MSG_RESULT($sudo_cv_func_fnmatch)
171 AS_IF([test $sudo_cv_func_fnmatch = yes], [$1], [$2])])
172
173 dnl
174 dnl check for isblank(3)
175 dnl
176 AC_DEFUN([SUDO_FUNC_ISBLANK],
177   [AC_CACHE_CHECK([for isblank], [sudo_cv_func_isblank],
178     [AC_TRY_LINK([#include <ctype.h>], [return (isblank('a'));],
179     sudo_cv_func_isblank=yes, sudo_cv_func_isblank=no)])
180 ] [
181   if test "$sudo_cv_func_isblank" = "yes"; then
182     AC_DEFINE(HAVE_ISBLANK, 1, [Define if you have isblank(3).])
183   else
184     AC_LIBOBJ(isblank)
185   fi
186 ])
187
188 AC_DEFUN([SUDO_CHECK_LIB], [
189     _sudo_check_lib_extras=`echo "$5"|sed -e 's/[       ]*//g' -e 's/-l/_/g'`
190     AC_MSG_CHECKING([for $2 in -l$1${5+ }$5])
191     AC_CACHE_VAL([sudo_cv_lib_$1''_$2$_sudo_check_lib_extras], [
192         SUDO_CHECK_LIB_OLIBS="$LIBS"
193         LIBS="$LIBS -l$1${5+ }$5"
194         AC_LINK_IFELSE(
195             [AC_LANG_CALL([], [$2])],
196             [eval sudo_cv_lib_$1''_$2$_sudo_check_lib_extras=yes],
197             [eval sudo_cv_lib_$1''_$2$_sudo_check_lib_extras=no]
198         )
199         LIBS="$SUDO_CHECK_LIB_OLIBS"
200     ])
201     if eval test \$sudo_cv_lib_$1''_$2$_sudo_check_lib_extras = "yes"; then
202         AC_MSG_RESULT([yes])
203         $3
204     else
205         AC_MSG_RESULT([no])
206         $4
207     fi
208 ])
209
210 dnl
211 dnl check unsetenv() return value
212 dnl
213 AC_DEFUN([SUDO_FUNC_UNSETENV_VOID],
214   [AC_CACHE_CHECK([whether unsetenv returns void], [sudo_cv_func_unsetenv_void],
215     [AC_RUN_IFELSE([AC_LANG_PROGRAM(
216       [AC_INCLUDES_DEFAULT
217         int unsetenv();
218       ], [
219         [return unsetenv("FOO") != 0;]
220       ])
221     ],
222     [sudo_cv_func_unsetenv_void=no],
223     [sudo_cv_func_unsetenv_void=yes],
224     [sudo_cv_func_unsetenv_void=no])])
225     if test $sudo_cv_func_unsetenv_void = yes; then
226       AC_DEFINE(UNSETENV_VOID, 1,
227         [Define to 1 if the `unsetenv' function returns void instead of `int'.])
228     fi
229   ])
230
231 dnl
232 dnl check putenv() argument for const
233 dnl
234 AC_DEFUN([SUDO_FUNC_PUTENV_CONST],
235 [AC_CACHE_CHECK([whether putenv takes a const argument],
236 sudo_cv_func_putenv_const,
237 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT
238 int putenv(const char *string) {return 0;}], [])],
239     [sudo_cv_func_putenv_const=yes],
240     [sudo_cv_func_putenv_const=no])
241   ])
242   if test $sudo_cv_func_putenv_const = yes; then
243     AC_DEFINE(PUTENV_CONST, const, [Define to const if the `putenv' takes a const argument.])
244   else
245     AC_DEFINE(PUTENV_CONST, [])
246   fi
247 ])
248
249 dnl
250 dnl check for sa_len field in struct sockaddr
251 dnl
252 AC_DEFUN([SUDO_SOCK_SA_LEN], [
253     AC_CHECK_MEMBER([struct sockaddr.sa_len], 
254         [AC_DEFINE(HAVE_STRUCT_SOCKADDR_SA_LEN, 1, [Define if your struct sockadr has an sa_len field.])],    
255         [],
256         [ #include <sys/types.h>
257           #include <sys/socket.h>] 
258     )]
259 )
260 dnl
261 dnl check for max length of uid_t in string representation.
262 dnl we can't really trust UID_MAX or MAXUID since they may exist
263 dnl only for backwards compatibility.
264 dnl
265 AC_DEFUN([SUDO_UID_T_LEN],
266 [AC_REQUIRE([AC_TYPE_UID_T])
267 AC_MSG_CHECKING(max length of uid_t)
268 AC_CACHE_VAL(sudo_cv_uid_t_len,
269 [rm -f conftestdata
270 AC_TRY_RUN(
271 [#include <stdio.h>
272 #include <pwd.h>
273 #include <limits.h>
274 #include <sys/types.h>
275 #include <sys/param.h>
276 main() {
277   FILE *f;
278   char b[1024];
279   uid_t u = (uid_t) -1;
280
281   if ((f = fopen("conftestdata", "w")) == NULL)
282     exit(1);
283
284   (void) sprintf(b, "%lu", (unsigned long) u);
285   (void) fprintf(f, "%d\n", strlen(b));
286   (void) fclose(f);
287   exit(0);
288 }], sudo_cv_uid_t_len=`cat conftestdata`, sudo_cv_uid_t_len=10, sudo_cv_uid_t_len=10)
289 ])
290 rm -f conftestdata
291 AC_MSG_RESULT($sudo_cv_uid_t_len)
292 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).])
293 ])
294
295 dnl
296 dnl append a libpath to an LDFLAGS style variable
297 dnl
298 AC_DEFUN([SUDO_APPEND_LIBPATH], [
299     if test X"$with_rpath" = X"yes"; then
300         case "$host" in
301             *-*-hpux*)  $1="${$1} -L$2 -Wl,+b,$2"
302                         ;;
303             *)          $1="${$1} -L$2 -Wl,-R$2"
304                         ;;
305         esac
306     else
307         $1="${$1} -L$2"
308     fi
309     if test X"$blibpath" != X"" -a "$1" = "SUDO_LDFLAGS"; then
310         blibpath_add="${blibpath_add}:$2"
311     fi
312 ])
313
314 dnl
315 dnl Determine the mail spool location
316 dnl NOTE: must be run *after* check for paths.h
317 dnl
318 AC_DEFUN([SUDO_MAILDIR], [
319 maildir=no
320 if test X"$ac_cv_header_paths_h" = X"yes"; then
321 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT
322 #include <paths.h>],
323 [char *p = _PATH_MAILDIR;])], [maildir=yes], [])
324 fi
325 if test $maildir = no; then
326     # Solaris has maillock.h which defines MAILDIR
327     AC_CHECK_HEADERS(maillock.h, [
328         SUDO_DEFINE(_PATH_MAILDIR, MAILDIR)
329         maildir=yes
330     ])
331     if test $maildir = no; then
332         for d in /var/mail /var/spool/mail /usr/spool/mail; do
333             if test -d "$d"; then
334                 maildir=yes
335                 SUDO_DEFINE_UNQUOTED(_PATH_MAILDIR, "$d")
336                 break
337             fi
338         done
339         if test $maildir = no; then
340             # unable to find mail dir, hope for the best
341             SUDO_DEFINE_UNQUOTED(_PATH_MAILDIR, "/var/mail")
342         fi
343     fi
344 fi
345 ])
346
347 dnl
348 dnl private versions of AC_DEFINE and AC_DEFINE_UNQUOTED that don't support
349 dnl tracing that we use to define paths for pathnames.h so autoheader doesn't
350 dnl put them in config.h.in.  An awful hack.
351 dnl
352 m4_define([SUDO_DEFINE],
353 [cat >>confdefs.h <<\EOF
354 [@%:@define] $1 m4_if($#, 2, [$2], $#, 3, [$2], 1)
355 EOF
356 ])
357
358 m4_define([SUDO_DEFINE_UNQUOTED],
359 [cat >>confdefs.h <<EOF
360 [@%:@define] $1 m4_if($#, 2, [$2], $#, 3, [$2], 1)
361 EOF
362 ])
363
364 dnl
365 dnl Pull in libtool macros
366 dnl
367 m4_include([libtool.m4])
368 m4_include([ltoptions.m4])
369 m4_include([ltsugar.m4])
370 m4_include([ltversion.m4])
371 m4_include([lt~obsolete.m4])