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