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