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