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