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