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