New macro for testing whether the compiler supports a given
[krb5.git] / src / aclocal.m4
1 AC_PREREQ(2.52)
2 AC_COPYRIGHT([Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2007, 2008
3 Massachusetts Institute of Technology.
4 ])
5 dnl
6 dnl Figure out the top of the source and build trees.  We depend on localdir
7 dnl being a relative pathname; we could make it general later, but for now 
8 dnl this is good enough.
9 dnl
10 dnl esyscmd([test -r aclocal.m4 && echo YES])
11 define([fileexists],[dnl
12 pushdef([x],esyscmd([if test -r $1; then echo YES;else echo NO; fi]))dnl
13 dnl Strip out newline.
14 ifelse(x,[YES
15 ],[YES],x,[NO
16 ],[NO],UNKNOWN)[]popdef([x])])
17 define([K5_TOPDIR],dnl
18 ifelse(fileexists(./aclocal.m4),YES,[.],[dnl
19 ifelse(fileexists(../aclocal.m4),YES,[..],[dnl
20 ifelse(fileexists(../../aclocal.m4),YES,[../..],[dnl
21 ifelse(fileexists(../../../aclocal.m4),YES,[../../..],[dnl
22 ifelse(fileexists(../../../../aclocal.m4),YES,[../../../..],[dnl
23 errprint(__file__:__line__: Cannot find path to aclocal.m4[
24 ]) m4exit(1) dnl sometimes that does not work?
25 builtin(m4exit,1)UNKNOWN])])])])]))
26 dnl
27 AC_DEFUN(V5_SET_TOPDIR,[dnl
28 ac_reltopdir="K5_TOPDIR"
29 if test ! -r "$srcdir/K5_TOPDIR/aclocal.m4"; then
30   AC_MSG_ERROR([Configure could not determine the relative topdir])
31 fi
32 ac_topdir=$srcdir/$ac_reltopdir
33 ac_config_fragdir=$ac_reltopdir/config
34 # echo "Looking for $srcdir/$ac_config_fragdir"
35 if test -d "$srcdir/$ac_config_fragdir"; then
36   AC_CONFIG_AUX_DIR(K5_TOPDIR/config)
37 else
38   AC_MSG_ERROR([can not find config/ directory in $ac_reltopdir])
39 fi
40 ])dnl
41 dnl
42 dnl Version info.
43 dnl
44 pushdef([x],esyscmd([sed -n 's/#define \([A-Z0-9_]*\)[ \t]*\(.*\)/\1=\2/p' < ]K5_TOPDIR/patchlevel.h))
45 define([PL_KRB5_MAJOR_RELEASE],regexp(x,[KRB5_MAJOR_RELEASE=\(.*\)],[\1]))
46 ifelse(PL_KRB5_MAJOR_RELEASE,,[errprint([Can't determine KRB5_MAJOR_RELEASE value from patchlevel.h.
47 ]) m4exit(1) dnl sometimes that does not work?
48 builtin(m4exit,1)])
49 define([PL_KRB5_MINOR_RELEASE],regexp(x,[KRB5_MINOR_RELEASE=\(.*\)],[\1]))
50 ifelse(PL_KRB5_MINOR_RELEASE,,[errprint([Can't determine KRB5_MINOR_RELEASE value from patchlevel.h.
51 ]) m4exit(1) dnl sometimes that does not work?
52 builtin(m4exit,1)])
53 define([PL_KRB5_PATCHLEVEL],regexp(x,[KRB5_PATCHLEVEL=\(.*\)],[\1]))
54 ifelse(PL_KRB5_PATCHLEVEL,,[errprint([Can't determine KRB5_PATCHLEVEL value from patchlevel.h.
55 ]) m4exit(1) dnl sometimes that does not work?
56 builtin(m4exit,1)])
57 define([PL_KRB5_RELTAIL],regexp(x,[KRB5_RELTAIL="\(.*\)"],[\1]))
58 dnl RELTAIL is allowed to not be defined.
59 popdef([x])
60 define([K5_VERSION],PL_KRB5_MAJOR_RELEASE.PL_KRB5_MINOR_RELEASE[]ifelse(PL_KRB5_PATCHLEVEL,0,,.PL_KRB5_PATCHLEVEL)ifelse(PL_KRB5_RELTAIL,,,-PL_KRB5_RELTAIL))
61 define([K5_BUGADDR],krb5-bugs@mit.edu)
62 define([K5_AC_INIT],[AC_INIT(Kerberos 5, K5_VERSION, K5_BUGADDR, krb5)
63 AC_CONFIG_SRCDIR($1)
64 build_dynobj=no])
65 dnl
66 dnl drop in standard rules for all configure files -- CONFIG_RULES
67 dnl
68 AC_DEFUN(CONFIG_RULES,[dnl
69 AC_REQUIRE([V5_SET_TOPDIR]) dnl
70 EXTRA_FILES=""
71 AC_SUBST(EXTRA_FILES)
72 WITH_CC dnl
73 AC_REQUIRE_CPP
74 if test -z "$LD" ; then LD=$CC; fi
75 AC_ARG_VAR(LD,[linker command [CC]])
76 AC_SUBST(LDFLAGS) dnl
77 WITH_KRB4 dnl
78 KRB5_AC_CHOOSE_ET dnl
79 KRB5_AC_CHOOSE_SS dnl
80 KRB5_AC_CHOOSE_DB dnl
81 dnl allow stuff in tree to access deprecated stuff for now
82 dnl AC_DEFINE([KRB5_DEPRECATED], 1, [Define only if building in-tree])
83 AC_C_CONST dnl
84 WITH_NETLIB dnl
85 WITH_HESIOD dnl
86 KRB5_AC_MAINTAINER_MODE dnl
87 AC_ARG_PROGRAM dnl
88 dnl
89 dnl This identifies the top of the source tree relative to the directory 
90 dnl in which the configure file lives.
91 dnl
92 CONFIG_RELTOPDIR=$ac_reltopdir
93 AC_SUBST(CONFIG_RELTOPDIR)
94 AC_SUBST(subdirs)
95 lib_frag=$srcdir/$ac_config_fragdir/lib.in
96 AC_SUBST_FILE(lib_frag)
97 libobj_frag=$srcdir/$ac_config_fragdir/libobj.in
98 AC_SUBST_FILE(libobj_frag)
99 libnover_frag=$srcdir/$ac_config_fragdir/libnover.in
100 AC_SUBST_FILE(libnover_frag)
101 libpriv_frag=$srcdir/$ac_config_fragdir/libpriv.in
102 AC_SUBST_FILE(libpriv_frag)
103 libnodeps_frag=$srcdir/$ac_config_fragdir/libnodeps.in
104 AC_SUBST_FILE(libnodeps_frag)
105 dnl
106 KRB5_AC_PRAGMA_WEAK_REF
107 WITH_LDAP
108 KRB5_LIB_PARAMS
109 KRB5_AC_INITFINI
110 KRB5_AC_ENABLE_THREADS
111 KRB5_AC_FIND_DLOPEN
112 KRB5_AC_KEYRING_CCACHE
113 ])dnl
114
115 dnl Maintainer mode, akin to what automake provides, 'cept we don't
116 dnl want to use automake right now.
117 AC_DEFUN([KRB5_AC_MAINTAINER_MODE],
118 [AC_ARG_ENABLE([maintainer-mode],
119 AC_HELP_STRING([--enable-maintainer-mode],[enable rebuilding of source files, Makefiles, etc]),
120 USE_MAINTAINER_MODE=$enableval,
121 USE_MAINTAINER_MODE=no)
122 if test "$USE_MAINTAINER_MODE" = yes; then
123   MAINTAINER_MODE_TRUE=
124   MAINTAINER_MODE_FALSE='#'
125   AC_MSG_NOTICE(enabling maintainer mode)
126 else
127   MAINTAINER_MODE_TRUE='#'
128   MAINTAINER_MODE_FALSE=
129 fi
130 MAINT=$MAINTAINER_MODE_TRUE
131 AC_SUBST(MAINTAINER_MODE_TRUE)
132 AC_SUBST(MAINTAINER_MODE_FALSE)
133 AC_SUBST(MAINT)
134 ])
135
136 dnl
137 AC_DEFUN([KRB5_AC_INITFINI],[
138 dnl Do we want initialization at load time?
139 AC_ARG_ENABLE([delayed-initialization],
140 AC_HELP_STRING([--disable-delayed-initialization],initialize library code when loaded @<:@delay until first use@:>@), , enable_delayed_initialization=yes)
141 case "$enable_delayed_initialization" in
142   yes)
143     AC_DEFINE(DELAY_INITIALIZER,1,[Define if library initialization should be delayed until first use]) ;;
144   no) ;;
145   *)  AC_MSG_ERROR(invalid option $enable_delayed_initialization for delayed-initialization) ;;
146 esac
147 dnl We always want finalization at unload time.
148 dnl
149 dnl Can we do things through gcc?
150 KRB5_AC_GCC_ATTRS
151 dnl How about with the linker?
152 if test -z "$use_linker_init_option" ; then
153   AC_MSG_ERROR(ran INITFINI before checking shlib.conf?)
154 fi
155 if test "$use_linker_init_option" = yes; then
156   AC_DEFINE(USE_LINKER_INIT_OPTION,1,[Define if link-time options for library initialization will be used])
157 fi
158 if test "$use_linker_fini_option" = yes; then
159   AC_DEFINE(USE_LINKER_FINI_OPTION,1,[Define if link-time options for library finalization will be used])
160 fi
161 ])
162
163 dnl find dlopen
164 AC_DEFUN([KRB5_AC_FIND_DLOPEN],[
165 old_LIBS="$LIBS"
166 DL_LIB=
167 AC_SEARCH_LIBS(dlopen, dl, [
168 if test "$ac_cv_search_dlopen" != "none required"; then
169   DL_LIB=$ac_cv_search_dlopen
170 fi
171 LIBS="$old_LIBS"
172 AC_DEFINE(USE_DLOPEN,1,[Define if dlopen should be used])])
173 AC_SUBST(DL_LIB)
174 ])
175
176
177 dnl Hack for now.
178 AC_DEFUN([KRB5_AC_ENABLE_THREADS],[
179 AC_ARG_ENABLE([thread-support],
180 AC_HELP_STRING([--disable-thread-support],don't enable thread support @<:@enabled@:>@), , enable_thread_support=yes)
181 if test "$enable_thread_support" = yes ; then
182   AC_MSG_NOTICE(enabling thread support)
183   AC_DEFINE(ENABLE_THREADS,1,[Define if thread support enabled])
184 fi
185 dnl Maybe this should be inside the conditional above?  Doesn't cache....
186 if test "$enable_thread_support" = yes; then
187   ACX_PTHREAD(,[AC_MSG_ERROR([cannot determine options for enabling thread support; try --disable-thread-support])])
188   AC_MSG_NOTICE(PTHREAD_CC = $PTHREAD_CC)
189   AC_MSG_NOTICE(PTHREAD_CFLAGS = $PTHREAD_CFLAGS)
190   AC_MSG_NOTICE(PTHREAD_LIBS = $PTHREAD_LIBS)
191   dnl Not really needed -- if pthread.h isn't found, ACX_PTHREAD will fail.
192   dnl AC_CHECK_HEADERS(pthread.h)
193   # AIX and Tru64 don't support weak references, and don't have
194   # stub versions of the pthread code in libc.
195   case "${host_os}" in
196     aix* | osf*)
197       # On these platforms, we'll always pull in the thread support.
198       LIBS="$LIBS $PTHREAD_LIBS"
199       CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
200       # We don't need to sometimes add the flags we've just folded in...
201       PTHREAD_LIBS=
202       PTHREAD_CFLAGS=
203       ;;
204     hpux*)
205       # These are the flags that "gcc -pthread" adds.  But we don't
206       # want "-pthread" because that has link-time effects, and we
207       # don't exclude CFLAGS when linking.  *sigh*
208       PTHREAD_CFLAGS="-D_REENTRANT -D_THREAD_SAFE -D_POSIX_C_SOURCE=199506L"
209       ;;
210     solaris2.[1-9])
211       # On Solaris 10 with gcc 3.4.3, the autoconf archive macro doesn't
212       # get the right result.   XXX What about Solaris 9 and earlier?
213       if test "$GCC" = yes ; then
214         PTHREAD_CFLAGS="-D_REENTRANT -pthreads"
215       fi
216       ;;
217     solaris*)
218       # On Solaris 10 with gcc 3.4.3, the autoconf archive macro doesn't
219       # get the right result.
220       if test "$GCC" = yes ; then
221         PTHREAD_CFLAGS="-D_REENTRANT -pthreads"
222       fi
223       # On Solaris 10, the thread support is always available in libc.
224       AC_DEFINE(NO_WEAK_PTHREADS,1,[Define if references to pthread routines should be non-weak.])
225       ;;
226   esac
227   THREAD_SUPPORT=1
228 else
229   PTHREAD_CC="$CC"
230   PTHREAD_CFLAGS=""
231   PTHREAD_LIBS=""
232   THREAD_SUPPORT=0
233 fi
234 AC_SUBST(THREAD_SUPPORT)
235 dnl We want to know where these routines live, so on systems with weak
236 dnl reference support we can figure out whether or not the pthread library
237 dnl has been linked in.
238 dnl If we don't add any libraries for thread support, don't bother.
239 AC_CHECK_FUNCS(pthread_once pthread_rwlock_init)
240 old_CC="$CC"
241 test "$PTHREAD_CC" != "" && test "$ac_cv_c_compiler_gnu" = no && CC=$PTHREAD_CC
242 old_CFLAGS="$CFLAGS"
243 # On Solaris, -pthreads is added to CFLAGS, no extra explicit libraries.
244 CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
245 AC_SUBST(PTHREAD_CFLAGS)
246 old_LIBS="$LIBS"
247 LIBS="$PTHREAD_LIBS $LIBS"
248 AC_MSG_NOTICE(rechecking with PTHREAD_... options)
249 AC_CHECK_LIB(c, pthread_rwlock_init,
250   [AC_DEFINE(HAVE_PTHREAD_RWLOCK_INIT_IN_THREAD_LIB,1,[Define if pthread_rwlock_init is provided in the thread library.])])
251 LIBS="$old_LIBS"
252 CC="$old_CC"
253 CFLAGS="$old_CFLAGS"
254 ])
255
256 dnl This is somewhat gross and should go away when the build system
257 dnl is revamped. -- tlyu
258 dnl DECLARE_SYS_ERRLIST - check for sys_errlist in libc
259 dnl
260 AC_DEFUN([DECLARE_SYS_ERRLIST],
261 [AC_CACHE_CHECK([for sys_errlist declaration], krb5_cv_decl_sys_errlist,
262 [AC_TRY_COMPILE([#include <stdio.h>
263 #include <errno.h>], [1+sys_nerr;],
264 krb5_cv_decl_sys_errlist=yes, krb5_cv_decl_sys_errlist=no)])
265 # assume sys_nerr won't be declared w/o being in libc
266 if test $krb5_cv_decl_sys_errlist = yes; then
267   AC_DEFINE(SYS_ERRLIST_DECLARED,1,[Define if sys_errlist is defined in errno.h])
268   AC_DEFINE(HAVE_SYS_ERRLIST,1,[Define if sys_errlist in libc])
269 else
270   # This means that sys_errlist is not declared in errno.h, but may still
271   # be in libc.
272   AC_CACHE_CHECK([for sys_errlist in libc], krb5_cv_var_sys_errlist,
273   [AC_TRY_LINK([extern int sys_nerr;], [if (1+sys_nerr < 0) return 1;],
274   krb5_cv_var_sys_errlist=yes, krb5_cv_var_sys_errlist=no;)])
275   if test $krb5_cv_var_sys_errlist = yes; then
276     AC_DEFINE(HAVE_SYS_ERRLIST,1,[Define if sys_errlist in libc])
277     # Do this cruft for backwards compatibility for now.
278     AC_DEFINE(NEED_SYS_ERRLIST,1,[Define if need to declare sys_errlist])
279   else
280     AC_MSG_WARN([sys_errlist is neither in errno.h nor in libc])
281   fi
282 fi])
283
284 dnl
285 dnl check for sigmask/sigprocmask -- CHECK_SIGPROCMASK
286 dnl
287 AC_DEFUN(CHECK_SIGPROCMASK,[
288 AC_MSG_CHECKING([for use of sigprocmask])
289 AC_CACHE_VAL(krb5_cv_func_sigprocmask_use,
290 [AC_TRY_LINK([#include <signal.h>], [sigprocmask(SIG_SETMASK,0,0);],
291  krb5_cv_func_sigprocmask_use=yes,
292 AC_TRY_LINK([#include <signal.h>], [sigmask(1);], 
293  krb5_cv_func_sigprocmask_use=no, krb5_cv_func_sigprocmask_use=yes))])
294 AC_MSG_RESULT($krb5_cv_func_sigprocmask_use)
295 if test $krb5_cv_func_sigprocmask_use = yes; then
296  AC_DEFINE(USE_SIGPROCMASK,1,[Define if sigprocmask should be used])
297 fi
298 ])dnl
299 dnl
300 AC_DEFUN(AC_PROG_ARCHIVE, [AC_CHECK_PROG(ARCHIVE, ar, ar cqv, false)])dnl
301 AC_DEFUN(AC_PROG_ARCHIVE_ADD, [AC_CHECK_PROG(ARADD, ar, ar cruv, false)])dnl
302 dnl
303 dnl check for <dirent.h> -- CHECK_DIRENT
304 dnl (may need to be more complex later)
305 dnl
306 AC_DEFUN(CHECK_DIRENT,[
307 AC_CHECK_HEADER(dirent.h,AC_DEFINE(USE_DIRENT_H,1,[Define if you have dirent.h functionality]))])dnl
308 dnl
309 dnl check if union wait is defined, or if WAIT_USES_INT -- CHECK_WAIT_TYPE
310 dnl
311 AC_DEFUN(CHECK_WAIT_TYPE,[
312 AC_MSG_CHECKING([if argument to wait is int *])
313 AC_CACHE_VAL(krb5_cv_struct_wait,
314 dnl Test for prototype clash - if there is none - then assume int * works
315 [AC_TRY_COMPILE([#include <sys/types.h>
316 #include <sys/wait.h>
317 extern pid_t wait(int *);],[], krb5_cv_struct_wait=no,dnl
318 dnl Else fallback on old stuff
319 [AC_TRY_COMPILE(
320 [#include <sys/wait.h>], [union wait i;
321 #ifdef WEXITSTATUS
322   WEXITSTATUS (i);
323 #endif
324 ], 
325         krb5_cv_struct_wait=yes, krb5_cv_struct_wait=no)])])
326 AC_MSG_RESULT($krb5_cv_struct_wait)
327 if test $krb5_cv_struct_wait = no; then
328         AC_DEFINE(WAIT_USES_INT,1,[Define if wait takes int as a argument])
329 fi
330 ])dnl
331 dnl
332 dnl check for POSIX signal handling -- CHECK_SIGNALS
333 dnl
334 AC_DEFUN(CHECK_SIGNALS,[
335 AC_CHECK_FUNC(sigprocmask,
336 AC_MSG_CHECKING(for sigset_t and POSIX_SIGNALS)
337 AC_CACHE_VAL(krb5_cv_type_sigset_t,
338 [AC_TRY_COMPILE(
339 [#include <signal.h>],
340 [sigset_t x],
341 krb5_cv_type_sigset_t=yes, krb5_cv_type_sigset_t=no)])
342 AC_MSG_RESULT($krb5_cv_type_sigset_t)
343 if test $krb5_cv_type_sigset_t = yes; then
344   AC_DEFINE(POSIX_SIGNALS,1,[Define if POSIX signal handling is used])
345 fi
346 )])dnl
347 dnl
348 dnl check for signal type
349 dnl
350 dnl AC_RETSIGTYPE isn't quite right, but almost.
351 AC_DEFUN(KRB5_SIGTYPE,[
352 AC_MSG_CHECKING([POSIX signal handlers])
353 AC_CACHE_VAL(krb5_cv_has_posix_signals,
354 [AC_TRY_COMPILE(
355 [#include <sys/types.h>
356 #include <signal.h>
357 #ifdef signal
358 #undef signal
359 #endif
360 extern void (*signal ()) ();], [],
361 krb5_cv_has_posix_signals=yes, krb5_cv_has_posix_signals=no)])
362 AC_MSG_RESULT($krb5_cv_has_posix_signals)
363 if test $krb5_cv_has_posix_signals = yes; then
364    stype=void
365    AC_DEFINE(POSIX_SIGTYPE, 1, [Define if POSIX signal handlers are used])
366 else
367   if test $ac_cv_type_signal = void; then
368      stype=void
369   else
370      stype=int
371   fi
372 fi
373 AC_DEFINE_UNQUOTED(krb5_sigtype, $stype, [Define krb5_sigtype to type of signal handler])dnl
374 ])dnl
375 dnl
376 dnl check for POSIX setjmp/longjmp -- CHECK_SETJMP
377 dnl
378 AC_DEFUN(CHECK_SETJMP,[
379 AC_CHECK_FUNC(sigsetjmp,
380 AC_MSG_CHECKING(for sigjmp_buf)
381 AC_CACHE_VAL(krb5_cv_struct_sigjmp_buf,
382 [AC_TRY_COMPILE(
383 [#include <setjmp.h>],[sigjmp_buf x],
384 krb5_cv_struct_sigjmp_buf=yes,krb5_cv_struct_sigjmp_buf=no)])
385 AC_MSG_RESULT($krb5_cv_struct_sigjmp_buf)
386 if test $krb5_cv_struct_sigjmp_buf = yes; then
387   AC_DEFINE(POSIX_SETJMP,1,[Define if setjmp indicates POSIX interface])
388 fi
389 )])dnl
390 dnl
391 dnl Check for IPv6 compile-time support.
392 dnl
393 AC_DEFUN(KRB5_AC_INET6,[
394 AC_CHECK_HEADERS(sys/types.h sys/socket.h netinet/in.h netdb.h)
395 AC_CHECK_FUNCS(inet_ntop inet_pton getnameinfo)
396 dnl getaddrinfo test needs netdb.h, for proper compilation on alpha
397 dnl under OSF/1^H^H^H^H^HDigital^H^H^H^H^H^H^HTru64 UNIX, where it's
398 dnl a macro
399 AC_MSG_CHECKING(for getaddrinfo)
400 AC_CACHE_VAL(ac_cv_func_getaddrinfo,
401 [AC_TRY_LINK([#ifdef HAVE_NETDB_H
402 #include <netdb.h>
403 #endif],[
404 struct addrinfo *ai;
405 getaddrinfo("kerberos.mit.edu", "echo", 0, &ai);
406 ], ac_cv_func_getaddrinfo=yes, ac_cv_func_getaddrinfo=no)])
407 AC_MSG_RESULT($ac_cv_func_getaddrinfo)
408 if test $ac_cv_func_getaddrinfo = yes; then
409   AC_DEFINE(HAVE_GETADDRINFO,1,[Define if you have the getaddrinfo function])
410 fi
411 dnl
412 AC_REQUIRE([KRB5_SOCKADDR_SA_LEN])dnl
413 AC_ARG_ENABLE([ipv6], , AC_MSG_WARN(enable/disable-ipv6 option is deprecated))dnl
414 AC_MSG_CHECKING(for IPv6 compile-time support)
415 AC_CACHE_VAL(krb5_cv_inet6,[
416 if test "$ac_cv_func_inet_ntop" != "yes" ; then
417   krb5_cv_inet6=no
418 else
419 AC_TRY_COMPILE([
420 #ifdef HAVE_SYS_TYPES_H
421 #include <sys/types.h>
422 #endif
423 #include <sys/socket.h>
424 #include <netinet/in.h>
425 #include <netdb.h>
426 ],[
427   struct sockaddr_in6 in;
428   AF_INET6;
429   IN6_IS_ADDR_LINKLOCAL (&in.sin6_addr);
430 ],krb5_cv_inet6=yes,krb5_cv_inet6=no)])
431 fi
432 AC_MSG_RESULT($krb5_cv_inet6)
433 if test "$krb5_cv_inet6" = no && test "$ac_cv_func_inet_ntop" = yes; then
434 AC_MSG_CHECKING(for IPv6 compile-time support with -DINET6)
435 AC_CACHE_VAL(krb5_cv_inet6_with_dinet6,[
436 old_CC="$CC"
437 CC="$CC -DINET6"
438 AC_TRY_COMPILE([
439 #ifdef HAVE_SYS_TYPES_H
440 #include <sys/types.h>
441 #endif
442 #include <sys/socket.h>
443 #include <netinet/in.h>
444 #include <netdb.h>
445 ],[
446   struct sockaddr_in6 in;
447   AF_INET6;
448   IN6_IS_ADDR_LINKLOCAL (&in.sin6_addr);
449 ],krb5_cv_inet6_with_dinet6=yes,krb5_cv_inet6_with_dinet6=no)
450 CC="$old_CC"])
451 AC_MSG_RESULT($krb5_cv_inet6_with_dinet6)
452 fi
453 if test $krb5_cv_inet6 = yes || test "$krb5_cv_inet6_with_dinet6" = yes; then
454   if test "$krb5_cv_inet6_with_dinet6" = yes; then
455     AC_DEFINE(INET6,1,[May need to be defined to enable IPv6 support, for example on IRIX])
456   fi
457   AC_DEFINE(KRB5_USE_INET6,1,[Define if we should compile in IPv6 support (even if we can't use it at run time)])
458 fi
459 ])dnl
460 dnl
461 dnl Generic File existence tests
462 dnl 
463 dnl K5_AC_CHECK_FILE(FILE, [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]])
464 dnl
465 AC_DEFUN(K5_AC_CHECK_FILE,
466 [AC_REQUIRE([AC_PROG_CC])dnl
467 dnl Do the transliteration at runtime so arg 1 can be a shell variable.
468 ac_safe=`echo "$1" | sed 'y%./+-%__p_%'`
469 AC_MSG_CHECKING([for $1])
470 AC_CACHE_VAL(ac_cv_file_$ac_safe,
471 [if test "$cross_compiling" = yes; then
472   errprint(__file__:__line__: warning: Cannot check for file existence when cross compiling
473 )dnl
474   AC_MSG_ERROR(Cannot check for file existence when cross compiling)
475 else
476   if test -r $1; then
477     eval "ac_cv_file_$ac_safe=yes"
478   else
479     eval "ac_cv_file_$ac_safe=no"
480   fi
481 fi])dnl
482 if eval "test \"`echo '$ac_cv_file_'$ac_safe`\" = yes"; then
483   AC_MSG_RESULT(yes)
484   ifelse([$2], , :, [$2])
485 else
486   AC_MSG_RESULT(no)
487 ifelse([$3], , , [$3
488 np])dnl
489 fi
490 ])
491 dnl
492 dnl K5_AC_CHECK_FILES(FILE... [, ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]])
493 dnl
494 AC_DEFUN(K5_AC_CHECK_FILES,
495 [AC_REQUIRE([AC_PROG_CC])dnl
496 for ac_file in $1
497 do
498 K5_AC_CHECK_FILE($ac_file,
499 [changequote(, )dnl
500   ac_tr_file=HAVE`echo $ac_file | sed 'y%abcdefghijklmnopqrstuvwxyz./-%ABCDEFGHIJKLMNOPQRSTUVWXYZ___%'`
501 changequote([, ])dnl
502   AC_DEFINE_UNQUOTED($ac_tr_file) $2], $3)dnl
503 done
504 ])
505 dnl
506 dnl set $(KRB4) from --with-krb4=value -- WITH_KRB4
507 dnl
508 AC_DEFUN(WITH_KRB4,[
509 AC_ARG_WITH([krb4],
510 [  --without-krb4          omit Kerberos V4 backwards compatibility (default)
511   --with-krb4             use V4 libraries included with V5
512   --with-krb4=KRB4DIR     use preinstalled V4 libraries],
513 ,
514 withval=no
515 )dnl
516 if test $withval = no; then
517         AC_MSG_NOTICE(no krb4 support)
518         KRB4_LIB=
519         KRB4_DEPLIB=
520         KRB4_INCLUDES=
521         KRB4_LIBPATH=
522         KRB_ERR_H_DEP=
523         krb5_cv_build_krb4_libs=no
524         krb5_cv_krb4_libdir=
525 else
526  AC_DEFINE([KRB5_KRB4_COMPAT], 1, [Define this if building with krb4 compat])
527  if test $withval = yes; then
528         AC_MSG_NOTICE(enabling built in krb4 support)
529         KRB4_DEPLIB='$(TOPLIBD)/libkrb4$(DEPLIBEXT)'
530         KRB4_LIB=-lkrb4
531         KRB4_INCLUDES='-I$(SRCTOP)/include/kerberosIV -I$(BUILDTOP)/include/kerberosIV'
532         KRB4_LIBPATH=
533         KRB_ERR_H_DEP='$(BUILDTOP)/include/kerberosIV/krb_err.h'
534         krb5_cv_build_krb4_libs=yes
535         krb5_cv_krb4_libdir=
536  else
537         AC_MSG_NOTICE(using preinstalled krb4 in $withval)
538         KRB4_LIB="-lkrb"
539 dnl     DEPKRB4_LIB="$withval/lib/libkrb.a"
540         KRB4_INCLUDES="-I$withval/include"
541         KRB4_LIBPATH="-L$withval/lib"
542         KRB_ERR_H_DEP=
543         krb5_cv_build_krb4_libs=no
544         krb5_cv_krb4_libdir="$withval/lib"
545  fi
546 fi
547 AC_SUBST(KRB4_INCLUDES)
548 AC_SUBST(KRB4_LIBPATH)
549 AC_SUBST(KRB4_LIB)
550 AC_SUBST(KRB4_DEPLIB)
551 AC_SUBST(KRB_ERR_H_DEP)
552 dnl We always compile the des425 library
553 DES425_DEPLIB='$(TOPLIBD)/libdes425$(DEPLIBEXT)'
554 DES425_LIB=-ldes425
555 AC_SUBST(DES425_DEPLIB)
556 AC_SUBST(DES425_LIB)
557 ])dnl
558 dnl
559 dnl
560 AC_DEFUN(KRB5_AC_CHECK_FOR_CFLAGS,[
561 AC_BEFORE([$0],[AC_PROG_CC])
562 AC_BEFORE([$0],[AC_PROG_CXX])
563 krb5_ac_cflags_set=${CFLAGS+set}
564 krb5_ac_cxxflags_set=${CXXFLAGS+set}
565 ])
566 dnl
567 AC_DEFUN(TRY_CC_FLAG,[dnl
568   cachevar=`echo "krb5_cv_cc_flag_$1" | sed s/[[^a-zA-Z0-9_]]/_/g`
569   AC_CACHE_CHECK([if C compiler supports $1], [$cachevar],
570   [# first try without, then with
571   AC_TRY_COMPILE([], 1;,
572     [old_cflags="$CFLAGS"
573      CFLAGS="$CFLAGS $1"
574      AC_TRY_COMPILE([], 1;, eval $cachevar=yes, eval $cachevar=no)
575      CFLAGS="$old_cflags"],
576     [AC_MSG_ERROR(compiling simple test program with $CFLAGS failed)])])
577   if eval test '"${'$cachevar'}"' = yes; then
578     CFLAGS="$CFLAGS $1"
579   fi
580   eval flag_supported='${'$cachevar'}'
581 ])dnl
582 dnl
583 AC_DEFUN(WITH_CC,[dnl
584 AC_REQUIRE([KRB5_AC_CHECK_FOR_CFLAGS])dnl
585 AC_REQUIRE([AC_PROG_CC])dnl
586 AC_REQUIRE([AC_PROG_CXX])dnl
587 if test $ac_cv_c_compiler_gnu = yes ; then
588      HAVE_GCC=yes
589      else HAVE_GCC=
590 fi
591 AC_SUBST(HAVE_GCC)
592 AC_CACHE_CHECK([for GNU linker], krb5_cv_prog_gnu_ld,
593 [krb5_cv_prog_gnu_ld=no
594 if test "$GCC" = yes; then
595   if AC_TRY_COMMAND([$CC -Wl,-v 2>&1 dnl
596                         | grep "GNU ld" > /dev/null]); then
597     krb5_cv_prog_gnu_ld=yes
598   fi
599 fi])
600 AC_ARG_WITH([size-optimizations],
601 [  --with-size-optimizations enable a few optimizations to reduce code size
602                           possibly at some run-time cost],
603 ,
604 withval=no)
605 if test "$withval" = yes; then
606   AC_DEFINE(CONFIG_SMALL,1,[Define to reduce code size even if it means more cpu usage])
607 fi
608 # -Wno-long-long, if needed, for k5-platform.h without inttypes.h etc.
609 extra_gcc_warn_opts="-Wall -Wcast-qual -Wcast-align -Wconversion -Wshadow"
610 # -Wmissing-prototypes
611 if test "$GCC" = yes ; then
612   # Putting this here means we get -Os after -O2, which works.
613   if test "$with_size_optimizations" = yes && test "x$krb5_ac_cflags_set" != xset; then
614     AC_MSG_NOTICE(adding -Os optimization option)
615     case "$CFLAGS" in
616       "-g -O2") CFLAGS="-g -Os" ;;
617       "-O2")    CFLAGS="-Os" ;;
618       *)        CFLAGS="$CFLAGS -Os" ;;
619     esac
620   fi
621   if test "x$krb5_ac_cflags_set" = xset ; then
622     AC_MSG_NOTICE(not adding extra gcc warning flags because CFLAGS was set)
623   else
624     AC_MSG_NOTICE(adding extra warning flags for gcc)
625     CFLAGS="$CFLAGS $extra_gcc_warn_opts -Wmissing-prototypes"
626     if test "`uname -s`" = Darwin ; then
627       AC_MSG_NOTICE(skipping pedantic warnings on Darwin)
628     elif test "`uname -s`" = Linux ; then
629       AC_MSG_NOTICE(skipping pedantic warnings on Linux)
630     else
631       CFLAGS="$CFLAGS -pedantic"
632     fi
633     if test "$ac_cv_cxx_compiler_gnu" = yes; then
634       if test "x$krb5_ac_cxxflags_set" = xset ; then
635         AC_MSG_NOTICE(not adding extra g++ warnings because CXXFLAGS was set)
636       else
637         AC_MSG_NOTICE(adding extra warning flags for g++)
638         CXXFLAGS="$CXXFLAGS $extra_gcc_warn_opts"
639       fi
640     fi
641     # Currently, G++ does not support -Wno-format-zero-length.
642     TRY_CC_FLAG(-Wno-format-zero-length)
643     # Other flags here may not be supported on some versions of
644     # gcc that people want to use.
645     for flag in overflow strict-overflow missing-format-attribute ; do
646       TRY_CC_FLAG(-W$flag)
647     done
648     #  old-style-definition? generates many, many warnings
649     #
650     # Warnings that we'd like to turn into errors on versions of gcc
651     # that support promoting only specific warnings to errors, but
652     # we'll take as warnings on older compilers.  (If such a warning
653     # is added after the -Werror=foo feature, you can just put
654     # error=foo in the above list, and skip the test for the
655     # warning-only form.)  At least in some versions, -Werror= doesn't
656     # seem to make the conditions actual errors, but still issues
657     # warnings; I guess we'll take what we can get.
658     #
659     # We're currently targeting C89+, not C99, so disallow some
660     # constructs.
661     for flag in declaration-after-statement variadic-macros ; do
662       TRY_CC_FLAG(-Werror=$flag)
663       if test "$flag_supported" = no; then
664         TRY_CC_FLAG(-W$flag)
665       fi
666     done
667     #  missing-prototypes? maybe someday
668     #
669   fi
670   if test "`uname -s`" = Darwin ; then
671     # Someday this should be a feature test.
672     # One current (Jaguar = OS 10.2) problem:
673     # Archive library with foo.o undef sym X and bar.o common sym X,
674     # if foo.o is pulled in at link time, bar.o may not be, causing
675     # the linker to complain.
676     # Dynamic library problems too?
677     case "$CC $CFLAGS" in
678     *-fcommon*) ;; # why someone would do this, I don't know
679     *-fno-common*) ;; # okay, they're already doing the right thing
680     *)
681       AC_MSG_NOTICE(disabling the use of common storage on Darwin)
682       CFLAGS="$CFLAGS -fno-common"
683       ;;
684     esac
685     case "$LD $LDFLAGS" in
686     *-Wl,-search_paths_first*) ;;
687     *) LDFLAGS="${LDFLAGS} -Wl,-search_paths_first" ;;
688     esac
689   fi
690 else
691   if test "`uname -s`" = AIX ; then
692     # Using AIX but not GCC, assume native compiler.
693     # The native compiler appears not to give a nonzero exit
694     # status for certain classes of errors, like missing arguments
695     # in function calls.  Let's try to fix that with -qhalt=e.
696     case "$CC $CFLAGS" in
697       *-qhalt=*) ;;
698       *)
699         CFLAGS="$CFLAGS -qhalt=e"
700         AC_MSG_NOTICE(adding -qhalt=e for better error reporting)
701         ;;
702     esac
703     # Also, the optimizer isn't turned on by default, which means
704     # the static inline functions get left in random object files,
705     # leading to references to pthread_mutex_lock from anything that
706     # includes k5-int.h whether it uses threads or not.
707     case "$CC $CFLAGS" in
708       *-O*) ;;
709       *)
710         CFLAGS="$CFLAGS -O"
711         AC_MSG_NOTICE(adding -O for inline thread-support function elimination)
712         ;;
713     esac
714   fi
715 fi
716 ])dnl
717 dnl
718 dnl
719 dnl check for yylineno -- HAVE_YYLINENO
720 dnl
721 AC_DEFUN(HAVE_YYLINENO,[dnl
722 AC_REQUIRE_CPP()AC_REQUIRE([AC_PROG_LEX])dnl
723 AC_MSG_CHECKING([for yylineno declaration])
724 AC_CACHE_VAL(krb5_cv_type_yylineno,
725 # some systems have yylineno, others don't...
726   echo '%%
727 %%' | ${LEX} -t > conftest.out
728   if egrep yylineno conftest.out >/dev/null 2>&1; then
729         krb5_cv_type_yylineno=yes
730   else
731         krb5_cv_type_yylineno=no
732   fi
733   rm -f conftest.out)
734   AC_MSG_RESULT($krb5_cv_type_yylineno)
735   if test $krb5_cv_type_yylineno = no; then
736         AC_DEFINE(NO_YYLINENO, 1, [Define if lex produes code with yylineno])
737   fi
738 ])dnl
739 dnl
740 dnl K5_GEN_MAKEFILE([dir, [frags]])
741 dnl
742 AC_DEFUN(K5_GEN_MAKEFILE,[dnl
743 ifelse($1, ,[_K5_GEN_MAKEFILE(.,$2)],[_K5_GEN_MAKEFILE($1,$2)])
744 ])
745 dnl
746 dnl _K5_GEN_MAKEFILE(dir, [frags])
747 dnl  dir must be present in this case
748 dnl  Note: Be careful in quoting. 
749 dnl        The ac_foreach generates the list of fragments to include
750 dnl        or "" if $2 is empty
751 AC_DEFUN(_K5_GEN_MAKEFILE,[dnl
752 AC_CONFIG_FILES([$1/Makefile:$srcdir/]K5_TOPDIR[/config/pre.in:$1/Makefile.in:$srcdir/]K5_TOPDIR[/config/post.in])
753 ])
754 dnl
755 dnl K5_GEN_FILE( <ac_output arguments> )
756 dnl
757 AC_DEFUN(K5_GEN_FILE,[AC_CONFIG_FILES($1)])dnl
758 dnl
759 dnl K5_AC_OUTPUT
760 dnl    Note: Adds the variables to config.status for individual 
761 dnl          Makefile generation from config.status
762 AC_DEFUN(K5_AC_OUTPUT,[AC_OUTPUT])dnl
763 dnl
764 dnl V5_AC_OUTPUT_MAKEFILE
765 dnl
766 AC_DEFUN(V5_AC_OUTPUT_MAKEFILE,
767 [ifelse($1, , [_V5_AC_OUTPUT_MAKEFILE(.,$2)],[_V5_AC_OUTPUT_MAKEFILE($1,$2)])])
768 dnl
769 define(_V5_AC_OUTPUT_MAKEFILE,
770 [ifelse($2, , ,AC_CONFIG_FILES($2))
771 AC_FOREACH([DIR], [$1],dnl
772  [AC_CONFIG_FILES(DIR[/Makefile:$srcdir/]K5_TOPDIR[/config/pre.in:]DIR[/Makefile.in:$srcdir/]K5_TOPDIR[/config/post.in])])
773 K5_AC_OUTPUT])dnl
774 dnl
775 dnl
776 dnl KRB5_SOCKADDR_SA_LEN: define HAVE_SA_LEN if sockaddr contains the sa_len
777 dnl component
778 dnl
779 AC_DEFUN([KRB5_SOCKADDR_SA_LEN],[ dnl
780 AC_CHECK_MEMBER(struct sockaddr.sa_len,
781   AC_DEFINE(HAVE_SA_LEN,1,[Define if struct sockaddr contains sa_len])
782 ,,[#include <sys/types.h>
783 #include <sys/socket.h>])])
784 dnl
785 dnl
786 dnl CHECK_UTMP: check utmp structure and functions
787 dnl
788 AC_DEFUN(CHECK_UTMP,[
789 AC_CHECK_MEMBERS([struct utmp.ut_pid, struct utmp.ut_type, struct utmp.ut_host, struct utmp.ut_exit],,,
790 [#include <sys/types.h>
791 #include <utmp.h>])
792
793 # Define the names actually used in the krb5 code currently:
794 if test $ac_cv_member_struct_utmp_ut_pid = no; then
795   AC_DEFINE(NO_UT_PID,1,[Define if ut_pid field not found])
796 fi
797 if test $ac_cv_member_struct_utmp_ut_type = no; then
798   AC_DEFINE(NO_UT_TYPE,1,[Define if ut_type field not found])
799 fi
800 if test $ac_cv_member_struct_utmp_ut_host = no; then
801   AC_DEFINE(NO_UT_HOST,1,[Define if ut_host field not found])
802 fi
803 if test $ac_cv_member_struct_utmp_ut_exit = no; then
804   AC_DEFINE(NO_UT_EXIT,1,[Define if ut_exit field not found])
805 fi
806
807 AC_CHECK_FUNCS(setutent setutxent updwtmp updwtmpx)
808 ])dnl
809 dnl
810 dnl WITH_NETLIB
811 dnl 
812 dnl
813 AC_DEFUN(WITH_NETLIB,[
814 AC_ARG_WITH([netlib],
815 AC_HELP_STRING([--with-netlib=LIBS], use user defined resolver library),
816 [  if test "$withval" = yes -o "$withval" = no ; then
817         AC_MSG_RESULT("netlib will link with C library resolver only")
818   else
819         LIBS="$LIBS $withval"
820         AC_MSG_RESULT("netlib will use \'$withval\'")
821   fi
822 ],dnl
823 [AC_LIBRARY_NET]
824 )])dnl
825 dnl
826 dnl
827 AC_DEFUN(KRB5_AC_NEED_DAEMON, [
828 KRB5_NEED_PROTO([#ifdef HAVE_UNISTD_H
829 #include <unistd.h>
830 #endif],daemon,1)])dnl
831 dnl
832 dnl Check if stdarg or varargs is available *and compiles*; prefer stdarg.
833 dnl (This was sent to djm for incorporation into autoconf 3/12/1996.  KR)
834 dnl
835 AC_DEFUN(AC_HEADER_STDARG, [
836
837 AC_MSG_CHECKING([for stdarg.h])
838 AC_CACHE_VAL(ac_cv_header_stdarg_h,
839 [AC_TRY_COMPILE([#include <stdarg.h>], [
840   } /* ac_try_compile will have started a function body */
841   int aoeu (char *format, ...) {
842     va_list v;
843     int i;
844     va_start (v, format);
845     i = va_arg (v, int);
846     va_end (v);
847 ],ac_cv_header_stdarg_h=yes,ac_cv_header_stdarg_h=no)])dnl
848 AC_MSG_RESULT($ac_cv_header_stdarg_h)
849 if test $ac_cv_header_stdarg_h = yes; then
850   AC_DEFINE(HAVE_STDARG_H, 1, [Define if stdarg available and compiles])
851 else
852
853 AC_MSG_CHECKING([for varargs.h])
854 AC_CACHE_VAL(ac_cv_header_varargs_h,
855 [AC_TRY_COMPILE([#include <varargs.h>],[
856   } /* ac_try_compile will have started a function body */
857   int aoeu (va_alist) va_dcl {
858     va_list v;
859     int i;
860     va_start (v);
861     i = va_arg (v, int);
862     va_end (v);
863 ],ac_cv_header_varargs_h=yes,ac_cv_header_varargs_h=no)])dnl
864 AC_MSG_RESULT($ac_cv_header_varargs_h)
865 if test $ac_cv_header_varargs_h = yes; then
866   AC_DEFINE(HAVE_VARARGS_H, 1, [Define if varargs available and compiles])
867 else
868   AC_MSG_ERROR(Neither stdarg nor varargs compile?)
869 fi
870
871 fi dnl stdarg test failure
872
873 ])dnl
874
875 dnl
876 dnl KRB5_AC_NEED_LIBGEN --- check if libgen needs to be linked in for
877 dnl                             compile/step    
878 dnl
879 dnl
880 AC_DEFUN(KRB5_AC_NEED_LIBGEN,[
881 AC_REQUIRE([AC_PROG_CC])dnl
882 dnl
883 dnl regcomp is present but non-functional on Solaris 2.4
884 dnl
885 AC_MSG_CHECKING(for working regcomp)
886 AC_CACHE_VAL(ac_cv_func_regcomp,[
887 AC_TRY_RUN([
888 #include <sys/types.h>
889 #include <regex.h>
890 regex_t x; regmatch_t m;
891 int main() { return regcomp(&x,"pat.*",0) || regexec(&x,"pattern",1,&m,0); }
892 ], ac_cv_func_regcomp=yes, ac_cv_func_regcomp=no, AC_MSG_ERROR([Cannot test regcomp when cross compiling]))])
893 AC_MSG_RESULT($ac_cv_func_regcomp)
894 test $ac_cv_func_regcomp = yes && AC_DEFINE(HAVE_REGCOMP,1,[Define if regcomp exists and functions])
895 dnl
896 dnl Check for the compile and step functions - only if regcomp is not available
897 dnl
898 if test $ac_cv_func_regcomp = no; then
899  save_LIBS="$LIBS"
900  LIBS=-lgen
901 dnl this will fail if there's no compile/step in -lgen, or if there's
902 dnl no -lgen.  This is fine.
903  AC_CHECK_FUNCS(compile step)
904  LIBS="$save_LIBS"
905 dnl
906 dnl Set GEN_LIB if necessary 
907 dnl
908  AC_CHECK_LIB(gen, compile, GEN_LIB=-lgen, GEN_LIB=)
909  AC_SUBST(GEN_LIB)
910 fi
911 ])
912 dnl
913 dnl KRB5_AC_REGEX_FUNCS --- check for different regular expression 
914 dnl                             support functions
915 dnl
916 AC_DEFUN(KRB5_AC_REGEX_FUNCS,[
917 AC_CHECK_FUNCS(re_comp re_exec regexec)
918 AC_REQUIRE([KRB5_AC_NEED_LIBGEN])dnl
919 ])dnl
920 dnl
921 dnl AC_KRB5_TCL_FIND_CONFIG (uses tcl_dir)
922 dnl
923 AC_DEFUN(AC_KRB5_TCL_FIND_CONFIG,[
924 AC_REQUIRE([KRB5_LIB_AUX])dnl
925 AC_MSG_CHECKING(for tclConfig.sh)
926 dnl On Debian, we might be given --with-tcl=/usr, or tclsh might
927 dnl point us to /usr/lib/tcl8.4; either way, we need to find
928 dnl /usr/lib/tcl8.4/tclConfig.sh.
929 dnl On NetBSD, we might be given --with-tcl=/usr/pkg, or tclsh
930 dnl might point us to /usr/pkg/lib/tcl8.4; we need to find
931 dnl /usr/pkg/lib/tclConfig.sh.
932 if test -r "$tcl_dir/lib/tclConfig.sh" ; then
933   tcl_conf="$tcl_dir/lib/tclConfig.sh"
934 elif test -r "$tcl_dir/tclConfig.sh" ; then
935   tcl_conf="$tcl_dir/tclConfig.sh"
936 elif test -r "$tcl_dir/../tclConfig.sh" ; then
937   tcl_conf="$tcl_dir/../tclConfig.sh"
938 else
939   tcl_conf=
940   lib="$tcl_dir/lib"
941   changequote(<<,>>)dnl
942   for d in "$lib" "$lib"/tcl7.[0-9] "$lib"/tcl8.[0-9] ; do
943     if test -r "$d/tclConfig.sh" ; then
944       tcl_conf="$tcl_conf $d/tclConfig.sh"
945     fi
946   done
947   changequote([,])dnl
948 fi
949 if test -n "$tcl_conf" ; then
950   AC_MSG_RESULT($tcl_conf)
951 else
952   AC_MSG_RESULT(not found)
953 fi
954 tcl_ok_conf=
955 tcl_vers_maj=
956 tcl_vers_min=
957 old_CPPFLAGS=$CPPFLAGS
958 old_LIBS=$LIBS
959 old_LDFLAGS=$LDFLAGS
960 if test -n "$tcl_conf" ; then
961   for file in $tcl_conf ; do
962     TCL_MAJOR_VERSION=x ; TCL_MINOR_VERSION=x
963     AC_MSG_CHECKING(Tcl info in $file)
964     . $file
965     v=$TCL_MAJOR_VERSION.$TCL_MINOR_VERSION
966     if test -z "$tcl_vers_maj" \
967         || test "$tcl_vers_maj" -lt "$TCL_MAJOR_VERSION" \
968         || test "$tcl_vers_maj" = "$TCL_MAJOR_VERSION" -a "$tcl_vers_min" -lt "$TCL_MINOR_VERSION" ; then
969       for incdir in "$TCL_PREFIX/include/tcl$v" "$TCL_PREFIX/include" ; do
970         if test -r "$incdir/tcl.h" -o -r "$incdir/tcl/tcl.h" ; then
971           CPPFLAGS="$old_CPPFLAGS -I$incdir"
972           break
973         fi
974       done
975       LIBS="$old_LIBS `eval echo x $TCL_LIB_SPEC $TCL_LIBS | sed 's/^x//'`"
976       LDFLAGS="$old_LDFLAGS $TCL_LD_FLAGS"
977       AC_TRY_LINK( , [Tcl_CreateInterp ();],
978         tcl_ok_conf=$file
979         tcl_vers_maj=$TCL_MAJOR_VERSION
980         tcl_vers_min=$TCL_MINOR_VERSION
981         AC_MSG_RESULT($v - working),
982         AC_MSG_RESULT($v - compilation failed)
983       )
984     else
985       AC_MSG_RESULT(older version $v)
986     fi
987   done
988 fi
989 CPPFLAGS=$old_CPPFLAGS
990 LIBS=$old_LIBS
991 LDFLAGS=$old_LDFLAGS
992 tcl_header=no
993 tcl_lib=no
994 if test -n "$tcl_ok_conf" ; then
995   . $tcl_ok_conf
996   TCL_INCLUDES=
997   for incdir in "$TCL_PREFIX/include/tcl$v" "$TCL_PREFIX/include" ; do
998     if test -r "$incdir/tcl.h" -o -r "$incdir/tcl/tcl.h" ; then
999       if test "$incdir" != "/usr/include" ; then
1000         TCL_INCLUDES=-I$incdir
1001       fi
1002       break
1003     fi
1004   done
1005   # Need eval because the first-level expansion could reference
1006   # variables like ${TCL_DBGX}.
1007   eval TCL_LIBS='"'$TCL_LIB_SPEC $TCL_LIBS $TCL_DL_LIBS'"'
1008   TCL_LIBPATH="-L$TCL_EXEC_PREFIX/lib"
1009   TCL_RPATH=":$TCL_EXEC_PREFIX/lib"
1010   if test "$DEPLIBEXT" != "$SHLIBEXT" && test -n "$RPATH_FLAG"; then
1011     TCL_MAYBE_RPATH='$(RPATH_FLAG)'"$TCL_EXEC_PREFIX/lib$RPATH_TAIL"
1012   else
1013     TCL_MAYBE_RPATH=
1014   fi
1015   CPPFLAGS="$old_CPPFLAGS $TCL_INCLUDES"
1016   AC_CHECK_HEADER(tcl.h,AC_DEFINE(HAVE_TCL_H,1,[Define if tcl.h is available]) tcl_header=yes)
1017   if test $tcl_header=no; then
1018      AC_CHECK_HEADER(tcl/tcl.h,AC_DEFINE(HAVE_TCL_TCL_H,1,[Define if tcl/tcl.h is available]) tcl_header=yes)
1019   fi
1020   CPPFLAGS="$old_CPPFLAGS"
1021   tcl_lib=yes
1022 else
1023   # If we read a tclConfig.sh file, it probably set this.
1024   TCL_LIBS=
1025 fi  
1026 AC_SUBST(TCL_INCLUDES)
1027 AC_SUBST(TCL_LIBS)
1028 AC_SUBST(TCL_LIBPATH)
1029 AC_SUBST(TCL_RPATH)
1030 AC_SUBST(TCL_MAYBE_RPATH)
1031 ])dnl
1032 dnl
1033 dnl AC_KRB5_TCL_TRYOLD
1034 dnl attempt to use old search algorithm for locating tcl
1035 dnl
1036 AC_DEFUN(AC_KRB5_TCL_TRYOLD, [
1037 AC_REQUIRE([KRB5_AC_FIND_DLOPEN])
1038 AC_MSG_WARN([trying old tcl search code])
1039 if test "$with_tcl" != yes -a "$with_tcl" != no; then
1040         TCL_INCLUDES=-I$with_tcl/include
1041         TCL_LIBPATH=-L$with_tcl/lib
1042         TCL_RPATH=:$with_tcl/lib
1043 fi
1044 if test "$with_tcl" != no ; then
1045         krb5_save_CPPFLAGS="$CPPFLAGS"
1046         krb5_save_LDFLAGS="$LDFLAGS"
1047         CPPFLAGS="$CPPFLAGS $TCL_INCLUDES"
1048         LDFLAGS="$LDFLAGS $TCL_LIBPATH"
1049         tcl_header=no
1050         AC_CHECK_HEADER(tcl.h,AC_DEFINE(HAVE_TCL_H,1,[Define if tcl.h found]) tcl_header=yes)
1051         if test $tcl_header=no; then
1052            AC_CHECK_HEADER(tcl/tcl.h,AC_DEFINE(HAVE_TCL_TCL_H,1,[Define if tcl/tcl.h found]) tcl_header=yes)
1053         fi
1054
1055         if test $tcl_header = yes ; then
1056                 tcl_lib=no
1057
1058                 if test $tcl_lib = no; then
1059                         AC_CHECK_LIB(tcl8.0, Tcl_CreateCommand, 
1060                                 TCL_LIBS="$TCL_LIBS -ltcl8.0 -lm $DL_LIB $LIBS"
1061                                 tcl_lib=yes,,-lm $DL_LIB)
1062                 fi
1063                 if test $tcl_lib = no; then
1064                         AC_CHECK_LIB(tcl7.6, Tcl_CreateCommand, 
1065                                 TCL_LIBS="$TCL_LIBS -ltcl7.6 -lm $DL_LIB $LIBS"
1066                                 tcl_lib=yes,,-lm $DL_LIB)
1067                 fi
1068                 if test $tcl_lib = no; then
1069                         AC_CHECK_LIB(tcl7.5, Tcl_CreateCommand, 
1070                                 TCL_LIBS="$TCL_LIBS -ltcl7.5 -lm $DL_LIB $LIBS"
1071                                 tcl_lib=yes,,-lm $DL_LIB)
1072
1073                 fi
1074                 if test $tcl_lib = no ; then
1075                         AC_CHECK_LIB(tcl, Tcl_CreateCommand, 
1076                                 TCL_LIBS="$TCL_LIBS -ltcl -lm $DL_LIB $LIBS"
1077                                 tcl_lib=yes,,-lm $DL_LIB)
1078
1079                 fi
1080                 if test $tcl_lib = no ; then            
1081                         AC_MSG_WARN("tcl.h found but not library")
1082                 fi
1083         else
1084                 AC_MSG_WARN(Could not find Tcl which is needed for the kadm5 tests)
1085                 TCL_LIBS=
1086         fi
1087         CPPFLAGS="$krb5_save_CPPFLAGS"
1088         LDFLAGS="$krb5_save_LDFLAGS"
1089         AC_SUBST(TCL_INCLUDES)
1090         AC_SUBST(TCL_LIBS)
1091         AC_SUBST(TCL_LIBPATH)
1092         AC_SUBST(TCL_RPATH)
1093 else
1094         AC_MSG_RESULT("Not looking for Tcl library")
1095 fi
1096 ])dnl
1097 dnl
1098 dnl AC_KRB5_TCL - determine if the TCL library is present on system
1099 dnl
1100 AC_DEFUN(AC_KRB5_TCL,[
1101 TCL_INCLUDES=
1102 TCL_LIBPATH=
1103 TCL_RPATH=
1104 TCL_LIBS=
1105 TCL_WITH=
1106 tcl_dir=
1107 AC_ARG_WITH(tcl,
1108 [  --with-tcl=path         where Tcl resides], , with_tcl=try)
1109 if test "$with_tcl" = no ; then
1110   true
1111 elif test "$with_tcl" = yes -o "$with_tcl" = try ; then
1112   tcl_dir=/usr
1113   if test ! -r /usr/lib/tclConfig.sh; then
1114     cat >> conftest <<\EOF
1115 puts "tcl_dir=$tcl_library"
1116 EOF
1117     if tclsh conftest >conftest.out 2>/dev/null; then
1118       if grep tcl_dir= conftest.out >/dev/null 2>&1; then
1119         t=`sed s/tcl_dir=// conftest.out`
1120         tcl_dir=$t
1121       fi
1122     fi # tclsh ran script okay
1123   rm -f conftest conftest.out
1124   fi # no /usr/lib/tclConfig.sh
1125 else
1126   tcl_dir=$with_tcl
1127 fi
1128 if test "$with_tcl" != no ; then
1129   AC_KRB5_TCL_FIND_CONFIG
1130   if test $tcl_lib = no ; then
1131     if test "$with_tcl" != try ; then
1132       AC_KRB5_TCL_TRYOLD
1133     else
1134       AC_MSG_WARN(Could not find Tcl which is needed for some tests)
1135     fi
1136   fi
1137 fi
1138 # If "yes" or pathname, error out if not found.
1139 if test "$with_tcl" != no -a "$with_tcl" != try ; then
1140   if test "$tcl_header $tcl_lib" != "yes yes" ; then
1141     AC_MSG_ERROR(Could not find Tcl)
1142   fi
1143 fi
1144 ])dnl
1145
1146 dnl
1147 dnl WITH_HESIOD
1148 dnl
1149 AC_DEFUN(WITH_HESIOD,
1150 [AC_ARG_WITH(hesiod, AC_HELP_STRING(--with-hesiod[=path], compile with hesiod support @<:@omitted@:>@),
1151         hesiod=$with_hesiod, with_hesiod=no)
1152 if test "$with_hesiod" != "no"; then
1153         HESIOD_DEFS=-DHESIOD
1154         AC_CHECK_LIB(resolv, res_send, res_lib=-lresolv)
1155         if test "$hesiod" != "yes"; then
1156                 HESIOD_LIBS="-L${hesiod}/lib -lhesiod $res_lib"
1157         else
1158                 HESIOD_LIBS="-lhesiod $res_lib"
1159         fi
1160 else
1161         HESIOD_DEFS=
1162         HESIOD_LIBS=
1163 fi
1164 AC_SUBST(HESIOD_DEFS)
1165 AC_SUBST(HESIOD_LIBS)])
1166
1167
1168 dnl
1169 dnl KRB5_BUILD_LIBRARY
1170 dnl
1171 dnl Pull in the necessary stuff to create the libraries.
1172
1173 AC_DEFUN(KRB5_BUILD_LIBRARY,
1174 [AC_REQUIRE([KRB5_LIB_AUX])dnl
1175 AC_REQUIRE([AC_PROG_LN_S])dnl
1176 AC_REQUIRE([AC_PROG_RANLIB])dnl
1177 AC_REQUIRE([AC_PROG_ARCHIVE])dnl
1178 AC_REQUIRE([AC_PROG_ARCHIVE_ADD])dnl
1179 AC_REQUIRE([AC_PROG_INSTALL])dnl
1180 AC_CHECK_PROG(AR, ar, ar, false)
1181 AC_CHECK_PROG(PERL, perl, perl, false)
1182 if test "$ac_cv_prog_PERL" = "false"; then
1183   AC_MSG_ERROR(Perl is now required for Kerberos builds.)
1184 fi
1185 AC_SUBST(LIBLIST)
1186 AC_SUBST(LIBLINKS)
1187 AC_SUBST(MAKE_SHLIB_COMMAND)
1188 AC_SUBST(SHLIB_EXPFLAGS)
1189 AC_SUBST(SHLIB_EXPORT_FILE_DEP)
1190 AC_SUBST(DYNOBJ_EXPDEPS)
1191 AC_SUBST(DYNOBJ_EXPFLAGS)
1192 AC_SUBST(INSTALL_SHLIB)
1193 AC_SUBST(STLIBEXT)
1194 AC_SUBST(SHLIBEXT)
1195 AC_SUBST(SHLIBVEXT)
1196 AC_SUBST(SHLIBSEXT)
1197 AC_SUBST(DEPLIBEXT)
1198 AC_SUBST(PFLIBEXT)
1199 AC_SUBST(LIBINSTLIST)
1200 AC_SUBST(DYNOBJEXT)
1201 AC_SUBST(MAKE_DYNOBJ_COMMAND)
1202 ])
1203
1204 dnl
1205 dnl KRB5_BUILD_LIBOBJS
1206 dnl
1207 dnl Pull in the necessary stuff to build library objects.
1208
1209 AC_DEFUN(KRB5_BUILD_LIBOBJS,
1210 [AC_REQUIRE([KRB5_LIB_AUX])dnl
1211 AC_SUBST(OBJLISTS)
1212 AC_SUBST(STOBJEXT)
1213 AC_SUBST(SHOBJEXT)
1214 AC_SUBST(PFOBJEXT)
1215 AC_SUBST(PICFLAGS)
1216 AC_SUBST(PROFFLAGS)])
1217
1218 dnl
1219 dnl KRB5_BUILD_PROGRAM
1220 dnl
1221 dnl Set variables to build a program.
1222
1223 AC_DEFUN(KRB5_BUILD_PROGRAM,
1224 [AC_REQUIRE([KRB5_LIB_AUX])dnl
1225 AC_REQUIRE([KRB5_AC_NEED_LIBGEN])dnl
1226 AC_SUBST(CC_LINK)
1227 AC_SUBST(CXX_LINK)
1228 AC_SUBST(RPATH_FLAG)
1229 AC_SUBST(DEPLIBEXT)])
1230
1231 dnl
1232 dnl KRB5_RUN_FLAGS
1233 dnl
1234 dnl Set up environment for running dynamic executables out of build tree
1235
1236 AC_DEFUN(KRB5_RUN_FLAGS,
1237 [AC_REQUIRE([KRB5_LIB_AUX])dnl
1238 KRB5_RUN_ENV="$RUN_ENV"
1239 AC_SUBST(KRB5_RUN_ENV)])
1240
1241 dnl
1242 dnl KRB5_LIB_AUX
1243 dnl
1244 dnl Parse configure options related to library building.
1245
1246 AC_DEFUN(KRB5_LIB_AUX,
1247 [AC_REQUIRE([KRB5_LIB_PARAMS])dnl
1248
1249 AC_ARG_ENABLE([static],,
1250 [if test "$enableval" != no; then
1251   AC_MSG_ERROR([Sorry, static libraries do not work in this release.])
1252 fi])
1253 AC_ARG_ENABLE([shared], , 
1254 [if test "$enableval" != yes; then
1255   AC_MSG_ERROR([Sorry, this release builds only shared libraries, cannot disable them.])
1256 fi])
1257
1258 if test "$SHLIBEXT" = ".so-nobuild"; then
1259    AC_MSG_ERROR([Shared libraries are not yet supported on this platform.])
1260 fi
1261
1262 DEPLIBEXT=$SHLIBEXT
1263
1264 if test "$krb5_force_static" = "yes"; then
1265         LIBLIST='lib$(LIBBASE)$(STLIBEXT)'
1266         LIBLINKS='$(TOPLIBD)/lib$(LIBBASE)$(STLIBEXT)'
1267         OBJLISTS=OBJS.ST
1268         # This used to be install-static, but now we only follow this
1269         # path for internal libraries we don't want installed, not for
1270         # configure-time requests for installed static libraries.
1271         LIBINSTLIST=
1272 #       CFLAGS="$CFLAGS -D_KDB5_STATIC_LINK"
1273
1274         AC_MSG_RESULT([Forcing static libraries.])
1275         # avoid duplicate rules generation for AIX and such
1276         SHLIBEXT=.so-nobuild
1277         SHLIBVEXT=.so.v-nobuild
1278         SHLIBSEXT=.so.s-nobuild
1279 else
1280         AC_MSG_NOTICE([using shared libraries])
1281
1282         # Clear some stuff in case of AIX, etc.
1283         if test "$STLIBEXT" = "$SHLIBEXT" ; then
1284                 STLIBEXT=.a-nobuild
1285         fi
1286         case "$SHLIBSEXT" in
1287         .so.s-nobuild)
1288                 SHLIB_HAVE_MINOR_VERS=no
1289                 LIBLIST='lib$(LIBBASE)$(SHLIBEXT)'
1290                 LIBLINKS='$(TOPLIBD)/lib$(LIBBASE)$(SHLIBEXT) $(TOPLIBD)/lib$(LIBBASE)$(SHLIBVEXT)'
1291                 LIBINSTLIST="install-shared"
1292                 ;;
1293         *)
1294                 SHLIB_HAVE_MINOR_VERS=yes
1295                 LIBLIST='lib$(LIBBASE)$(SHLIBEXT) lib$(LIBBASE)$(SHLIBSEXT)'
1296                 LIBLINKS='$(TOPLIBD)/lib$(LIBBASE)$(SHLIBEXT) $(TOPLIBD)/lib$(LIBBASE)$(SHLIBVEXT) $(TOPLIBD)/lib$(LIBBASE)$(SHLIBSEXT)'
1297                 LIBINSTLIST="install-shlib-soname"
1298                 ;;
1299         esac
1300         OBJLISTS="OBJS.SH"
1301 fi
1302 CC_LINK="$CC_LINK_SHARED"
1303 CXX_LINK="$CXX_LINK_SHARED"
1304 AC_SUBST(SHLIB_HAVE_MINOR_VERS)
1305
1306 if test -z "$LIBLIST"; then
1307         AC_MSG_ERROR([must enable one of shared or static libraries])
1308 fi
1309
1310 # Check whether to build profiled libraries.
1311 AC_ARG_ENABLE([profiled],
1312 dnl [  --enable-profiled       build profiled libraries @<:@disabled@:>@]
1313 ,
1314 [if test "$enableval" = yes; then
1315   AC_MSG_ERROR([Sorry, profiled libraries do not work in this release.])
1316 fi])])
1317
1318 dnl
1319 dnl KRB5_LIB_PARAMS
1320 dnl
1321 dnl Determine parameters related to libraries, e.g. various extensions.
1322
1323 AC_DEFUN(KRB5_LIB_PARAMS,
1324 [AC_REQUIRE([AC_CANONICAL_HOST])dnl
1325 krb5_cv_host=$host
1326 AC_SUBST(krb5_cv_host)
1327 AC_REQUIRE([AC_PROG_CC])dnl
1328 AC_REQUIRE([V5_SET_TOPDIR])dnl
1329 . $ac_topdir/config/shlib.conf])
1330 dnl
1331 dnl The following was written by jhawk@mit.edu
1332 dnl
1333 dnl AC_LIBRARY_NET: Id: net.m4,v 1.4 1997/10/25 20:49:53 jhawk Exp 
1334 dnl
1335 dnl This test is for network applications that need socket() and
1336 dnl gethostbyname() -ish functions.  Under Solaris, those applications need to
1337 dnl link with "-lsocket -lnsl".  Under IRIX, they should *not* link with
1338 dnl "-lsocket" because libsocket.a breaks a number of things (for instance:
1339 dnl gethostbyname() under IRIX 5.2, and snoop sockets under most versions of
1340 dnl IRIX).
1341 dnl 
1342 dnl Unfortunately, many application developers are not aware of this, and
1343 dnl mistakenly write tests that cause -lsocket to be used under IRIX.  It is
1344 dnl also easy to write tests that cause -lnsl to be used under operating
1345 dnl systems where neither are necessary (or useful), such as SunOS 4.1.4, which
1346 dnl uses -lnsl for TLI.
1347 dnl 
1348 dnl This test exists so that every application developer does not test this in
1349 dnl a different, and subtly broken fashion.
1350 dnl 
1351 dnl It has been argued that this test should be broken up into two seperate
1352 dnl tests, one for the resolver libraries, and one for the libraries necessary
1353 dnl for using Sockets API. Unfortunately, the two are carefully intertwined and
1354 dnl allowing the autoconf user to use them independantly potentially results in
1355 dnl unfortunate ordering dependancies -- as such, such component macros would
1356 dnl have to carefully use indirection and be aware if the other components were
1357 dnl executed. Since other autoconf macros do not go to this trouble, and almost
1358 dnl no applications use sockets without the resolver, this complexity has not
1359 dnl been implemented.
1360 dnl
1361 dnl The check for libresolv is in case you are attempting to link statically
1362 dnl and happen to have a libresolv.a lying around (and no libnsl.a).
1363 dnl
1364 AC_DEFUN(AC_LIBRARY_NET, [
1365    # Most operating systems have gethostbyname() in the default searched
1366    # libraries (i.e. libc):
1367    AC_CHECK_FUNC(gethostbyname, , [
1368      # Some OSes (eg. Solaris) place it in libnsl:
1369      AC_CHECK_LIB(nsl, gethostbyname, , [
1370        # Some strange OSes (SINIX) have it in libsocket:
1371        AC_CHECK_LIB(socket, gethostbyname, , [
1372           # Unfortunately libsocket sometimes depends on libnsl.
1373           # AC_CHECK_LIB's API is essentially broken so the following
1374           # ugliness is necessary:
1375           AC_CHECK_LIB(socket, gethostbyname,
1376              LIBS="-lsocket -lnsl $LIBS",
1377                [AC_CHECK_LIB(resolv, gethostbyname,
1378                              LIBS="-lresolv $LIBS" )],
1379              -lnsl)
1380        ])
1381      ])
1382    ])
1383   AC_CHECK_FUNC(socket, , AC_CHECK_LIB(socket, socket, ,
1384     AC_CHECK_LIB(socket, socket, LIBS="-lsocket -lnsl $LIBS", , -lnsl)))
1385   KRB5_AC_ENABLE_DNS
1386   if test "$enable_dns" = yes ; then
1387     # We assume that if libresolv exists we can link against it.
1388     # This may get us a gethostby* that doesn't respect nsswitch.
1389     AC_CHECK_LIB(resolv, main)
1390
1391 _KRB5_AC_CHECK_RES_FUNCS(res_ninit res_nclose res_ndestroy res_nsearch dnl
1392 ns_initparse ns_name_uncompress dn_skipname res_search)
1393     if test $krb5_cv_func_res_nsearch = no \
1394       && test $krb5_cv_func_res_search = no; then
1395         # Attempt to link with res_search(), in case it's not prototyped.
1396         AC_CHECK_FUNC(res_search,
1397           [AC_DEFINE(HAVE_RES_SEARCH, 1,
1398             [Define to 1 if you have the `res_search' function])],
1399           [AC_ERROR([cannot find res_nsearch or res_search])])
1400     fi
1401   fi
1402 ])
1403 AC_DEFUN([_KRB5_AC_CHECK_RES_FUNCS],
1404 [AC_FOREACH([AC_Func], [$1],
1405   [AH_TEMPLATE(AS_TR_CPP(HAVE_[]AC_Func),
1406                [Define to 1 if you have the `]AC_Func[' function.])])dnl
1407 for krb5_func in $1; do
1408 _KRB5_AC_CHECK_RES_FUNC($krb5_func)
1409 done
1410 ])
1411 AC_DEFUN([_KRB5_AC_CHECK_RES_FUNC], [
1412 # Solaris 9 prototypes ns_name_uncompress() in arpa/nameser.h, but
1413 # doesn't export it from libresolv.so, so we use extreme paranoia here
1414 # and check both for the declaration and that we can link against the
1415 # function.
1416 AC_CACHE_CHECK([for $1], [krb5_cv_func_$1], [AC_TRY_LINK(
1417 [#include <sys/types.h>
1418 #include <netinet/in.h>
1419 #include <arpa/nameser.h>
1420 @%:@include <resolv.h>],
1421 [/*
1422  * Use volatile, or else optimization can cause false positives.
1423  */
1424 void (* volatile p)() = (void (*)())$1;],
1425                              [AS_VAR_SET(krb5_cv_func_$1, yes)],
1426                              [AS_VAR_SET(krb5_cv_func_$1, no)])])
1427 AS_IF([test AS_VAR_GET(krb5_cv_func_$1) = yes],
1428       [AC_DEFINE_UNQUOTED(AS_TR_CPP([HAVE_$1]), 1,
1429                           [Define to 1 if you have the `$1' function])])[]dnl
1430 ])
1431 dnl
1432 dnl
1433 dnl KRB5_AC_ENABLE_DNS
1434 dnl
1435 AC_DEFUN(KRB5_AC_ENABLE_DNS, [
1436 enable_dns=yes
1437 enable_dns_for_kdc=yes
1438 AC_DEFINE(KRB5_DNS_LOOKUP_KDC,1,[Define to enable DNS lookups of Kerberos KDCs])
1439
1440   AC_ARG_ENABLE([dns-for-realm],
1441 [  --enable-dns-for-realm  enable DNS lookups of Kerberos realm names], ,
1442 [enable_dns_for_realm=no])
1443   if test "$enable_dns_for_realm" = yes; then
1444     AC_DEFINE(KRB5_DNS_LOOKUP_REALM,1,[Define to enable DNS lookups of Kerberos realm names])
1445   fi
1446
1447 AC_DEFINE(KRB5_DNS_LOOKUP, 1,[Define for DNS support of locating realms and KDCs])
1448
1449 ])
1450 dnl
1451 dnl
1452 dnl Check if we need the prototype for a function - we give it a bogus 
1453 dnl prototype and if it complains - then a valid prototype exists on the 
1454 dnl system.
1455 dnl
1456 dnl KRB5_NEED_PROTO(includes, function, [bypass])
1457 dnl if $3 set, don't see if library defined. 
1458 dnl Useful for case where we will define in libkrb5 the function if need be
1459 dnl but want to know if a prototype exists in either case on system.
1460 dnl
1461 AC_DEFUN([KRB5_NEED_PROTO], [
1462 ifelse([$3], ,[if test "x$ac_cv_func_$2" = xyes; then])
1463 AC_CACHE_CHECK([if $2 needs a prototype provided], krb5_cv_func_$2_noproto,
1464 AC_TRY_COMPILE([$1],
1465 [struct k5foo {int foo; } xx;
1466 extern int $2 (struct k5foo*);
1467 $2(&xx);
1468 ],
1469 krb5_cv_func_$2_noproto=yes,krb5_cv_func_$2_noproto=no))
1470 if test $krb5_cv_func_$2_noproto = yes; then
1471         AC_DEFINE([NEED_]translit($2, [a-z], [A-Z])[_PROTO], 1, dnl
1472 [define if the system header files are missing prototype for $2()])
1473 fi
1474 ifelse([$3], ,[fi])
1475 ])
1476 dnl
1477 dnl =============================================================
1478 dnl Internal function for testing for getpeername prototype
1479 dnl
1480 AC_DEFUN([KRB5_GETPEERNAME_ARGS],[
1481 AC_DEFINE([GETPEERNAME_ARG2_TYPE],GETSOCKNAME_ARG2_TYPE,[Type of getpeername second argument.])
1482 AC_DEFINE([GETPEERNAME_ARG3_TYPE],GETSOCKNAME_ARG3_TYPE,[Type of getpeername second argument.])
1483 ])
1484 dnl
1485 dnl =============================================================
1486 dnl Internal function for testing for getsockname arguments
1487 dnl
1488 AC_DEFUN([TRY_GETSOCK_INT],[
1489 krb5_lib_var=`echo "$1 $2" | sed 'y% ./+-*%___p_p%'`
1490 AC_MSG_CHECKING([if getsockname() takes arguments $1 and $2])
1491 AC_CACHE_VAL(krb5_cv_getsockname_proto_$krb5_lib_var,
1492 [
1493 AC_TRY_COMPILE([#include <sys/types.h>
1494 #include <sys/socket.h>
1495 extern int getsockname(int, $1, $2);
1496 ],,eval "krb5_cv_getsockname_proto_$krb5_lib_var=yes",
1497     eval "krb5_cv_getsockname_proto_$krb5_lib_var=no")])
1498 if eval "test \"`echo '$krb5_cv_getsockname_proto_'$krb5_lib_var`\" = yes"; then
1499         AC_MSG_RESULT(yes)
1500         sock_set=yes; res1="$1"; res2="$2"
1501 else
1502         AC_MSG_RESULT(no)
1503 fi
1504 ])
1505 dnl
1506 dnl Determines the types of the second and third arguments to getsockname().
1507 dnl
1508 AC_DEFUN([KRB5_GETSOCKNAME_ARGS],[
1509 sock_set=no
1510 for sock_arg1 in "struct sockaddr *" "void *"
1511 do
1512   for sock_arg2 in "size_t *" "int *" "socklen_t *"
1513   do
1514         if test $sock_set = no; then
1515           TRY_GETSOCK_INT($sock_arg1, $sock_arg2)
1516         fi
1517   done 
1518 done
1519 if test "$sock_set" = no; then
1520   AC_MSG_NOTICE(assuming struct sockaddr and socklen_t for getsockname args)
1521   res1="struct sockaddr *"
1522   res2="socklen_t *"
1523 fi
1524 res1=`echo "$res1" | tr -d '*' | sed -e 's/ *$//'`
1525 res2=`echo "$res2" | tr -d '*' | sed -e 's/ *$//'`
1526 AC_DEFINE_UNQUOTED([GETSOCKNAME_ARG2_TYPE],$res1,[Type of pointer target for argument 2 to getsockname])
1527 AC_DEFINE_UNQUOTED([GETSOCKNAME_ARG3_TYPE],$res2,[Type of pointer target for argument 3 to getsockname])
1528 ])
1529 dnl
1530 dnl
1531 AC_DEFUN([KRB5_AC_CHOOSE_ET],[
1532 AC_ARG_WITH([system-et],
1533 AC_HELP_STRING(--with-system-et,use system compile_et and -lcom_err @<:@default: build and install a local version@:>@))
1534 AC_MSG_CHECKING(which version of com_err to use)
1535 if test "x$with_system_et" = xyes ; then
1536   COM_ERR_VERSION=sys
1537   AC_MSG_RESULT(system)
1538 else
1539   COM_ERR_VERSION=k5
1540   AC_MSG_RESULT(krb5)
1541 fi
1542 if test $COM_ERR_VERSION = sys; then
1543   # check for various functions we need
1544   AC_CHECK_LIB(com_err, add_error_table, :, AC_MSG_ERROR(cannot find add_error_table in com_err library))
1545   AC_CHECK_LIB(com_err, remove_error_table, :, AC_MSG_ERROR(cannot find remove_error_table in com_err library))
1546   # make sure compile_et provides "et_foo" name
1547   cat >> conf$$e.et <<EOF
1548 error_table foo
1549 error_code ERR_FOO, "foo"
1550 end
1551 EOF
1552   AC_CHECK_PROGS(compile_et,compile_et,false)
1553   if test "$compile_et" = false; then
1554     AC_MSG_ERROR(cannot find compile_et)
1555   fi
1556   AC_CACHE_CHECK(whether compile_et is useful,krb5_cv_compile_et_useful,[
1557   if compile_et conf$$e.et >/dev/null 2>&1 ; then true ; else
1558     AC_MSG_ERROR(execution failed)
1559   fi
1560   AC_TRY_COMPILE([#include "conf$$e.h"
1561                  ],[ &et_foo_error_table; ],:,
1562                  [AC_MSG_ERROR(cannot use et_foo_error_table)])
1563   # Anything else we need to test for?
1564   rm -f conf$$e.et conf$$e.c conf$$e.h
1565   krb5_cv_compile_et_useful=yes
1566   ])
1567 fi
1568 AC_SUBST(COM_ERR_VERSION)
1569 ])
1570 AC_DEFUN([KRB5_AC_CHOOSE_SS],[
1571 AC_ARG_WITH(system-ss,
1572             AC_HELP_STRING(--with-system-ss,use system -lss and mk_cmds @<:@private version@:>@))
1573 AC_ARG_VAR(SS_LIB,[system libraries for 'ss' package [-lss]])
1574 AC_MSG_CHECKING(which version of subsystem package to use)
1575 if test "x$with_system_ss" = xyes ; then
1576   SS_VERSION=sys
1577   AC_MSG_RESULT(system)
1578   # todo: check for various libraries we might need
1579   # in the meantime...
1580   test "x${SS_LIB+set}" = xset || SS_LIB=-lss
1581   old_LIBS="$LIBS"
1582   LIBS="$LIBS $SS_LIB"
1583   AC_CACHE_CHECK(whether system ss package works, krb5_cv_system_ss_okay,[
1584   AC_TRY_RUN([
1585 #include <ss/ss.h>
1586 int main(int argc, char *argv[]) {
1587   if (argc == 42) {
1588     int i, err;
1589     i = ss_create_invocation("foo","foo","",0,&err);
1590     ss_listen(i);
1591   }
1592   return 0;
1593 }], krb5_cv_system_ss_okay=yes, AC_MSG_ERROR(cannot run test program),
1594   krb5_cv_system_ss_okay="assumed")])
1595   LIBS="$old_LIBS"
1596 else
1597   SS_VERSION=k5
1598   AC_MSG_RESULT(krb5)
1599 fi
1600 AC_SUBST(SS_LIB)
1601 AC_SUBST(SS_VERSION)
1602 ])
1603 dnl
1604 AC_DEFUN([KRB5_AC_CHOOSE_DB],[
1605 AC_ARG_WITH(system-db,
1606             AC_HELP_STRING(--with-system-db,use system Berkeley db @<:@private version@:>@))
1607 AC_ARG_VAR(DB_HEADER,[header file for system Berkeley db package [db.h]])
1608 AC_ARG_VAR(DB_LIB,[library for system Berkeley db package [-ldb]])
1609 if test "x$with_system_db" = xyes ; then
1610   DB_VERSION=sys
1611   # TODO: Do we have specific routines we should check for?
1612   # How about known, easily recognizable bugs?
1613   # We want to use bt_rseq in some cases, but no other version but
1614   # ours has it right now.
1615   #
1616   # Okay, check the variables.
1617   test "x${DB_HEADER+set}" = xset || DB_HEADER=db.h
1618   test "x${DB_LIB+set}" = xset || DB_LIB=-ldb
1619   #
1620   if test "x${DB_HEADER}" = xdb.h ; then
1621     DB_HEADER_VERSION=sys
1622   else
1623     DB_HEADER_VERSION=redirect
1624   fi
1625   KDB5_DB_LIB="$DB_LIB"
1626 else
1627   DB_VERSION=k5
1628   AC_DEFINE(HAVE_BT_RSEQ,1,[Define if bt_rseq is available, for recursive btree traversal.])
1629   DB_HEADER=db.h
1630   DB_HEADER_VERSION=k5
1631   # libdb gets sucked into libkdb
1632   KDB5_DB_LIB=
1633   # needed for a couple of things that need libdb for its own sake
1634   DB_LIB=-ldb
1635 fi
1636 AC_SUBST(DB_VERSION)
1637 AC_SUBST(DB_HEADER)
1638 AC_SUBST(DB_HEADER_VERSION)
1639 AC_SUBST(DB_LIB)
1640 AC_SUBST(KDB5_DB_LIB)
1641 ])
1642 dnl
1643 dnl KRB5_AC_PRIOCNTL_HACK
1644 dnl
1645 dnl
1646 AC_DEFUN([KRB5_AC_PRIOCNTL_HACK],
1647 [AC_REQUIRE([AC_PROG_AWK])dnl
1648 AC_REQUIRE([AC_LANG_COMPILER_REQUIRE])dnl
1649 AC_CACHE_CHECK([whether to use priocntl hack], [krb5_cv_priocntl_hack],
1650 [case $krb5_cv_host in
1651 *-*-solaris2.9*)
1652         if test "$cross_compiling" = yes; then
1653                 krb5_cv_priocntl_hack=yes
1654         else
1655                 # Solaris patch 117171-11 (sparc) or 117172-11 (x86)
1656                 # fixes the Solaris 9 bug where final pty output
1657                 # gets lost on close.
1658                 if showrev -p | $AWK 'BEGIN { e = 1 }
1659 /Patch: 11717[[12]]/ { x = index[]([$]2, "-");
1660 if (substr[]([$]2, x + 1, length([$]2) - x) >= 11)
1661 { e = 0 } else { e = 1 } }
1662 END { exit e; }'; then
1663                         krb5_cv_priocntl_hack=no
1664                 else
1665                         krb5_cv_priocntl_hack=yes
1666                 fi
1667         fi
1668         ;;
1669 *)
1670         krb5_cv_priocntl_hack=no
1671         ;;
1672 esac])
1673 if test "$krb5_cv_priocntl_hack" = yes; then
1674         PRIOCNTL_HACK=1
1675 else
1676         PRIOCNTL_HACK=0
1677 fi
1678 AC_SUBST(PRIOCNTL_HACK)])
1679 dnl
1680 dnl
1681 dnl KRB5_AC_GCC_ATTRS
1682 AC_DEFUN([KRB5_AC_GCC_ATTRS],
1683 [AC_CACHE_CHECK([for constructor/destructor attribute support],krb5_cv_attr_constructor_destructor,
1684 [rm -f conftest.1 conftest.2
1685 if test -r conftest.1 || test -r conftest.2 ; then
1686   AC_MSG_ERROR(write error in local file system?)
1687 fi
1688 true > conftest.1
1689 true > conftest.2
1690 if test -r conftest.1 && test -r conftest.2 ; then true ; else
1691   AC_MSG_ERROR(write error in local file system?)
1692 fi
1693 a=no
1694 b=no
1695 # blindly assume we have 'unlink'...
1696 AC_TRY_RUN([void foo1() __attribute__((constructor));
1697 void foo1() { unlink("conftest.1"); }
1698 void foo2() __attribute__((destructor));
1699 void foo2() { unlink("conftest.2"); }
1700 int main () { return 0; }],
1701 [test -r conftest.1 || a=yes
1702 test -r conftest.2 || b=yes], , AC_MSG_ERROR(Cannot test for constructor/destructor support when cross compiling))
1703 case $krb5_cv_host in
1704 *-*-aix4.*)
1705         # Under AIX 4.3.3, at least, shared library destructor functions
1706         # appear to get executed in reverse link order (right to left),
1707         # so that a library's destructor function may run after that of
1708         # libraries it depends on, and may still have to access in the
1709         # destructor.
1710         #
1711         # That counts as "not working", for me, but it's a much more
1712         # complicated test case to set up.
1713         b=no
1714         ;;
1715 esac
1716 krb5_cv_attr_constructor_destructor="$a,$b"
1717 ])
1718 # Okay, krb5_cv_... should be set now.
1719 case $krb5_cv_attr_constructor_destructor in
1720   yes,*)
1721     AC_DEFINE(CONSTRUCTOR_ATTR_WORKS,1,[Define if __attribute__((constructor)) works]) ;;
1722 esac
1723 case $krb5_cv_attr_constructor_destructor in
1724   *,yes)
1725     AC_DEFINE(DESTRUCTOR_ATTR_WORKS,1,[Define if __attribute__((destructor)) works]) ;;
1726 esac
1727 dnl End of attributes we care about right now.
1728 ])
1729 dnl
1730 dnl
1731 dnl KRB5_AC_PRAGMA_WEAK_REF
1732 AC_DEFUN([KRB5_AC_PRAGMA_WEAK_REF],
1733 [AC_CACHE_CHECK([whether pragma weak references are supported],
1734 krb5_cv_pragma_weak_ref,
1735 [AC_TRY_LINK([#pragma weak flurbl
1736 extern int flurbl(void);],[if (&flurbl != 0) return flurbl();],
1737 krb5_cv_pragma_weak_ref=yes,krb5_cv_pragma_weak_ref=no)])
1738 if test $krb5_cv_pragma_weak_ref = yes ; then
1739   AC_DEFINE(HAVE_PRAGMA_WEAK_REF,1,[Define if #pragma weak references work])
1740 fi])
1741 dnl
1742 dnl
1743 m4_include(config/ac-archive/acx_pthread.m4)
1744 #
1745 # KRB5_AC_LIBUTIL
1746 #
1747 # Check for libutil, for NetBSD, et al.; needed for openpty() and
1748 # logwtmp() on some platforms.
1749 #
1750 AC_DEFUN([KRB5_AC_LIBUTIL],
1751         [AC_CHECK_LIB(util, main,
1752                 [AC_DEFINE(HAVE_LIBUTIL,1,[Define if util library is available with openpty, logwtmp, etc])
1753   UTIL_LIB=-lutil])dnl
1754 AC_SUBST(UTIL_LIB)
1755 ])
1756 dnl
1757 dnl
1758 dnl
1759 dnl --with-ldap=value
1760 dnl
1761 AC_DEFUN(WITH_LDAP,[
1762 AC_ARG_WITH([ldap],
1763 [  --with-ldap             compile OpenLDAP database backend module],
1764 [case "$withval" in
1765     OPENLDAP) with_ldap=yes ;;
1766     yes | no) ;;
1767     EDIRECTORY) AC_MSG_ERROR(Option --with-ldap=EDIRECTORY is deprecated; use --with-edirectory instead.) ;;
1768     *)  AC_MSG_ERROR(Invalid option value --with-ldap="$withval") ;;
1769 esac], with_ldap=no)dnl
1770 AC_ARG_WITH([edirectory],
1771 [  --with-edirectory       compile eDirectory database backend module],
1772 [case "$withval" in
1773     yes | no) ;;
1774     *)  AC_MSG_ERROR(Invalid option value --with-edirectory="$withval") ;;
1775 esac], with_edirectory=no)dnl
1776
1777 if test $with_ldap = yes; then
1778   if test $with_edirectory = yes; then
1779     AC_MSG_ERROR(Cannot enable both OpenLDAP and eDirectory backends; choose one.)
1780   fi
1781   AC_MSG_NOTICE(enabling OpenLDAP database backend module support)
1782   OPENLDAP_PLUGIN=yes
1783 elif test $with_edirectory = yes; then
1784   AC_MSG_NOTICE(enabling eDirectory database backend module support)
1785   OPENLDAP_PLUGIN=yes
1786   AC_DEFINE(HAVE_EDIRECTORY,1,[Define if LDAP KDB interface should assume eDirectory.])
1787 else
1788   : # neither enabled
1789 dnl  AC_MSG_NOTICE(disabling ldap backend module support)
1790 fi
1791 AC_SUBST(OPENLDAP_PLUGIN)
1792 ])dnl
1793 dnl
1794 dnl If libkeyutils exists (on Linux) include it and use keyring ccache
1795 AC_DEFUN(KRB5_AC_KEYRING_CCACHE,[
1796   AC_CHECK_HEADERS([keyutils.h],
1797     AC_CHECK_LIB(keyutils, add_key, 
1798       [dnl Pre-reqs were found
1799        AC_DEFINE(USE_KEYRING_CCACHE, 1, [Define if the keyring ccache should be enabled])
1800        LIBS="-lkeyutils $LIBS"
1801       ]))
1802 ])dnl
1803 dnl