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