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