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