Move func substitutes from rlm_eap to missing.c
[freeradius.git] / configure.ac
1 dnl #############################################################
2 dnl #
3 dnl #  For information about autoconf, see:
4 dnl #
5 dnl #  http://www.gnu.org/software/autoconf/
6 dnl #
7 dnl #  The recommended order is:
8 dnl #
9 dnl #  AC_INIT(file)
10 dnl #  0. checks for compiler, libtool, and command line options
11 dnl #  1. checks for programs
12 dnl #  2. checks for libraries
13 dnl #  3. checks for header files
14 dnl #  4. checks for typedefs
15 dnl #  5. checks for structures and functions
16 dnl #  6. checks for compiler characteristics
17 dnl #  7. checks for library functions
18 dnl #  8. checks for system services
19 dnl #  AC_OUTPUT([file...])
20 dnl #
21 dnl #############################################################
22
23 AC_PREREQ([2.59])
24 export CFLAGS LIBS LDFLAGS CPPFLAGS
25
26 AC_INIT([freeradius],[$]Id[$],[http://bugs.freeradius.org],,[http://www.freeradius.org])
27 AC_CONFIG_SRCDIR([src/main/radiusd.c])
28 AC_CONFIG_HEADER([src/include/autoconf.h])
29 m4_include([m4/ax_cc.m4])
30
31 dnl #############################################################
32 dnl #
33 dnl #  Custom hackery to discover version at configure time
34 dnl #
35 dnl #############################################################
36 RADIUSD_MAJOR_VERSION=`cat VERSION | cut -f1 -d.`
37 RADIUSD_MINOR_VERSION=`cat VERSION | cut -f2 -d.`
38 RADIUSD_INCRM_VERSION=`cat VERSION | cut -f3 -d. | sed 's/[[\.-]].*$//'`
39
40 RADIUSD_VERSION=`printf "%02i%02i%02i" $RADIUSD_MAJOR_VERSION $RADIUSD_MINOR_VERSION $RADIUSD_INCRM_VERSION`
41
42 dnl #
43 dnl #  Still useful for custom builds
44 dnl #
45 RADIUSD_VERSION_STRING=`cat VERSION`
46
47 dnl #
48 dnl #  Add definitions to Make.inc as it's used by various build targets
49 dnl #
50 AC_SUBST([RADIUSD_VERSION_STRING])
51
52 dnl #
53 dnl #  Add definitions to autoconf.h, so that the headers that we install
54 dnl #  contain the version number of the server.
55 dnl #
56 AC_DEFINE_UNQUOTED([RADIUSD_VERSION], [${RADIUSD_VERSION}], [Version integer in format <ma><ma><mi><mi><in><in>])
57 AC_DEFINE_UNQUOTED([RADIUSD_VERSION_STRING], ["${RADIUSD_VERSION_STRING}"], [Raw version string from VERSION file])
58
59 dnl #############################################################
60 dnl #
61 dnl #  Override some of the default autoconf variables such as
62 dnl #  CFLAGS if were building in developer mode
63 dnl #
64 dnl #############################################################
65
66 dnl #
67 dnl #  Enable developer features like debugging symbols.
68 dnl #  These checks must be done before expanding the AC_PROG_CC
69 dnl #  and AC_PROG_CXX macros.
70 dnl #
71 AC_ARG_ENABLE(developer,
72 [  --enable-developer      enables features of interest to developers.],
73 [ case "$enableval" in
74   no)
75     developer=no
76     ;;
77   *)
78     developer=yes
79   esac ]
80 )
81
82 dnl #
83 dnl #  Turn on the developer flag when taken from a git checkout (not a release)
84 dnl #
85 if test -d $srcdir/.git; then
86   if test "x$developer" != "xno"; then
87     AC_MSG_NOTICE([found .git directory, enabling developer build implicitly, disable with --disable-developer])
88     developer="yes"
89   fi
90 fi
91
92 dnl #
93 dnl #  Autoconf sets -O2 and -g by default, but this is a PITA for debugging
94 dnl #  so we remove the defaults if were building in developer mode, and set
95 dnl #  -g3 so nice things like macro values are included. Other arguments are
96 dnl #  added later when we know what compiler were using.
97 dnl #
98 if test "x$developer" = "xyes"; then
99   : ${CFLAGS=-g3}
100 fi
101
102 dnl #############################################################
103 dnl #
104 dnl #  0. Checks for compiler, libtool, and command line options.
105 dnl #
106 dnl #############################################################
107
108 dnl #
109 dnl #  Get system information
110 dnl #
111 AC_CANONICAL_SYSTEM
112
113 dnl #
114 dnl #  Check for GNU cc
115 dnl #
116 AC_PROG_CC
117 AC_PROG_CXX
118
119 dnl #
120 dnl #  check for AIX, to allow us to use some BSD functions
121 dnl #  must be before macros that call the compiler.
122 dnl #
123 AC_AIX
124
125 AC_PROG_GCC_TRADITIONAL
126 AC_PROG_CC_SUNPRO
127 AC_PROG_RANLIB
128
129 dnl #
130 dnl #  Definitive check for whether the compiler is clang
131 dnl #
132 AX_CC_IS_CLANG
133 if test "x$ax_cv_cc_clang" = "xyes"; then
134   AC_SUBST(clang_path, "$CC")
135 else
136   AC_SUBST(clang_path, "")
137 fi
138
139
140 dnl #
141 dnl #  Set Default CFLAGS for GCC compatible compilers
142 dnl #
143 if test "x$GCC" = "xyes"; then
144   CFLAGS="$CFLAGS -Wall -std=c99 -D_GNU_SOURCE"
145 fi
146
147 dnl #
148 dnl #  -Qunused-arguments means the compiler won't complain about unsupported arguments
149 dnl #
150 AX_CC_QUNUSED_ARGUMENTS_FLAG
151 if test "x$ax_cv_cc_qunused_arguments_flag" = "xyes"; then
152   CFLAGS="$CFLAGS -Qunused-arguments"
153   LDFLAGS="$LDFLAGS -Qunused-arguments"
154 fi
155
156 dnl #
157 dnl #  Compile in large (2G+) file support.
158 dnl #
159 AC_SYS_LARGEFILE
160
161 dnl #
162 dnl #  check for system bytesex
163 dnl #  AC_DEFINES WORDS_BIGENDIAN
164 dnl #
165 AC_C_BIGENDIAN(
166   [AC_DEFINE(FR_BIG_ENDIAN, 1, [Define if your processor stores words with the most significant byte first])],
167   [AC_DEFINE(FR_LITTLE_ENDIAN, 1, [Define if your processor stores words with the least significant byte first])]
168 )
169
170 dnl #
171 dnl #  Find GNU Make.
172 dnl #
173 AC_CHECK_PROG(GMAKE, gmake, yes, no)
174 if test $GMAKE = no; then
175   AC_PATH_PROG(MAKE, make, /usr/local/bin/make)
176 else
177   AC_PATH_PROG(MAKE, gmake, /usr/local/gnu/bin/make)
178 fi
179 makever=`$ac_cv_path_MAKE --version 2>&1 | grep "GNU Make"`
180 if test -z "$makever"; then
181   AC_MSG_ERROR([GNU Make is not installed.  Please download and install it from ftp://prep.ai.mit.edu/pub/gnu/make/ before continuing.])
182 fi
183
184 dnl #
185 dnl #  autoconf explicitly sets MAKEFLAGS and MFLAGS to '' even though we
186 dnl #  didn't tell it to, so we have to use FR_MAKEFLAGS.
187 dnl #
188 dnl #  determine the number of cores available and set the number of build
189 dnl #  processes appropriately.
190 dnl #
191 AX_SYSTEM_CORES
192
193 dnl #  Temporarily disabled because test and installation targets do not
194 dnl #  have dependencies set up correctly for multiple build processes.
195 dnl if test "x$ax_cv_system_cores" != "x"; then
196 dnl  : ${FR_MAKEFLAGS=-j$ax_cv_system_cores}
197 dnl fi
198 AC_SUBST(FR_MAKEFLAGS)
199
200 dnl #
201 dnl #  See if we have Git.
202 dnl #
203 AC_CHECK_PROG(GIT, git, yes, no)
204
205 dnl Put this in later, when all distributed modules use autoconf.
206 dnl AC_ARG_WITH(disablemodulefoo,
207 dnl [  --without-rlm_foo         Disables module compilation.  Module list:]
208 dnl esyscmd([find src/modules -type d -name rlm_\* -print |\
209 dnl   sed -e 's%src/modules/.*/% (sub)- %; s%.*/%- %' |\
210 dnl   awk '{print "                            "$0}']))
211
212 AC_ARG_ENABLE(strict-dependencies,
213 [  --enable-strict-dependencies  fail configure on lack of module dependancy.])
214
215 AC_ARG_ENABLE(werror,
216 [  --enable-werror         causes the build to fail if any warnings are generated.],
217 [ case "$enableval" in
218     no)
219       werror=no
220     ;;
221     *)
222       werror=yes
223   esac ]
224 )
225
226 dnl #
227 dnl #  extra argument: --with-docdir
228 dnl #
229 docdir='${datadir}/doc/freeradius'
230 AC_MSG_CHECKING([docdir])
231 AC_ARG_WITH(docdir,
232 [  --with-docdir=DIR       directory for documentation [DATADIR/doc/freeradius] ],
233 [ case "$withval" in
234   no)
235     docdir=no
236     ;;
237   yes)
238     ;;
239   [[\\/$]]* | ?:[[\\/]]* )
240     docdir="$withval"
241     ;;
242   *)
243     AC_MSG_ERROR([expected an absolute directory name for --with-docdir: $withval])
244     ;;
245   esac ]
246 )
247 AC_SUBST(docdir)
248 AC_MSG_RESULT($docdir)
249 if test "x$docdir" = xno; then
250   AC_MSG_WARN([Documentation files will NOT be installed.])
251 fi
252
253 dnl #
254 dnl #  extra argument: --with-logdir
255 dnl #
256 logdir='${localstatedir}/log/radius'
257 AC_MSG_CHECKING(logdir)
258 AC_ARG_WITH(logdir,
259 [  --with-logdir=DIR       directory for logfiles [LOCALSTATEDIR/log/radius] ],
260 [ case "$withval" in
261   no)
262     AC_MSG_ERROR([Need logdir])
263     ;;
264   yes)
265     ;;
266   [[\\/$]]* | ?:[[\\/]]* )
267     logdir="$withval"
268     ;;
269   *)
270     AC_MSG_ERROR([expected an absolute directory name for --with-logdir: $withval])
271     ;;
272   esac ]
273 )
274 AC_SUBST(logdir)
275 AC_MSG_RESULT($logdir)
276
277 dnl #
278 dnl #  extra argument: --with-radacctdir
279 dnl #
280 radacctdir='${logdir}/radacct'
281 AC_MSG_CHECKING(radacctdir)
282 AC_ARG_WITH(radacctdir,
283 [  --with-radacctdir=DIR   directory for detail files [LOGDIR/radacct] ],
284 [ case "$withval" in
285   no)
286     AC_MSG_ERROR([Need radacctdir])
287     ;;
288   yes)
289     ;;
290   [[\\/$]]* | ?:[[\\/]]* )
291     radacctdir="$withval"
292     ;;
293   *)
294     AC_MSG_ERROR([expected an absolute directory name for --with-radacctdir: $withval])
295     ;;
296   esac ]
297 )
298 AC_SUBST(radacctdir)
299 AC_MSG_RESULT($radacctdir)
300
301 dnl #
302 dnl #  extra argument: --with-raddbdir
303 dnl #
304 raddbdir='${sysconfdir}/raddb'
305 AC_MSG_CHECKING(raddbdir)
306 AC_ARG_WITH(raddbdir,
307 [  --with-raddbdir=DIR     directory for config files [SYSCONFDIR/raddb] ],
308 [ case "$withval" in
309   no)
310     AC_MSG_ERROR([Need raddbdir])
311     ;;
312   yes)
313     ;;
314   [[\\/$]]* | ?:[[\\/]]* )
315     raddbdir="$withval"
316     ;;
317   *)
318     AC_MSG_ERROR([expected an absolute directory name for --with-raddbdir: $withval])
319     ;;
320   esac ]
321 )
322 AC_SUBST(raddbdir)
323 AC_MSG_RESULT($raddbdir)
324
325 dnl #
326 dnl #  extra argument: --with-dictdir
327 dnl #
328 dictdir='${datarootdir}/freeradius'
329 AC_MSG_CHECKING(dictdir)
330 AC_ARG_WITH(dictdir,
331 [  --with-dictdir=DIR      directory for dictionary files [DATAROOTDIR/freeradius] ],
332 [ case "$withval" in
333   no)
334     AC_MSG_ERROR([Need dictdir])
335     ;;
336   yes)
337     ;;
338   [[\\/$]]* | ?:[[\\/]]* )
339     dictdir="$withval"
340     ;;
341   *)
342     AC_MSG_ERROR([expected an absolute directory name for --with-dictdir: $withval])
343     ;;
344   esac ]
345 )
346 AC_SUBST(dictdir)
347 AC_MSG_RESULT($dictdir)
348
349 modconfdir='${raddbdir}/mods-config'
350 AC_SUBST(modconfdir)
351
352 dnl #
353 dnl #  extra argument: --with-ascend-binary
354 dnl #
355 WITH_ASCEND_BINARY=yes
356 AC_ARG_WITH(ascend-binary,
357 [  --with-ascend-binary    include support for Ascend binary filter attributes (default=yes)],
358 [ case "$withval" in
359   yes)
360     ;;
361   *)
362     WITH_ASCEND_BINARY=no
363   esac ]
364 )
365 if test "x$WITH_ASCEND_BINARY" = "xyes"; then
366   AC_DEFINE(WITH_ASCEND_BINARY, [1], [include support for Ascend binary filter attributes])
367 fi
368
369 dnl #
370 dnl #  extra argument: --with-threads
371 dnl #
372 WITH_THREADS=yes
373 AC_ARG_WITH(threads,
374 [  --with-threads          use threads, if available.  (default=yes) ],
375 [ case "$withval" in
376   yes)
377     ;;
378   *)
379     WITH_THREADS=no
380   esac ]
381 )
382
383 dnl #
384 dnl #  extra argument: --with-tcp
385 dnl #
386 WITH_TCP=yes
387 AC_ARG_WITH(tcp,
388 [  --with-tcp              compile in TCP support. (default=yes)],
389 [ case "$withval" in
390   yes)
391     ;;
392   *)
393     WITH_TCP=no
394   esac ]
395 )
396 if test "x$WITH_TCP" = "xyes"; then
397   AC_DEFINE(WITH_TCP, [1], [define if you want TCP support (For RADSec et al)])
398 fi
399
400 dnl #
401 dnl #  extra argument: --with-vmps
402 dnl #
403 WITH_VMPS=yes
404 AC_ARG_WITH(vmps,
405 [  --with-vmps             compile in VMPS support. (default=yes)],
406 [ case "$withval" in
407   yes)
408     ;;
409   *)
410     WITH_VMPS=no
411   esac ]
412 )
413 if test "x$WITH_VMPS" = "xyes"; then
414   AC_DEFINE(WITH_VMPS, [1], [define if you want VMPS support])
415 fi
416
417 dnl #
418 dnl #  extra argument: --with-dhcp
419 dnl #
420 WITH_DHCP=yes
421 AC_ARG_WITH(dhcp,
422 [  --with-dhcp             compile in DHCP support. (default=yes)],
423 [ case "$withval" in
424   yes)
425     ;;
426   *)
427     WITH_DHCP=no
428   esac ]
429 )
430 if test "x$WITH_DHCP" = "xyes"; then
431   AC_DEFINE(WITH_DHCP, [1], [define if you want DHCP support])
432 fi
433
434 dnl #
435 dnl #  Allow the user to specify a list of modules to be linked
436 dnl #  statically to the server.
437 dnl #
438 STATIC_MODULES=
439 AC_ARG_WITH(static_modules,
440 [  --with-static-modules=QUOTED-MODULE-LIST],[
441   for i in $withval; do
442     STATIC_MODULES="$STATIC_MODULES -dlpreopen ../modules/rlm_$i/rlm_$i.la"
443   done
444 ])
445
446 USE_SHARED_LIBS=yes
447 AC_ARG_WITH(shared-libs,
448 [AS_HELP_STRING([--with-shared-libs ],
449 [build dynamic libraries and link against them. (default=yes)])],
450 [ case "$withval" in
451   no)
452     USE_SHARED_LIBS=no
453     ;;
454   *)
455   esac
456 ])
457
458 MODULES=
459 AC_ARG_WITH(modules,
460 [  --with-modules=QUOTED-MODULE-LIST],[
461  for i in $withval; do
462    MODULES="$MODULES $i"
463  done
464 ])
465
466 dnl #
467 dnl #  extra argument: --with-experimental-modules
468 dnl #
469 EXPERIMENTAL=
470 AC_ARG_WITH(experimental-modules,
471 [AS_HELP_STRING([--with-experimental-modules],
472 [use experimental and unstable modules. (default=no, unless --enable-developer=yes)])],
473 [ case "$withval" in
474   yes)
475     EXPERIMENTAL=yes
476     ;;
477   no)
478     EXPERIMENTAL=no
479     ;;
480   *)
481   esac ]
482 )
483
484 dnl #
485 dnl #  extra argument: --with-udpfromto
486 dnl #
487 WITH_UDPFROMTO=yes
488 AC_ARG_WITH(udpfromto,
489 [  --with-udpfromto        compile in UDPFROMTO support. (default=yes)],
490 [ case "$withval" in
491   yes)
492     WITH_UDPFROMTO=yes
493     ;;
494   *)
495     WITH_UDPFROMTO=no
496   esac ]
497 )
498
499 if test "x$WITH_UDPFROMTO" = "xyes"; then
500   AC_DEFINE(WITH_UDPFROMTO, [], [define if you want udpfromto])
501 fi
502
503 dnl #
504 dnl #  These next two arguments don't actually do anything.  They're
505 dnl #  place holders so that the top-level configure script can tell
506 dnl #  the user how to configure lower-level modules
507 dnl #
508
509 dnl #
510 dnl #  extra argument: --with-rlm-FOO-lib-dir
511 dnl #
512 AC_ARG_WITH(rlm-FOO-lib-dir,
513 [AS_HELP_STRING([--with-rlm-FOO-lib-dir=DIR],
514 [directory in which to look for library files used by module FOO])],
515 [ case "$withval" in
516   *)
517     ;;
518   esac ]
519 )
520
521 dnl #
522 dnl #  extra argument: --with-rlm-FOO-include-dir
523 dnl #
524 AC_ARG_WITH(rlm-FOO-include-dir,
525 [AS_HELP_STRING([--with-rlm-FOO-include-dir=DIR],
526 [directory in which to look for include files used by module FOO])],
527 [ case "$withval" in
528   *)
529     ;;
530   esac ]
531 )
532
533 dnl #
534 dnl #  extra argument: --with-openssl
535 dnl #
536 WITH_OPENSSL=yes
537 AC_ARG_WITH(openssl,
538 [  --with-openssl          use OpenSSL. (default=yes)],
539 [ case "$withval" in
540   no)
541     WITH_OPENSSL=no
542     ;;
543   *)
544     WITH_OPENSSL=yes
545     ;;
546   esac ]
547 )
548
549 dnl #
550 dnl #  extra argument: --with-openssl-lib-dir=dir
551 dnl #
552 openssl_lib_dir=
553 AC_ARG_WITH(openssl-lib-dir,
554 [AS_HELP_STRING([--with-openssl-lib-dir=DIR],
555 [directory to look for OpenSSL library files])],
556 [ case "$withval" in
557   *) openssl_lib_dir="$withval"
558     ;;
559   esac ]
560 )
561
562 dnl #
563 dnl #  extra argument: --with-openssl-includes=dir
564 dnl #
565 openssl_include_dir=
566 AC_ARG_WITH(openssl-include-dir,
567 [AS_HELP_STRING([--with-openssl-include-dir=DIR],
568 [directory to look for OpenSSL include files])],
569 [ case "$withval" in
570   *) openssl_include_dir="$withval"
571     ;;
572   esac ]
573 )
574
575 dnl #
576 dnl #  extra argument: --disable-openssl-version-check
577 dnl #
578 AC_ARG_ENABLE(openssl-version-check,
579 [AS_HELP_STRING([--disable-openssl-version-check],
580                 [disable vulnerable OpenSSL version check])]
581 )
582 if test "x$enable_openssl_version_check" != "xno"; then
583   AC_DEFINE(ENABLE_OPENSSL_VERSION_CHECK, [1],
584             [Define to 1 to have OpenSSL version check enabled])
585   openssl_version_check_config="\
586         #
587         #  allow_vulnerable_openssl: Allow the server to start with
588         #  versions of OpenSSL known to have critical vulnerabilities.
589         #
590         #  This check is based on the version number reported by libssl
591         #  and may not reflect patches applied to libssl by
592         #  distribution maintainers.
593         #
594         allow_vulnerable_openssl = no"
595 else
596   openssl_version_check_config=
597 fi
598 AC_SUBST([openssl_version_check_config])
599
600
601 dnl #############################################################
602 dnl #
603 dnl #  1. Checks for programs
604 dnl #
605 dnl #############################################################
606
607 CHECKRAD=checkrad
608 AC_PATH_PROG(PERL, perl, /usr/local/bin/perl)
609 if test "x$ac_cv_path_PERL" = "x"; then
610   AC_MSG_WARN([perl not found - Simultaneous-Use and checkrad may not work])
611 fi
612 AC_PATH_PROG(SNMPGET, snmpget)
613 if test "x$ac_cv_path_SNMPGET" = "x"; then
614   AC_MSG_WARN([snmpget not found - Simultaneous-Use and checkrad may not work])
615 fi
616
617 AC_PATH_PROG(SNMPWALK, snmpwalk)
618 if test "x$ac_cv_path_SNMPWALK" = "x"; then
619   AC_MSG_WARN([snmpwalk not found - Simultaneous-Use and checkrad may not work])
620 fi
621
622 AC_PATH_PROG(RUSERS, rusers, /usr/bin/rusers)
623
624 dnl #
625 dnl #  FIXME This is truly gross.
626 dnl #
627 missing_dir=`cd $ac_aux_dir && pwd`
628 AM_MISSING_PROG(ACLOCAL, aclocal, $missing_dir)
629 AM_MISSING_PROG(AUTOCONF, autoconf, $missing_dir)
630 AM_MISSING_PROG(AUTOHEADER, autoheader, $missing_dir)
631
632 AC_PATH_PROG(LOCATE,locate)
633 AC_PATH_PROG(DIRNAME,dirname)
634 AC_PATH_PROG(GREP,grep)
635
636 dnl #############################################################
637 dnl #
638 dnl #  2. Checks for libraries
639 dnl #
640 dnl #############################################################
641
642 dnl Check for talloc
643 dnl extra argument: --with-talloc-lib-dir=DIR
644 talloc_lib_dir=
645 AC_ARG_WITH(talloc-lib-dir,
646   [AS_HELP_STRING([--with-talloc-lib-dir=DIR],
647   [directory in which to look for talloc library files])],
648   [case "$withval" in
649     no)
650       AC_MSG_ERROR([Need talloc-lib-dir])
651       ;;
652     yes)
653       ;;
654     *)
655       talloc_lib_dir="$withval"
656       ;;
657   esac])
658
659 dnl extra argument: --with-talloc-include-dir=DIR
660 talloc_include_dir=
661 AC_ARG_WITH(talloc-include-dir,
662   [AS_HELP_STRING([--with-talloc-include-dir=DIR],
663   [directory in which to look for talloc include files])],
664   [case "$withval" in
665     no)
666       AC_MSG_ERROR([Need talloc-include-dir])
667       ;;
668     yes)
669       ;;
670     *)
671       talloc_include_dir="$withval"
672       ;;
673   esac])
674
675 smart_try_dir="$talloc_lib_dir"
676 FR_SMART_CHECK_LIB(talloc, _talloc)
677 if test "x$ac_cv_lib_talloc__talloc" != "xyes"; then
678   AC_MSG_WARN([talloc library not found. Use --with-talloc-lib-dir=<path>.])
679   AC_MSG_ERROR([FreeRADIUS requires libtalloc])
680 fi
681
682 TALLOC_LIBS="${smart_lib}"
683 TALLOC_LDFLAGS="${smart_ldflags}"
684 AC_SUBST(TALLOC_LIBS)
685 AC_SUBST(TALLOC_LDFLAGS)
686 LIBS="$old_LIBS"
687
688 dnl #
689 dnl #  If using pthreads, check for -lpthread (posix) or -lc_r (*BSD)
690 dnl #
691 old_CFLAGS=$CFLAGS
692 if test "x$WITH_THREADS" = "xyes"; then
693   if test $ac_cv_prog_suncc = "yes"; then
694     CFLAGS="$CFLAGS -mt"
695   fi
696
697   AC_CHECK_HEADERS(pthread.h, [],
698     [
699       WITH_THREADS="no"
700       fail=[pthread.h]
701     ])
702
703   dnl #
704   dnl #  pthread stuff is usually in -lpthread
705   dnl #  or in -lc_r, on *BSD
706   dnl #
707   dnl #  On Some systems, we need extra pre-processor flags, to get them to
708   dnl #  to do the threading properly.
709   dnl #
710   if test "x$WITH_THREADS" != "xno"; then
711     AC_CHECK_LIB(pthread, pthread_create,
712       [
713         HAVE_LPTHREAD='yes'
714         CFLAGS="$CFLAGS -D_REENTRANT -D_POSIX_PTHREAD_SEMANTICS"
715         LIBS="-lpthread $LIBS"
716
717         dnl #
718         dnl #  -pthread should add all required CPP definitions and linker
719         dnl #  arguments. But not all compilers support it, or some compilers
720         dnl #  only support it on certain platforms.
721         dnl #
722         AX_CC_PTHREAD_FLAG
723         if test "x$ax_cv_cc_pthread_flag" != 'xyes'; then
724           CFLAGS="$CFLAGS -pthread"
725         fi
726       ]
727     )
728
729     dnl #
730     dnl #  Check for libc_r which used to be the threading library used
731     dnl #  for FreeBSD. Internet says it may be deprecated, but if we
732     dnl #  can't find lpthread it's probably worth checking.
733     dnl #
734     if test "x$HAVE_LPTHREAD" != "xyes"; then
735       AC_CHECK_LIB(c_r, pthread_create,
736         [
737           CFLAGS="$CFLAGS -D_THREAD_SAFE"
738
739           dnl #
740           dnl #  -pthread should add all required CPP definitions and linker
741           dnl #  arguments. But not all compilers support it, or some compilers
742           dnl #  only support it on certain platforms.
743           dnl #
744           AX_CC_PTHREAD_FLAG
745           if test "x$ax_cv_cc_pthread_flag" != 'xyes'; then
746             LIBS="-lc_r $LIBS"
747           else
748             CFLAGS="$CFLAGS -pthread"
749           fi
750         ],
751         [ fail=[-lc_r or -lpthread] ]
752       )
753     fi
754   fi
755
756   if test "x$WITH_THREADS" != "xyes"; then
757     AC_MSG_WARN([silently not building with thread support.])
758     AC_MSG_WARN([FAILURE: thread support requires: $fail.])
759   else
760     AC_DEFINE(WITH_THREADS, [1], [define if you want thread support])
761   fi
762 fi
763
764 dnl #
765 dnl #  If we have NO pthread libraries, remove any knowledge of threads.
766 dnl #
767 if test "x$WITH_THREADS" != "xyes"; then
768   CFLAGS=$old_CFLAGS
769   ac_cv_header_pthread_h="no"
770   WITH_THREADS=no
771 else
772   dnl #
773   dnl #  We need sem_init() and friends, as they're the friendliest
774   dnl #  semaphore functions for threading.
775   dnl #
776   dnl #  HP/UX requires linking with librt, too, to get the sem_* symbols.
777   dnl #  Some systems have them in -lsem
778   dnl #  Solaris has them in -lposix4
779   dnl #  NetBSD has them in -lsemaphore
780   dnl #
781
782   AC_SEARCH_LIBS(sem_init, pthread sem posix4 rt semaphore,
783     [],
784     [AC_MSG_ERROR([[-lsem not found.  You may want to download it from ftp://ftp.to.gd-es.com/pub/BSDI/libsem.tar.bz2 or ftp://ftp.freeradius.org/pub/radius/contrib/libsem.tar.gz]])]
785   )
786 fi
787
788 dnl #
789 dnl #  Check if we have -ldl
790 dnl #
791 AC_CHECK_LIB(dl, dlopen)
792
793 dnl #
794 dnl #  Check if we need -lsocket
795 dnl #
796 AC_CHECK_LIB(socket, getsockname)
797
798 dnl #
799 dnl #  Check for -lresolv
800 dnl #  This library may be needed later.
801 dnl #
802 AC_CHECK_LIB(resolv, inet_aton)
803
804 dnl #
805 dnl #  Check if we need -lnsl. Usually if we want to
806 dnl #  link against -lsocket we need to include -lnsl as well.
807 dnl #
808 AC_CHECK_LIB(nsl, inet_ntoa)
809 AC_CHECK_LIB(ws2_32, htonl)
810
811 dnl #
812 dnl #  Check the pcap library for the RADIUS sniffer.
813 dnl #
814 dnl extra argument: --with-pcap-lib-dir=DIR
815 pcap_lib_dir=
816 AC_ARG_WITH(pcap-lib-dir,
817   [AS_HELP_STRING([--with-pcap-lib-dir=DIR],
818   [directory in which to look for pcap library files])],
819   [case "$withval" in
820     no)
821       AC_MSG_ERROR([Need pcap-lib-dir])
822       ;;
823     yes)
824       ;;
825     *)
826       pcap_lib_dir="$withval"
827       ;;
828   esac])
829
830 dnl extra argument: --with-pcap-include-dir=DIR
831 pcap_include_dir=
832 AC_ARG_WITH(pcap-include-dir,
833   [AS_HELP_STRING([--with-pcap-include-dir=DIR],
834   [directory in which to look for pcap include files])],
835   [case "$withval" in
836     no)
837       AC_MSG_ERROR([Need pcap-include-dir])
838       ;;
839     yes)
840       ;;
841     *)
842       pcap_include_dir="$withval"
843       ;;
844   esac])
845
846 smart_try_dir="$pcap_lib_dir"
847 FR_SMART_CHECK_LIB(pcap, pcap_open_live)
848 if test "x$ac_cv_lib_pcap_pcap_open_live" != "xyes"; then
849   AC_MSG_WARN([pcap library not found, silently disabling the RADIUS sniffer, and ARP listener.  Use --with-pcap-lib-dir=<path>.])
850 else
851   AC_DEFINE(HAVE_LIBPCAP, 1,
852     [Define to 1 if you have the `pcap' library (-lpcap).]
853   )
854
855   AC_CHECK_FUNCS(\
856     pcap_fopen_offline \
857     pcap_dump_fopen \
858     pcap_create \
859     pcap_activate
860   )
861
862   PCAP_LIBS="${smart_lib}"
863   PCAP_LDFLAGS="${smart_ldflags}"
864 fi
865 dnl Set by FR_SMART_CHECK_LIB
866 LIBS="${old_LIBS}"
867
868 dnl Check for collectdclient
869 dnl extra argument: --with-collectdclient-lib-dir=DIR
870 collectdclient_lib_dir=
871 AC_ARG_WITH(collectdclient-lib-dir,
872   [AS_HELP_STRING([--with-collectdclient-lib-dir=DIR],
873   [directory in which to look for collectdclient library files])],
874   [case "$withval" in
875     no)
876       AC_MSG_ERROR([Need collectdclient-lib-dir])
877       ;;
878     yes)
879       ;;
880     *)
881       collectdclient_lib_dir="$withval"
882       ;;
883   esac])
884
885 dnl extra argument: --with-collectdclient-include-dir=DIR
886 collectdclient_include_dir=
887 AC_ARG_WITH(collectdclient-include-dir,
888   [AS_HELP_STRING([--with-collectdclient-include-dir=DIR],
889   [directory in which to look for collectdclient include files])],
890   [case "$withval" in
891     no)
892       AC_MSG_ERROR([Need collectdclient-include-dir])
893       ;;
894     yes)
895       ;;
896     *)
897       collectdclient_include_dir="$withval"
898       ;;
899   esac])
900
901 smart_try_dir="$collectdclient_lib_dir"
902 FR_SMART_CHECK_LIB(collectdclient, lcc_connect)
903 if test "x$ac_cv_lib_collectdclient_lcc_connect" != "xyes"; then
904   AC_MSG_WARN([collectdclient library not found. Use --with-collectdclient-lib-dir=<path>.])
905 else
906   COLLECTDC_LIBS="${smart_lib}"
907   COLLECTDC_LDFLAGS="${smart_ldflags}"
908 fi
909 dnl Set by FR_SMART_CHECKLIB
910 LIBS="${old_LIBS}"
911
912 dnl Check for cap
913 dnl extra argument: --with-cap-lib-dir=DIR
914 cap_lib_dir=
915 AC_ARG_WITH(cap-lib-dir,
916   [AS_HELP_STRING([--with-cap-lib-dir=DIR],
917   [directory in which to look for cap library files])],
918   [case "$withval" in
919     no)
920       AC_MSG_ERROR([Need cap-lib-dir])
921       ;;
922     yes)
923       ;;
924     *)
925       cap_lib_dir="$withval"
926       ;;
927   esac])
928
929 dnl extra argument: --with-cap-include-dir=DIR
930 cap_include_dir=
931 AC_ARG_WITH(cap-include-dir,
932   [AS_HELP_STRING([--with-cap-include-dir=DIR],
933   [directory in which to look for cap include files])],
934   [case "$withval" in
935     no)
936       AC_MSG_ERROR([Need cap-include-dir])
937       ;;
938     yes)
939       ;;
940     *)
941       cap_include_dir="$withval"
942       ;;
943   esac])
944
945 smart_try_dir="$cap_lib_dir"
946 FR_SMART_CHECK_LIB(cap, cap_get_proc)
947 if test "x$ac_cv_lib_cap_cap_get_proc" != "xyes"; then
948   AC_MSG_WARN([cap library not found, debugger checks will not be enabled. Use --with-cap-lib-dir=<path>.])
949 else
950   AC_DEFINE(HAVE_LIBCAP, 1,
951     [Define to 1 if you have the `cap' library (-lcap).]
952   )
953   HAVE_LIBCAP=1
954 fi
955
956 VL_LIB_READLINE
957
958 dnl #############################################################
959 dnl #
960 dnl #  3. Checks for header files
961 dnl #
962 dnl #############################################################
963
964 dnl #
965 dnl # Check for talloc header files
966 dnl #
967 smart_try_dir="$talloc_include_dir"
968 FR_SMART_CHECK_INCLUDE([talloc.h])
969 if test "x$ac_cv_header_talloc_h" != "xyes"; then
970   AC_MSG_WARN([talloc headers not found. Use --with-talloc-include-dir=<path>.])
971   AC_MSG_ERROR([FreeRADIUS requires libtalloc])
972 fi
973
974 dnl #
975 dnl #  Interix requires us to set -D_ALL_SOURCE, otherwise
976 dnl #  getopt will be #included, but won't link.  <sigh>
977 dnl #
978 case "$host" in
979   *-interix*)
980     CFLAGS="$CFLAGS -D_ALL_SOURCE"
981     ;;
982   *-darwin*)
983     CFLAGS="$CFLAGS -DDARWIN"
984     LIBS="-framework DirectoryService $LIBS"
985     AC_DEFINE([__APPLE_USE_RFC_3542], 1, [Force OSX >= 10.7 Lion to use RFC2292 IPv6 socket options])
986     ;;
987 esac
988
989 AC_HEADER_DIRENT
990 AC_HEADER_STDC
991 AC_HEADER_TIME
992 AC_HEADER_SYS_WAIT
993
994 AC_CHECK_HEADERS( \
995   arpa/inet.h \
996   crypt.h \
997   dlfcn.h \
998   errno.h \
999   fcntl.h \
1000   features.h \
1001   fnmatch.h \
1002   getopt.h \
1003   glob.h \
1004   grp.h \
1005   inttypes.h \
1006   limits.h \
1007   malloc.h \
1008   netdb.h \
1009   netinet/in.h \
1010   prot.h \
1011   pwd.h \
1012   resource.h \
1013   semaphore.h \
1014   sia.h \
1015   siad.h \
1016   signal.h \
1017   stdbool.h \
1018   stddef.h \
1019   stdint.h \
1020   stdio.h \
1021   sys/event.h \
1022   sys/fcntl.h \
1023   sys/prctl.h \
1024   sys/ptrace.h \
1025   sys/resource.h \
1026   sys/security.h \
1027   sys/select.h \
1028   sys/socket.h \
1029   sys/time.h \
1030   sys/types.h \
1031   sys/un.h \
1032   sys/wait.h \
1033   syslog.h \
1034   unistd.h \
1035   utime.h \
1036   utmp.h \
1037   utmpx.h \
1038   winsock.h
1039 )
1040
1041 dnl #
1042 dnl #  FreeBSD requires sys/socket.h before net/if.h
1043 dnl #
1044 AC_CHECK_HEADERS(net/if.h, [], [],
1045   [
1046     #ifdef HAVE_SYS_SOCKET_H
1047     #  include <sys/socket.h>
1048     #endif
1049   ]
1050 )
1051
1052 dnl #
1053 dnl #  other checks which require headers
1054 dnl #
1055 if test "x$ac_cv_header_sys_security_h" = "xyes" && test "x$ac_cv_header_prot_h" = "xyes"
1056 then
1057   AC_DEFINE(OSFC2, [], [define if you have OSFC2 authentication])
1058 fi
1059
1060 if test "x$ac_cv_header_sia_h" = "xyes" && test "x$ac_cv_header_siad_h" = "xyes"
1061 then
1062   AC_DEFINE(OSFSIA, [], [define if you have OSFSIA authentication])
1063 fi
1064
1065 dnl #
1066 dnl #  Were we told to use OpenSSL, if we were and we find an error, call AC_MSG_FAILURE and exit
1067 dnl #
1068 if test "x$WITH_OPENSSL" = xyes; then
1069   OLD_LIBS="$LIBS"
1070
1071   dnl #
1072   dnl #  Apparently OpenSSL will attempt to build with kerberos if we don't pass this?!
1073   dnl #
1074   CFLAGS="$CFLAGS -DOPENSSL_NO_KRB5"
1075
1076   dnl #
1077   dnl #  Check we can link to libcrypto and libssl
1078   dnl #
1079   smart_try_dir="$openssl_lib_dir"
1080   FR_SMART_CHECK_LIB(crypto, DH_new)
1081   if test "x$ac_cv_lib_crypto_DH_new" = "xyes"; then
1082     AC_DEFINE(HAVE_LIBCRYPTO, 1, [Define to 1 if you have the `crypto' library (-lcrypto).])
1083     OPENSSL_LIBS="$smart_lib"
1084     OPENSSL_LDFLAGS="$smart_ldflags"
1085
1086     FR_SMART_CHECK_LIB(ssl, SSL_new)
1087     if test "x$ac_cv_lib_ssl_SSL_new" != "xyes"; then
1088       AC_MSG_FAILURE([failed linking to libssl. Use --with-openssl-lib-dir=<path>, or --with-openssl=no (builds without OpenSSL)])
1089     else
1090       AC_DEFINE(HAVE_LIBSSL, 1, [Define to 1 if you have the `ssl' library (-lssl).])
1091       OPENSSL_LIBS="$OPENSSL_LIBS $smart_lib"
1092
1093       if test "$OPENSSL_LDFLAGS" != "$smart_ldflags"; then
1094         AC_MSG_FAILURE(["inconsistent LDFLAGS between -lssl '$smart_ldflags' and -lcrypto '$OPENSSL_LDFLAGS'"])
1095       fi
1096     fi
1097   else
1098     AC_MSG_FAILURE([failed linking to libcrypto. Use --with-openssl-lib-dir=<path>, or --with-openssl=no (builds without OpenSSL)])
1099   fi
1100
1101   smart_try_dir="$openssl_include_dir"
1102   FR_SMART_CHECK_INCLUDE(openssl/ssl.h)
1103   if test "x$ac_cv_header_openssl_ssl_h" = "xyes"; then
1104     AC_DEFINE(HAVE_OPENSSL_SSL_H, 1, [Define to 1 if you have the <openssl/ssl.h> header file.])
1105
1106     AC_CHECK_HEADERS( \
1107       openssl/asn1.h \
1108       openssl/conf.h \
1109       openssl/crypto.h \
1110       openssl/err.h \
1111       openssl/evp.h \
1112       openssl/hmac.h \
1113       openssl/md5.h \
1114       openssl/md4.h \
1115       openssl/sha.h \
1116       openssl/ssl.h \
1117       openssl/ocsp.h \
1118       openssl/engine.h,
1119       [ OPENSSL_CPPFLAGS="$smart_include" ],
1120       [
1121         AC_MSG_FAILURE([failed locating OpenSSL headers. Use --with-openssl-include-dir=<path>, or --with-openssl=no (builds without OpenSSL)])
1122       ]
1123     )
1124
1125     AC_MSG_CHECKING([for OpenSSL version >= 0.9.7])
1126     AC_EGREP_CPP(yes,
1127       [#include <openssl/crypto.h>
1128        #if (OPENSSL_VERSION_NUMBER >= 0x00907000L)
1129        yes
1130        #endif
1131       ],
1132       [
1133         AC_MSG_RESULT(yes)
1134       ],
1135       [
1136         AC_MSG_RESULT(no)
1137         AC_MSG_FAILURE([OpenSSL version too old])
1138       ]
1139     )
1140
1141     dnl #
1142     dnl #  CPPFLAGS are passed to the compiler first, so we use
1143     dnl #  them to ensure things like --sysroot don't override the
1144     dnl #  library location we discovered previously.
1145     dnl #
1146     old_CPPFLAGS="$CPPFLAGS"
1147     CPPFLAGS="$OPENSSL_CPPFLAGS $CPPFLAGS"
1148
1149     dnl #
1150     dnl #  Now check that the header versions match the library
1151     dnl #
1152     AC_MSG_CHECKING([OpenSSL library and header version consistency])
1153     AC_RUN_IFELSE(
1154       [AC_LANG_PROGRAM(
1155         [[
1156           #include <stdio.h>
1157           #include <openssl/opensslv.h>
1158           #include <openssl/crypto.h>
1159         ]],
1160         [[
1161           printf("library: %lx header: %lx... ", (unsigned long) SSLeay(), (unsigned long) OPENSSL_VERSION_NUMBER);
1162           if (SSLeay() == OPENSSL_VERSION_NUMBER) {
1163             return 0;
1164           } else {
1165             return 1;
1166           }
1167         ]]
1168       )],
1169       [
1170         AC_MSG_RESULT(yes)
1171       ],
1172       [
1173         AC_MSG_RESULT(no)
1174         AC_MSG_FAILURE([OpenSSL library version does not match header version])
1175       ],
1176       [
1177         AC_MSG_RESULT([cross-compiling (assuming yes)])
1178       ]
1179     )
1180     dnl #
1181     dnl #  Check if the new HMAC_CTX interface is defined
1182     dnl #
1183     AC_CHECK_FUNCS( \
1184       SSL_get_client_random \
1185       SSL_get_server_random \
1186       SSL_SESSION_get_master_key \
1187       HMAC_CTX_new \
1188       HMAC_CTX_free \
1189       ASN1_STRING_get0_data \
1190       CONF_modules_load_file \
1191     )
1192     CPPFLAGS="$old_CPPFLAGS"
1193   fi
1194
1195   LIBS="$OLD_LIBS"
1196   AC_SUBST(OPENSSL_LIBS)
1197   AC_SUBST(OPENSSL_LDFLAGS)
1198   AC_SUBST(OPENSSL_CPPFLAGS)
1199   export OPENSSL_LIBS OPENSSL_LDFLAGS OPENSSL_CPPFLAGS
1200 fi
1201
1202 dnl #
1203 dnl #  Check the pcap includes for the RADIUS sniffer.
1204 dnl #
1205 if test "x$PCAP_LIBS" = x; then
1206   AC_MSG_NOTICE([skipping test for pcap.h.])
1207 else
1208   dnl #
1209   dnl # Check for pcap header files
1210   dnl #
1211   smart_try_dir="$pcap_include_dir"
1212   FR_SMART_CHECK_INCLUDE([pcap.h])
1213   if test "x$ac_cv_header_pcap_h" == "xyes"; then
1214     AC_DEFINE(HAVE_PCAP_H, 1, [Define to 1 if you have the <pcap.h> header file.])
1215     AC_SUBST(PCAP_LIBS)
1216     AC_SUBST(PCAP_LDFLAGS)
1217   else
1218     AC_MSG_WARN([pcap headers not found, silently disabling the RADIUS sniffer, and ARP listener. Use --with-pcap-include-dir=<path>.])
1219   fi
1220 fi
1221
1222 dnl Check for collectd-client
1223 if test "x$COLLECTDC_LIBS" = x; then
1224   AC_MSG_NOTICE([skipping test for collectd/client.h.])
1225 else
1226   dnl #
1227   dnl # Check for collectd-client header files
1228   dnl #
1229   smart_try_dir="$collectdclient_include_dir"
1230   FR_SMART_CHECK_INCLUDE([collectd/client.h])
1231   if test "x$ac_cv_header_collectd_client_h" == "xyes"; then
1232     AC_DEFINE(HAVE_COLLECTDC_H, 1, [Define to 1 if you have the `collectdclient' library (-lcollectdclient).])
1233     AC_SUBST(COLLECTDC_LIBS)
1234     AC_SUBST(COLLECTDC_LDFLAGS)
1235   else
1236     AC_MSG_WARN([collectdclient headers not found. Use --with-collectdclient-include-dir=<path>.])
1237   fi
1238 fi
1239
1240 dnl #
1241 dnl #  Check the CAP includes for debugger checks
1242 dnl #
1243 if test "x$HAVE_LIBCAP" = x; then
1244   AC_MSG_NOTICE([skipping test for cap.h.])
1245 else
1246   dnl #
1247   dnl # Check for CAP header files
1248   dnl #
1249   smart_try_dir="$cap_include_dir"
1250   FR_SMART_CHECK_INCLUDE([sys/capability.h])
1251   if test "x$ac_cv_header_sys_capability_h" == "xyes"; then
1252     AC_DEFINE(HAVE_CAPABILITY_H, 1, [Define to 1 if you have the <sys/capability.h> header file.])
1253   else
1254     AC_MSG_WARN([cap headers not found, will not perform debugger checks. Use --with-cap-include-dir=<path>.])
1255   fi
1256 fi
1257
1258 dnl #############################################################
1259 dnl #
1260 dnl #  4. Checks for typedefs
1261 dnl #
1262 dnl #############################################################
1263
1264 dnl #
1265 dnl #  Ensure that these are defined
1266 dnl #
1267 AC_TYPE_OFF_T
1268 AC_TYPE_PID_T
1269 AC_TYPE_SIZE_T
1270 AC_TYPE_UID_T
1271
1272 dnl #
1273 dnl #  Check for socklen_t
1274 dnl #
1275 FR_CHECK_TYPE_INCLUDE(
1276   [
1277     #ifdef HAVE_SYS_TYPES_H
1278     #  include <sys/types.h>
1279     #endif
1280
1281     #ifdef HAVE_SYS_SOCKET_H
1282     #  include <sys/socket.h>
1283     #endif
1284   ],
1285   socklen_t, int, [socklen_t is generally 'int' on systems which don't use it]
1286 )
1287
1288 dnl #
1289 dnl #  Check for uint8_t
1290 dnl #
1291 FR_CHECK_TYPE_INCLUDE(
1292   [
1293     #ifdef HAVE_INTTYPES_H
1294     #  include <inttypes.h>
1295     #endif
1296
1297     #ifdef HAVE_STDINT_H
1298     #  include <stdint.h>
1299     #endif
1300   ],
1301   uint8_t, unsigned char, [uint8_t should be the canonical 'octet' for network traffic]
1302 )
1303
1304 dnl #
1305 dnl #  Check for uint16_t
1306 dnl #
1307 FR_CHECK_TYPE_INCLUDE(
1308   [
1309     #ifdef HAVE_INTTYPES_H
1310     #  include <inttypes.h>
1311     #endif
1312
1313     #ifdef HAVE_STDINT_H
1314     #  include <stdint.h>
1315     #endif
1316   ],
1317   uint16_t, unsigned short, [uint16_t should be the canonical '2 octets' for network traffic]
1318 )
1319
1320 dnl #
1321 dnl #  Check for uint32_t
1322 dnl #
1323 FR_CHECK_TYPE_INCLUDE(
1324   [
1325     #ifdef HAVE_INTTYPES_H
1326     #  include <inttypes.h>
1327     #endif
1328
1329     #ifdef HAVE_STDINT_H
1330     #  include <stdint.h>
1331     #endif
1332   ],
1333   uint32_t, unsigned int, [uint32_t should be the canonical 'network integer']
1334 )
1335
1336 dnl #
1337 dnl #  Check for uint64_t
1338 dnl #
1339 FR_CHECK_TYPE_INCLUDE(
1340   [
1341     #ifdef HAVE_INTTYPES_H
1342     #  include <inttypes.h>
1343     #endif
1344
1345     #ifdef HAVE_STDINT_H
1346     #  include <stdint.h>
1347     #endif
1348   ],
1349   uint64_t, unsigned long long, [uint64_t is required for larger counters]
1350 )
1351
1352 dnl #
1353 dnl #  Check for __uint128_t (compiler builtin)
1354 dnl #
1355 AC_CHECK_TYPE(__uint128_t, AC_DEFINE(HAVE___UINT128_T, 1, [compiler specific 128 bit unsigned integer]), [], [])
1356
1357 dnl #
1358 dnl #  Check for uint128_t (fictitious future data type)
1359 dnl #
1360 AC_CHECK_TYPE(uint128_t, AC_DEFINE(HAVE_UINT128_T, 1, [128 bit unsigned integer]), [],
1361   [
1362     #ifdef HAVE_INTTYPES_H
1363     #  include <inttypes.h>
1364     #endif
1365
1366     #ifdef HAVE_STDINT_H
1367     #  include <stdint.h>
1368     #endif
1369   ]
1370 )
1371
1372 AC_CHECK_TYPE(struct in6_addr, AC_DEFINE(HAVE_STRUCT_IN6_ADDR, 1, [IPv6 address structure]), [],
1373   [
1374     #ifdef HAVE_NETINET_IN_H
1375     #  include <netinet/in.h>
1376     #endif
1377   ]
1378 )
1379
1380 AC_CHECK_TYPE(struct sockaddr_storage, AC_DEFINE(HAVE_STRUCT_SOCKADDR_STORAGE, 1, [Generic socket addresses]), [],
1381   [
1382     #ifdef HAVE_NETINET_IN_H
1383     #  include <netinet/in.h>
1384     #endif
1385
1386     #ifdef HAVE_SYS_SOCKET_H
1387     #  include <sys/socket.h>
1388     #endif
1389 ])
1390
1391 AC_CHECK_TYPE(struct sockaddr_in6, AC_DEFINE(HAVE_STRUCT_SOCKADDR_IN6, 1, [IPv6 socket addresses]), [],
1392   [
1393     #ifdef HAVE_NETINET_IN_H
1394     #  include <netinet/in.h>
1395     #endif
1396 ])
1397
1398 AC_CHECK_TYPE(struct addrinfo, AC_DEFINE(HAVE_STRUCT_ADDRINFO, 1, [Generic DNS lookups]), [],
1399   [
1400     #ifdef HAVE_SYS_TYPES_H
1401     #  include <sys/types.h>
1402     #endif
1403
1404     #ifdef HAVE_SYS_SOCKET_H
1405     #  include <sys/socket.h>
1406     #endif
1407
1408     #ifdef HAVE_NETDB_H
1409     #  include <netdb.h>
1410     #endif
1411   ]
1412 )
1413
1414 dnl #
1415 dnl #  Check for sig_t
1416 dnl #
1417 dnl #  FR_CHECK_TYPE_INCLUDE doesn't work for callbacks as it doesn't produce typedefs
1418 dnl #
1419 AC_MSG_CHECKING([if sig_t is defined])
1420 AC_LINK_IFELSE(
1421   [AC_LANG_PROGRAM(
1422     [[
1423       #ifdef HAVE_SIGNAL_H
1424       #  include <signal.h>
1425       #endif
1426     ]],
1427     [[
1428       sig_t func;
1429       return 0;
1430     ]]
1431   )],
1432   [
1433       AC_MSG_RESULT(yes)
1434       AC_DEFINE(HAVE_SIG_T, 1, [Define if the type sig_t is defined by signal.h])
1435   ],
1436   [
1437       AC_MSG_RESULT(no)
1438   ]
1439 )
1440
1441 dnl #############################################################
1442 dnl #
1443 dnl #  5. Checks for structures and functions
1444 dnl #
1445 dnl #############################################################
1446 AC_CHECK_FUNCS( \
1447   bindat \
1448   clock_gettime \
1449   closefrom \
1450   ctime_r \
1451   dladdr \
1452   fcntl \
1453   fopencookie \
1454   funopen \
1455   getaddrinfo \
1456   getnameinfo \
1457   getopt_long \
1458   getpeereid \
1459   getresuid \
1460   gettimeofday \
1461   getusershell \
1462   gmtime_r \
1463   if_indextoname \
1464   inet_aton \
1465   inet_ntop \
1466   inet_pton \
1467   initgroups \
1468   kqueue \
1469   localtime_r \
1470   mallopt \
1471   mkdirat \
1472   openat \
1473   pthread_sigmask \
1474   setlinebuf \
1475   setresuid \
1476   setsid \
1477   setuid \
1478   setvbuf \
1479   sigaction \
1480   sigprocmask \
1481   snprintf \
1482   strcasecmp \
1483   strlcat \
1484   strlcpy \
1485   strncasecmp \
1486   strsep \
1487   strsignal \
1488   unlinkat \
1489   vdprintf \
1490   vsnprintf
1491 )
1492
1493 AC_TYPE_SIGNAL
1494
1495 dnl #
1496 dnl #  Check if we have utmpx.h
1497 dnl #  if so, check if struct utmpx has entry ut_xtime
1498 dnl #  if not, set it to define ut_xtime == ut_tv.tv_sec
1499 dnl #
1500 if test "x$ac_cv_header_utmpx_h" = "xyes"; then
1501  FR_CHECK_STRUCT_HAS_MEMBER([#include <utmpx.h>], [struct utmpx], ut_xtime)
1502  if test "x$ac_cv_type_struct_utmpx_has_ut_xtime" = "x"; then
1503    AC_DEFINE(ut_xtime, ut_tv.tv_sec, [define to something if you don't have ut_xtime in struct utmpx])
1504  fi
1505 fi
1506
1507 dnl #
1508 dnl #  struct ip_pktinfo
1509 dnl #
1510 FR_CHECK_STRUCT_HAS_MEMBER([#include <netinet/in.h>], [struct in_pktinfo], ipi_addr)
1511 if test "x$ac_cv_type_struct_in_pktinfo_has_ipi_addr" = "xyes"; then
1512   AC_DEFINE(HAVE_IP_PKTINFO, [], [define if you have IP_PKTINFO (Linux)])
1513 fi
1514
1515 dnl #
1516 dnl #  struct in6_pktinfo
1517 dnl #
1518 FR_CHECK_STRUCT_HAS_MEMBER([#include <netinet/in.h>], [struct in6_pktinfo], ipi6_addr)
1519 if test "x$ac_cv_type_struct_in6_pktinfo_has_ipi6_addr" = "xyes"; then
1520   AC_DEFINE(HAVE_IN6_PKTINFO, [], [define if you have IN6_PKTINFO (Linux)])
1521 fi
1522
1523 dnl #
1524 dnl #  Check for htonll and htonlll
1525 dnl #
1526 AC_MSG_CHECKING([if htonll is defined])
1527 AC_LINK_IFELSE(
1528   [AC_LANG_PROGRAM(
1529     [[
1530       #include <sys/types.h>
1531       #include <netinet/in.h>
1532     ]],
1533     [[
1534       return htonll(0);
1535     ]]
1536   )],
1537   [
1538       AC_MSG_RESULT(yes)
1539       AC_DEFINE(HAVE_HTONLL, 1, [Define if the function (or macro) htonll exists.])
1540   ],
1541   [
1542       AC_MSG_RESULT(no)
1543   ]
1544 )
1545
1546 AC_MSG_CHECKING([if htonlll is defined])
1547 AC_LINK_IFELSE(
1548   [AC_LANG_PROGRAM(
1549     [[
1550       #include <sys/types.h>
1551       #include <netinet/in.h>
1552     ]],
1553     [[
1554       return htonlll(0);
1555     ]]
1556   )],
1557   [
1558       AC_MSG_RESULT(yes)
1559       AC_DEFINE(HAVE_HTONLLL, 1, [Define if the function (or macro) htonlll exists.])
1560   ],
1561   [
1562       AC_MSG_RESULT(no)
1563   ]
1564 )
1565
1566 dnl #############################################################
1567 dnl #
1568 dnl #  6. Checks for compiler characteristics
1569 dnl #
1570 dnl #############################################################
1571
1572 dnl #
1573 dnl #  Ensure that these are defined
1574 dnl #
1575 AC_C_CONST
1576
1577 dnl #
1578 dnl #  See if this is OS/2
1579 dnl #
1580 AC_MSG_CHECKING([type of OS])
1581 OS=`uname -s`
1582 AC_MSG_RESULT($OS)
1583 if test "$OS" = "OS/2"; then
1584   LIBPREFIX=
1585 else
1586   LIBPREFIX=lib
1587 fi
1588 AC_SUBST(LIBPREFIX)
1589
1590 if test "x$developer" = "xyes"; then
1591   AC_MSG_NOTICE([Setting additional developer CFLAGS])
1592
1593   dnl #
1594   dnl #  Tell the compiler to parse doxygen documentation and verify it against function and variable declarations
1595   dnl #
1596   AX_CC_WDOCUMENTATION_FLAG
1597   if test "x$ax_cv_cc_wdocumentation_flag" = "xyes"; then
1598     devflags="-Wdocumentation"
1599   fi
1600
1601   dnl #
1602   dnl #  If we have -Weverything, it really means *everything* unlike -Wall
1603   dnl #  It's so verbose we need to turn off warnings which aren't useful.
1604   dnl #
1605   AX_CC_WEVERYTHING_FLAG
1606   if test "x$ax_cv_cc_weverything_flag" = "xyes"; then
1607     devflags="$devflags -W -Weverything -Wformat=2 -Wno-missing-field-initializers -Wno-date-time -Wno-padded -Wno-gnu-zero-variadic-macro-arguments -Wno-shorten-64-to-32 -Wno-sign-conversion -Wno-conversion -Wno-switch-enum -Wno-gnu-statement-expression -Wno-extended-offsetof -Wno-cast-align -Wno-documentation-unknown-command -Wno-covered-switch-default -Wno-packed -DWITH_VERIFY_PTR=1"
1608   else
1609     if test "x$GCC" = "xyes"; then
1610       devflags="$devflags -Wshadow -Wpointer-arith -Wcast-qual -Wcast-align -Wwrite-strings -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations -Wnested-externs -W -Wredundant-decls -Wundef -Wformat-y2k -Wno-format-extra-args -Wno-format-zero-length -Wno-cast-align -Wformat-nonliteral -Wformat-security -Wformat=2 -DWITH_VERIFY_PTR=1"
1611       INSTALLSTRIP=""
1612     fi
1613   fi
1614
1615   AC_MSG_NOTICE([Developer CFLAGS are "$devflags"])
1616
1617   CFLAGS="$CFLAGS $devflags"
1618   dnl #
1619   dnl #  Enable experimental modules (we want to know if code changes breaks one of them)
1620   dnl #
1621   if test "x$EXPERIMENTAL" != "xno"; then
1622     AC_MSG_NOTICE([is developer build, enabling experimental modules implicitly, disable with --without-experimental-modules])
1623     EXPERIMENTAL=yes
1624   fi
1625 else
1626   devflags=""
1627   CFLAGS="$CFLAGS -DNDEBUG"
1628   INSTALLSTRIP=""
1629 fi
1630
1631 dnl #
1632 dnl #  May of been set outside of this configure script
1633 dnl #
1634 AC_MSG_CHECKING([if building with -DNDEBUG])
1635 if echo "$CFLAGS" | grep '\-DNDEBUG' > /dev/null; then
1636   AC_MSG_RESULT([yes])
1637   AC_DEFINE([WITH_NDEBUG], [1], [define if the server was built with -DNDEBUG])
1638 else
1639   AC_MSG_RESULT([no])
1640 fi
1641
1642 export EXPERIMENTAL
1643
1644 dnl #
1645 dnl #  append the current git hash onto the version string
1646 dnl #
1647 if test -d $srcdir/.git -a "x$GIT" = "xyes"; then
1648   RADIUSD_VERSION_COMMIT=`git log --pretty=format:'%h' -n 1`
1649   AC_DEFINE_UNQUOTED([RADIUSD_VERSION_COMMIT],[${RADIUSD_VERSION_COMMIT}],[Commit HEAD at time of configuring])
1650 fi
1651
1652 dnl #
1653 dnl #  check for some compiler features
1654 dnl #
1655 FR_TLS
1656 FR_HAVE_BUILTIN_CHOOSE_EXPR
1657 FR_HAVE_BUILTIN_TYPES_COMPATIBLE_P
1658 FR_HAVE_BUILTIN_BSWAP64
1659 FR_HAVE_BOUNDED_ATTRIBUTE
1660
1661 dnl #############################################################
1662 dnl #
1663 dnl #  7. Checks for library functions
1664 dnl #
1665 dnl #############################################################
1666
1667 dnl #
1668 dnl # Check for talloc_set_memlimit
1669 dnl # This was only included in version 2.0.8
1670 dnl #
1671 AC_CHECK_LIB(talloc, talloc_set_memlimit,
1672   [
1673     AC_DEFINE(HAVE_TALLOC_SET_MEMLIMIT, 1, [Define to 1 if you have the function talloc_set_memlimit.])
1674   ]
1675 )
1676
1677 dnl #
1678 dnl # Check for libcrypt
1679 dnl # We use crypt(3) which may be in libc, or in libcrypt (eg FreeBSD)
1680 dnl #
1681 AC_CHECK_LIB(crypt, crypt,
1682   CRYPTLIB="-lcrypt"
1683 )
1684
1685 if test "$CRYPTLIB" != ""; then
1686   AC_DEFINE(HAVE_CRYPT, [], [Do we have the crypt function])
1687 else
1688   AC_CHECK_FUNC(crypt, AC_DEFINE(HAVE_CRYPT, [], [Do we have the crypt function]))
1689 fi
1690
1691 dnl Check for libcipher
1692 AC_CHECK_LIB(cipher, setkey,
1693    CRYPTLIB="${CRYPTLIB} -lcipher"
1694 )
1695 AC_SUBST(CRYPTLIB)
1696
1697 dnl #
1698 dnl #  Check for libexecinfo support, on some systems this is built into libc
1699 dnl #  on others it's a separate library.
1700 dnl #
1701 dnl extra argument: --with-execinfo-lib-dir
1702 execinfo_lib_dir=
1703 AC_ARG_WITH(execinfo-lib-dir,
1704 [AS_HELP_STRING([--with-execinfo-lib-dir=DIR],
1705 [directory in which to look for execinfo library files])],
1706 [ case "$withval" in
1707     no)
1708         AC_MSG_ERROR([Need execinfo-lib-dir])
1709         ;;
1710     yes)
1711         ;;
1712     *)
1713         execinfo_lib_dir="$withval"
1714         ;;
1715   esac ]
1716 )
1717
1718 dnl extra argument: --with-execinfo-include-dir
1719 execinfo_include_dir=
1720 AC_ARG_WITH(execinfo-include-dir,
1721 [AS_HELP_STRING([--with-execinfo-include-dir=DIR],
1722 [directory in which to look for execinfo include files])],
1723 [ case "$withval" in
1724     no)
1725         AC_MSG_ERROR([Need execinfo-include-dir])
1726         ;;
1727     yes)
1728         ;;
1729     *)
1730         execinfo_include_dir="$withval"
1731         ;;
1732   esac ]
1733 )
1734
1735 dnl #
1736 dnl #  Look for execinfo.h and symbols
1737 dnl #
1738 smart_try_dir=$execinfo_include_dir
1739 FR_SMART_CHECK_INCLUDE(execinfo.h)
1740 if test "x$ac_cv_header_execinfo_h" = "xyes"; then
1741   smart_try_dir=$execinfo_lib_dir
1742   FR_SMART_CHECK_LIB(execinfo, backtrace_symbols)
1743   if test "x$ac_cv_lib_execinfo_backtrace_symbols" != "xyes"; then
1744     dnl # Might be provided as part of libc
1745     AC_MSG_CHECKING([if execinfo provided as part of libc])
1746     AC_TRY_LINK(
1747       [
1748         #include <execinfo.h>
1749       ],
1750       [
1751         void *sym[1];
1752         backtrace_symbols(&sym, sizeof(sym)) ],
1753       [
1754         AC_MSG_RESULT(yes)
1755         ac_cv_lib_execinfo_backtrace_symbols="yes"
1756       ],
1757       [
1758         AC_MSG_RESULT(no)
1759       ]
1760     )
1761   fi
1762
1763   if test "x$ac_cv_lib_execinfo_backtrace_symbols" = "xyes"; then
1764     AC_DEFINE(HAVE_EXECINFO, [1], [define this if we have <execinfo.h> and symbols])
1765   fi
1766 fi
1767
1768 dnl #
1769 dnl #  Check for regular expression support.
1770 dnl #
1771 dnl extra argument: --with-pcre
1772 PCRE=yes
1773 AC_ARG_WITH(pcre,
1774 [AS_HELP_STRING([--with-pcre],
1775 [use libpcre (if available). (default=yes)])],
1776 [ case "$withval" in
1777     no)
1778     PCRE=no
1779         ;;
1780     yes)
1781     PCRE=yes
1782         ;;
1783   esac ]
1784 )
1785
1786 dnl extra argument: --with-pcre-lib-dir
1787 pcre_lib_dir=
1788 AC_ARG_WITH(pcre-lib-dir,
1789 [AS_HELP_STRING([--with-pcre-lib-dir=DIR],
1790 [directory in which to look for pcre library files])],
1791 [ case "$withval" in
1792     no)
1793         AC_MSG_ERROR(Need pcre-lib-dir)
1794         ;;
1795     yes)
1796         ;;
1797     *)
1798         pcre_lib_dir="$withval"
1799         ;;
1800   esac ]
1801 )
1802
1803 dnl extra argument: --with-pcre-include-dir
1804 pcre_include_dir=
1805 AC_ARG_WITH(pcre-include-dir,
1806 [AS_HELP_STRING([--with-pcre-include-dir=DIR],
1807 [directory in which to look for pcre include files])],
1808 [ case "$withval" in
1809     no)
1810         AC_MSG_ERROR(Need pcre-include-dir)
1811         ;;
1812     yes)
1813         ;;
1814     *)
1815         pcre_include_dir="$withval"
1816         ;;
1817   esac ]
1818 )
1819
1820 dnl extra argument: --with-regex
1821 REGEX=
1822 AC_ARG_WITH(regex,
1823 [AS_HELP_STRING([--with-regex],
1824 [Whether to build with regular expressions (default=yes)])],
1825 [ case "$withval" in
1826     no)
1827         REGEX=no
1828         ;;
1829     *)
1830         ;;
1831   esac ]
1832 )
1833
1834 dnl #
1835 dnl #  First look for PCRE
1836 dnl #
1837 if test "x$REGEX" != "xno" && test "x$PCRE" != "xno"; then
1838   smart_try_dir=$pcre_include_dir
1839   FR_SMART_CHECK_INCLUDE(pcre.h)
1840   if test "x$ac_cv_header_pcre_h" = "xyes"; then
1841     smart_try_dir=$pcre_lib_dir
1842     FR_SMART_CHECK_LIB(pcre, pcre_compile)
1843     if test "x$ac_cv_lib_pcre_pcre_compile" = "xyes"; then
1844       REGEX=yes
1845       AC_DEFINE(HAVE_PCRE, [1], [define this if we have libpcre])
1846       AC_DEFINE(HAVE_BINSAFE_REGEX, 1, [Define if we have a binary safe regular expression library])
1847     fi
1848   fi
1849 fi
1850
1851 dnl #
1852 dnl #  If no PCRE, fallback to POSIX regular expressions
1853 dnl #
1854 if test "x$REGEX" = "x"; then
1855   smart_try_dir=
1856   FR_SMART_CHECK_INCLUDE(regex.h)
1857   if test "x$ac_cv_header_regex_h" = "xyes"; then
1858     REGEX=yes
1859     AC_MSG_CHECKING([for extended regular expressions])
1860     AC_EGREP_CPP(yes,
1861       [
1862         #include <regex.h>
1863         #ifdef REG_EXTENDED
1864         yes
1865         #endif
1866       ],
1867       [
1868         AC_MSG_RESULT(yes)
1869         AC_DEFINE(HAVE_REG_EXTENDED, [1], [define this if we have REG_EXTENDED (from <regex.h>)])
1870       ],
1871       [
1872         AC_MSG_RESULT(no)
1873       ]
1874     )
1875
1876     dnl #
1877     dnl #  Some platforms require the regex library to be linked explicitly
1878     dnl #
1879     AC_CHECK_LIB(regex, regcomp,
1880       [
1881         LIBS="-lregex $LIBS"
1882       ]
1883     )
1884
1885     dnl #
1886     dnl #  Check for some BSD extensions which allow normal regexes to be
1887     dnl #  binary safe.
1888     dnl #
1889     AC_CHECK_FUNCS(\
1890       regncomp \
1891       regnexec
1892     )
1893     if test x"$ac_cv_func_regncomp" = x"yes" && test  x"$ac_cv_func_regnexec" = x"yes"; then
1894       AC_DEFINE(HAVE_BINSAFE_REGEX, 1, [Define if we have a binary safe regular expression library])
1895     fi
1896   fi
1897 fi
1898
1899 if test "x$REGEX" = "xyes"; then
1900   AC_DEFINE(HAVE_REGEX, 1, [Define if we have any regular expression library])
1901 fi
1902
1903 dnl #
1904 dnl #  Check the style of gethostbyaddr, in order of preference
1905 dnl #  GNU (_r eight args)
1906 dnl #
1907 AC_DEFINE(GNUSTYLE, [1], [GNU-Style get*byaddr_r])
1908
1909 dnl #
1910 dnl #  SYSV (_r six args)
1911 dnl #
1912 AC_DEFINE(SYSVSTYLE, [2], [SYSV-Style get*byaddr_r])
1913
1914 dnl #
1915 dnl #  BSD (three args, may not be thread safe)
1916 dnl #
1917 AC_DEFINE(BSDSTYLE, [3], [BSD-Style get*byaddr_r])
1918
1919 dnl #
1920 dnl #  Tru64 has BSD version, but it is thread safe
1921 dnl #  http://h30097.www3.hp.com/docs/base_doc/DOCUMENTATION/V51B_HTML/MAN/MAN3/1739____.HTM
1922 dnl #  We need #stdio.h to define NULL on FreeBSD (at least)
1923 dnl #
1924 gethostbyaddrrstyle=""
1925 AC_MSG_CHECKING([gethostbyaddr_r() syntax])
1926 case "$host" in
1927   *-freebsd*)
1928     dnl #
1929     dnl #  With FreeBSD, check if there's a prototype for gethostbyaddr_r.
1930     dnl #  Some versions (FreeBSD 5.1?) have a symbol but no prototype - so we
1931     dnl #  override this test to BSDSTYLE. FreeBSD 6.2 and up have proper GNU
1932     dnl #  style support.
1933     dnl #
1934     AC_CHECK_DECLS([gethostbyaddr_r], [],
1935       [
1936         AC_DEFINE(GETHOSTBYADDRRSTYLE, BSDSTYLE,
1937           [style of gethostbyaddr_r functions ])
1938         gethostbyaddrrstyle=BSD
1939         AC_MSG_WARN([FreeBSD overridden to BSD-style])
1940       ],
1941       [
1942         #ifdef HAVE_NETDB_H
1943         #include <netdb.h>
1944         #endif
1945       ])
1946     ;;
1947 esac
1948
1949 if test "x$gethostbyaddrrstyle" = "x"; then
1950   AC_TRY_LINK(
1951     [
1952       #include <stdio.h>
1953       #include <netdb.h>
1954     ],
1955     [ gethostbyaddr_r(NULL, 0, 0, NULL, NULL, 0, NULL, NULL) ],
1956     [
1957       AC_DEFINE(GETHOSTBYADDRRSTYLE, GNUSTYLE, [style of gethostbyaddr_r functions ])
1958       gethostbyaddrrstyle=GNU
1959     ]
1960   )
1961 fi
1962
1963 if test "x$gethostbyaddrrstyle" = "x"; then
1964   AC_TRY_LINK(
1965     [
1966       #include <stdio.h>
1967       #include <netdb.h>
1968     ],
1969     [ gethostbyaddr_r(NULL, 0, 0, NULL, NULL, 0, NULL) ] ,
1970     [
1971       AC_DEFINE(GETHOSTBYADDRRSTYLE, SYSVSTYLE, [style of gethostbyaddr_r functions ])
1972       gethostbyaddrrstyle=SYSV
1973     ]
1974   )
1975 fi
1976
1977
1978 if test "x$gethostbyaddrrstyle" = "x"; then
1979   AC_TRY_LINK(
1980     [
1981       #include <stdio.h>
1982       #include <netdb.h>
1983     ],
1984     [ gethostbyaddr(NULL, 0, 0)  ],
1985     [
1986       AC_DEFINE(GETHOSTBYADDRRSTYLE, BSDSTYLE, [style of gethostbyaddr_r functions ])
1987       gethostbyaddrrstyle=BSD
1988     ]
1989   )
1990 fi
1991
1992 if test "x$gethostbyaddrrstyle" = "x"; then
1993   AC_MSG_RESULT([none!  It must not exist, here.])
1994 else
1995   AC_MSG_RESULT([${gethostbyaddrrstyle}-style])
1996 fi
1997
1998 if test "x$gethostbyaddrrstyle" = "xBSD"; then
1999   AC_MSG_WARN([ ****** BSD-style gethostbyaddr might NOT be thread-safe! ****** ])
2000 fi
2001
2002 dnl #
2003 dnl #  Check the style of gethostbyname, in order of preference
2004 dnl #  GNU (_r seven args)
2005 dnl #  SYSV (_r five args)
2006 dnl #  BSD (two args, may not be thread safe)
2007 dnl #  Tru64 has BSD version, but it _is_ thread safe
2008 dnl #    http://h30097.www3.hp.com/docs/base_doc/DOCUMENTATION/V51B_HTML/MAN/MAN3/1946____.HTM
2009 dnl #  We need #stdio.h to define NULL on FreeBSD (at least)
2010 dnl #
2011 gethostbynamerstyle=""
2012 AC_MSG_CHECKING([gethostbyname_r() syntax])
2013 AC_TRY_LINK(
2014   [
2015     #include <stdio.h>
2016     #include <netdb.h>
2017   ],
2018   [ gethostbyname_r(NULL, NULL, NULL, 0, NULL, NULL) ],
2019   [
2020     AC_DEFINE(GETHOSTBYNAMERSTYLE, GNUSTYLE, [style of gethostbyname_r functions ])
2021     gethostbynamerstyle=GNU
2022   ]
2023 )
2024
2025 if test "x$gethostbynamerstyle" = "x"; then
2026   AC_TRY_LINK(
2027     [
2028       #include <stdio.h>
2029       #include <netdb.h>
2030     ],
2031     [ gethostbyname_r(NULL, NULL, NULL, 0, NULL) ] ,
2032     [
2033       AC_DEFINE(GETHOSTBYNAMERSTYLE, SYSVSTYLE, [style of gethostbyname_r functions ])
2034       gethostbynamerstyle=SYSV
2035     ]
2036   )
2037 fi
2038
2039 if test "x$gethostbynamerstyle" = "x"; then
2040   AC_TRY_LINK(
2041     [
2042       #include <stdio.h>
2043       #include <netdb.h>
2044     ],
2045     [ gethostbyname(NULL) ],
2046     [
2047       AC_DEFINE(GETHOSTBYNAMERSTYLE, BSDSTYLE, [style of gethostbyname_r functions ])
2048       gethostbynamerstyle=BSD
2049     ]
2050   )
2051 fi
2052
2053 if test "x$gethostbynamerstyle" = "x"; then
2054   AC_MSG_RESULT([none!  It must not exist, here.])
2055 else
2056   AC_MSG_RESULT([${gethostbynamerstyle}-style])
2057 fi
2058
2059 if test "x$gethostbynamerstyle" = "xBSD"; then
2060   AC_MSG_WARN([ ****** BSD-style gethostbyname might NOT be thread-safe! ****** ])
2061 fi
2062
2063 dnl #
2064 dnl #  Check for thread-safe getpwnam_r and getgrnam_r
2065 dnl #
2066 if test "x$ac_cv_header_pwd_h" = "xyes"; then
2067   AC_MSG_CHECKING([getpwnam_r])
2068   AC_TRY_LINK(
2069     [
2070       #include <stdlib.h>
2071       #include <sys/types.h>
2072       #include <pwd.h>
2073     ],
2074     [ getpwnam_r(NULL, NULL, NULL, 0, NULL) ],
2075     [
2076       AC_MSG_RESULT([yes])
2077       AC_DEFINE(HAVE_GETPWNAM_R, 1,
2078                 [Define to 1 if you have the getpwnam_r.]
2079                 )
2080     ],
2081     [
2082         AC_MSG_RESULT(no)
2083     ]
2084   )
2085 fi
2086
2087 if test "x$ac_cv_header_grp_h" = "xyes"; then
2088   AC_MSG_CHECKING([getgrnam_r])
2089   AC_TRY_LINK(
2090     [
2091       #include <stdlib.h>
2092       #include <sys/types.h>
2093       #include <grp.h>
2094     ],
2095     [ getgrnam_r(NULL, NULL, NULL, 0, NULL) ],
2096     [
2097       AC_MSG_RESULT([yes])
2098       AC_DEFINE(HAVE_GETGRNAM_R, 1,
2099                 [Define to 1 if you have the getgrnam_r.]
2100                 )
2101     ],
2102     [
2103         AC_MSG_RESULT(no)
2104     ]
2105   )
2106 fi
2107
2108
2109 dnl #
2110 dnl #  Check for non-posix solaris ctime_r (extra buflen int arg)
2111 dnl #
2112 AC_DEFINE(POSIXSTYLE, [1], [Posix-Style ctime_r])
2113 AC_DEFINE(SOLARISSTYLE, [2], [Solaris-Style ctime_r])
2114 ctimerstyle=""
2115 AC_MSG_CHECKING([ctime_r() syntax])
2116 AC_TRY_LINK(
2117   [
2118     #include <time.h>
2119   ],
2120   [ ctime_r(NULL, NULL, 0) ],
2121   [
2122     AC_DEFINE(CTIMERSTYLE, SOLARISSTYLE, [style of ctime_r function])
2123     ctimerstyle="SOLARIS"
2124   ]
2125 )
2126
2127 if test "x$ctimerstyle" = "x"; then
2128   AC_TRY_LINK(
2129     [
2130       #include <time.h>
2131     ],
2132     [ ctime_r(NULL, NULL) ],
2133     [
2134       AC_DEFINE(CTIMERSTYLE, POSIXSTYLE, [style of ctime_r function])
2135       ctimerstyle="POSIX"
2136     ]
2137   )
2138 fi
2139
2140 if test "x$ctimerstyle" = "x"; then
2141     AC_MSG_RESULT([none!  It must not exist, here.])
2142 else
2143     AC_MSG_RESULT([${ctimerstyle}-style])
2144 fi
2145
2146 AC_SUBST(HOSTINFO, $host)
2147
2148 dnl #############################################################
2149 dnl #
2150 dnl #  8. Checks for system services
2151 dnl #
2152 dnl #############################################################
2153
2154 dnl #
2155 dnl #  Figure out where libtool is located,
2156 dnl #
2157 top_builddir=`pwd`
2158 export top_builddir
2159 AC_MSG_RESULT([top_builddir=$top_builddir])
2160 dnl #  AC_SUBST(top_builddir)
2161
2162 dnl #
2163 dnl #  import libtool stuff
2164 dnl #
2165 dnl #############################################################
2166 dnl #
2167 dnl #  Configure in any module directories.
2168 dnl #
2169 dnl #############################################################
2170
2171 dnl ############################################################
2172 dnl #  Remove any conflicting definitions if autoconf.h
2173 dnl #  is being included by a module.
2174 dnl #############################################################
2175 AH_BOTTOM([#include <freeradius-devel/automask.h>])
2176
2177 dnl ############################################################
2178 dnl #  make modules by list
2179 dnl #############################################################
2180 if test "x$EXPERIMENTAL" = "xyes"; then
2181   for foo in `ls -1 "${srcdir}"/src/modules | grep rlm_`; do
2182     MODULES="$MODULES $foo"
2183   done
2184 else
2185    dnl #
2186    dnl #  make ONLY the stable modules
2187    dnl #
2188    for foo in `cat "${srcdir}"/src/modules/stable`; do
2189       MODULES="$MODULES $foo"
2190    done
2191 fi
2192
2193 dnl ############################################################
2194 dnl #  Add autoconf subdirs, based on the module list we
2195 dnl #  previously created.
2196 dnl #############################################################
2197 mysubdirs=""
2198 for bar in $MODULES; do
2199   if test -f "${srcdir}"/src/modules/$bar/configure; then
2200     mysubdirs="$mysubdirs src/modules/$bar"
2201   fi
2202 done
2203
2204 dnl #
2205 dnl #  Don't change the variable name here.  Autoconf goes bonkers
2206 dnl #  if you do.
2207 dnl #
2208 AC_CONFIG_SUBDIRS($mysubdirs)
2209 AC_SUBST(MODULES)
2210
2211 dnl #############################################################
2212 dnl #
2213 dnl #  Add -Werror last, so it doesn't interfere with autoconf's
2214 dnl #  test programs.
2215 dnl #
2216 dnl #############################################################
2217 if test "x$werror" == "xyes"; then
2218   CFLAGS="-Werror $CFLAGS"
2219 fi
2220
2221 dnl #############################################################
2222 dnl #
2223 dnl #  And finally, output the results.
2224 dnl #
2225 dnl #############################################################
2226 AC_CONFIG_COMMANDS([stamp-h], [echo timestamp > src/include/stamp-h])
2227 AC_CONFIG_COMMANDS([build-radpaths-h], [(cd ./src/include && /bin/sh ./build-radpaths-h)])
2228 AC_CONFIG_COMMANDS([main-chmod], [(cd ./src/main && chmod +x checkrad radlast radtest)])
2229 AC_CONFIG_COMMANDS([scripts-chmod], [(cd ./scripts && chmod +x rc.radiusd cron/radiusd.cron.daily cron/radiusd.cron.monthly cryptpasswd)])
2230
2231 dnl #
2232 dnl #  Substitute whatever libraries we found to be necessary
2233 dnl #
2234 AC_SUBST(LIBS)
2235 AC_SUBST(INSTALLSTRIP)
2236
2237 AC_SUBST(USE_SHARED_LIBS)
2238 USE_STATIC_LIBS="yes"
2239 AC_SUBST(USE_STATIC_LIBS)
2240 AC_SUBST(STATIC_MODULES)
2241
2242 AC_OUTPUT(\
2243   ./Make.inc \
2244   ./src/include/build-radpaths-h \
2245   ./src/main/radsniff.mk \
2246   ./src/main/checkrad \
2247   ./src/main/radlast \
2248   ./src/main/radtest \
2249   ./scripts/rc.radiusd \
2250   ./scripts/cron/radiusd.cron.daily \
2251   ./scripts/cron/radiusd.cron.monthly \
2252   ./scripts/cryptpasswd \
2253   ./raddb/radrelay.conf \
2254   ./raddb/radiusd.conf
2255 )