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