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