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