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