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