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