Check and define sig_t if it's not in signals.h
[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 #  As of OSX 10.9 (Mavericks), /usr is no longer populated with the
119 dnl #  standard set of headers and libraries, instead were meant to use
120 dnl #  one of the SDKs which contains system headers and libraries for
121 dnl #  different versions of OSX and iOS.
122 dnl #
123 case "$host" in
124   *-darwin*)
125     dnl #
126     dnl #  The version of GCC apple ships with Mavericks works out of the
127     dnl #  box, and presumably selects the highest version SDK for OSX.
128     dnl #
129     AC_MSG_CHECKING([if cc is apple llvm])
130     if ! $CC --version 2>&1 | grep -I 'Apple LLVM' > /dev/null; then
131       AC_MSG_RESULT(no)
132       AC_CHECK_PROG(SW_VERS, sw_vers, yes, no)
133       AC_CHECK_PROG(XCODEBUILD, xcodebuild, yes, no)
134
135       if test "x$SW_VERS" = "xyes" && test "x$XCODEBUILD" = "xyes"; then
136         AC_MSG_NOTICE([determining OSX SDK path])
137         osx_sdk_path=$(xcodebuild -version -sdk macosx$(sw_vers -productVersion | egrep -o '^[[0-9]]+\.[[0-9]]+') Path)
138         AC_MSG_RESULT([$osx_sdk_path])
139
140         dnl #
141         dnl #  We need to export these, else the child configure scripts all fail
142         dnl #  their compiler checks.
143         dnl #
144         export CFLAGS="$CFLAGS --sysroot=$osx_sdk_path"
145         export CPPFLAGS="$CPPFLAGS --sysroot=$osx_sdk_path"
146         export LDFLAGS="$LDFLAGS -L$osx_sdk_path/usr/lib/"
147         DARWIN_CFLAGS="--sysroot=$osx_sdk_path"
148         AC_SUBST(DARWIN_CFLAGS)
149       fi
150     else
151       AC_MSG_RESULT(yes)
152     fi
153     ;;
154 esac
155
156 dnl #
157 dnl #  Check for GNU cc
158 dnl #
159 AC_PROG_CC
160 AC_PROG_CXX
161
162 dnl #
163 dnl #  check for AIX, to allow us to use some BSD functions
164 dnl #  must be before macros that call the compiler.
165 dnl #
166 AC_AIX
167
168 AC_PROG_GCC_TRADITIONAL
169 AC_PROG_CC_SUNPRO
170 AC_PROG_RANLIB
171
172 dnl #
173 dnl #  Definitive check for whether the compiler is clang
174 dnl #
175 AX_CC_IS_CLANG
176 if test "x$ax_cv_cc_clang" = "xyes"; then
177   AC_SUBST(clang_path, "$CC")
178 else
179   AC_SUBST(clang_path, "")
180 fi
181
182
183 dnl #
184 dnl #  Set Default CFLAGS for GCC compatible compilers
185 dnl #
186 if test "x$GCC" = "xyes"; then
187   CFLAGS="$CFLAGS -Wall -D_GNU_SOURCE"
188 fi
189
190 dnl #
191 dnl #  -Qunused-arguments means the compiler won't complain about unsupported arguments
192 dnl #
193 AX_CC_QUNUSED_ARGUMENTS_FLAG
194 if test "x$ax_cv_cc_qunused_arguments_flag" = "xyes"; then
195   CFLAGS="$CFLAGS -Qunused-arguments"
196   LDFLAGS="$LDFLAGS -Qunused-arguments"
197 fi
198
199 dnl #
200 dnl #  Compile in large (2G+) file support.
201 dnl #
202 AC_SYS_LARGEFILE
203
204 dnl #
205 dnl #  check for system bytesex
206 dnl #  AC_DEFINES WORDS_BIGENDIAN
207 dnl #
208 AC_C_BIGENDIAN(
209   [AC_DEFINE(BIG_ENDIAN, 1, [Define if your processor stores words with the most significant byte first])],
210   [AC_DEFINE(LITTLE_ENDIAN, 1, [Define if your processor stores words with the least significant byte first])]
211 )
212
213 dnl #
214 dnl #  Find GNU Make.
215 dnl #
216 AC_CHECK_PROG(GMAKE, gmake, yes, no)
217 if test $GMAKE = no; then
218   AC_PATH_PROG(MAKE, make, /usr/local/bin/make)
219 else
220   AC_PATH_PROG(MAKE, gmake, /usr/local/gnu/bin/make)
221 fi
222 makever=`$ac_cv_path_MAKE --version 2>&1 | grep "GNU Make"`
223 if test -z "$makever"; then
224   AC_MSG_ERROR([GNU Make is not installed.  Please download and install it from ftp://prep.ai.mit.edu/pub/gnu/make/ before continuing.])
225 fi
226
227 dnl #
228 dnl #  autoconf explicitly sets MAKEFLAGS and MFLAGS to '' even though we
229 dnl #  didn't tell it to, so we have to use FR_MAKEFLAGS.
230 dnl #
231 dnl #  determine the number of cores available and set the number of build
232 dnl #  processes appropriately.
233 dnl #
234 AX_SYSTEM_CORES
235
236 dnl #  Temporarily disabled because test and installation targets do not
237 dnl #  have dependencies set up correctly for multiple build processes.
238 dnl if test "x$ax_cv_system_cores" != "x"; then
239 dnl  : ${FR_MAKEFLAGS=-j$ax_cv_system_cores}
240 dnl fi
241 AC_SUBST(FR_MAKEFLAGS)
242
243 dnl #
244 dnl #  See if we have Git.
245 dnl #
246 AC_CHECK_PROG(GIT, git, yes, no)
247
248 dnl Put this in later, when all distributed modules use autoconf.
249 dnl AC_ARG_WITH(disablemodulefoo,
250 dnl [  --without-rlm_foo         Disables module compilation.  Module list:]
251 dnl esyscmd([find src/modules -type d -name rlm_\* -print |\
252 dnl   sed -e 's%src/modules/.*/% (sub)- %; s%.*/%- %' |\
253 dnl   awk '{print "                            "$0}']))
254
255 AC_ARG_ENABLE(strict-dependencies,
256 [  --enable-strict-dependencies  fail configure on lack of module dependancy.])
257
258 AC_ARG_ENABLE(werror,
259 [  --enable-werror         causes the build to fail if any warnings are generated.],
260 [ case "$enableval" in
261     no)
262       werror=no
263     ;;
264     *)
265       werror=yes
266   esac ]
267 )
268
269 dnl #
270 dnl #  extra argument: --with-docdir
271 dnl #
272 docdir='${datadir}/doc/freeradius'
273 AC_MSG_CHECKING([docdir])
274 AC_ARG_WITH(docdir,
275 [  --with-docdir=DIR       directory for documentation [DATADIR/doc/freeradius] ],
276 [ case "$withval" in
277   no)
278     docdir=no
279     ;;
280   yes)
281     ;;
282   [[\\/$]]* | ?:[[\\/]]* )
283     docdir="$withval"
284     ;;
285   *)
286     AC_MSG_ERROR([expected an absolute directory name for --with-docdir: $withval])
287     ;;
288   esac ]
289 )
290 AC_SUBST(docdir)
291 AC_MSG_RESULT($docdir)
292 if test "x$docdir" = xno; then
293   AC_MSG_WARN([Documentation files will NOT be installed.])
294 fi
295
296 dnl #
297 dnl #  extra argument: --with-logdir
298 dnl #
299 logdir='${localstatedir}/log/radius'
300 AC_MSG_CHECKING(logdir)
301 AC_ARG_WITH(logdir,
302 [  --with-logdir=DIR       directory for logfiles [LOCALSTATEDIR/log/radius] ],
303 [ case "$withval" in
304   no)
305     AC_MSG_ERROR([Need logdir])
306     ;;
307   yes)
308     ;;
309   [[\\/$]]* | ?:[[\\/]]* )
310     logdir="$withval"
311     ;;
312   *)
313     AC_MSG_ERROR([expected an absolute directory name for --with-logdir: $withval])
314     ;;
315   esac ]
316 )
317 AC_SUBST(logdir)
318 AC_MSG_RESULT($logdir)
319
320 dnl #
321 dnl #  extra argument: --with-radacctdir
322 dnl #
323 radacctdir='${logdir}/radacct'
324 AC_MSG_CHECKING(radacctdir)
325 AC_ARG_WITH(radacctdir,
326 [  --with-radacctdir=DIR   directory for detail files [LOGDIR/radacct] ],
327 [ case "$withval" in
328   no)
329     AC_MSG_ERROR([Need radacctdir])
330     ;;
331   yes)
332     ;;
333   [[\\/$]]* | ?:[[\\/]]* )
334     radacctdir="$withval"
335     ;;
336   *)
337     AC_MSG_ERROR([expected an absolute directory name for --with-radacctdir: $withval])
338     ;;
339   esac ]
340 )
341 AC_SUBST(radacctdir)
342 AC_MSG_RESULT($radacctdir)
343
344 dnl #
345 dnl #  extra argument: --with-raddbdir
346 dnl #
347 raddbdir='${sysconfdir}/raddb'
348 AC_MSG_CHECKING(raddbdir)
349 AC_ARG_WITH(raddbdir,
350 [  --with-raddbdir=DIR     directory for config files [SYSCONFDIR/raddb] ],
351 [ case "$withval" in
352   no)
353     AC_MSG_ERROR([Need raddbdir])
354     ;;
355   yes)
356     ;;
357   [[\\/$]]* | ?:[[\\/]]* )
358     raddbdir="$withval"
359     ;;
360   *)
361     AC_MSG_ERROR([expected an absolute directory name for --with-raddbdir: $withval])
362     ;;
363   esac ]
364 )
365 AC_SUBST(raddbdir)
366 AC_MSG_RESULT($raddbdir)
367
368 dnl #
369 dnl #  extra argument: --with-dictdir
370 dnl #
371 dictdir='${datarootdir}/freeradius'
372 AC_MSG_CHECKING(dictdir)
373 AC_ARG_WITH(dictdir,
374 [  --with-dictdir=DIR      directory for dictionary files [DATAROOTDIR/freeradius] ],
375 [ case "$withval" in
376   no)
377     AC_MSG_ERROR([Need dictdir])
378     ;;
379   yes)
380     ;;
381   [[\\/$]]* | ?:[[\\/]]* )
382     dictdir="$withval"
383     ;;
384   *)
385     AC_MSG_ERROR([expected an absolute directory name for --with-dictdir: $withval])
386     ;;
387   esac ]
388 )
389 AC_SUBST(dictdir)
390 AC_MSG_RESULT($dictdir)
391
392 modconfdir='${raddbdir}/mods-config'
393 AC_SUBST(modconfdir)
394
395 dnl #
396 dnl #  extra argument: --with-ascend-binary
397 dnl #
398 WITH_ASCEND_BINARY=yes
399 AC_ARG_WITH(ascend-binary,
400 [  --with-ascend-binary    include support for Ascend binary filter attributes (default=yes)],
401 [ case "$withval" in
402   yes)
403     ;;
404   *)
405     WITH_ASCEND_BINARY=no
406   esac ]
407 )
408 if test "x$WITH_ASCEND_BINARY" = "xyes"; then
409   AC_DEFINE(WITH_ASCEND_BINARY, [1], [include support for Ascend binary filter attributes])
410 fi
411
412 dnl #
413 dnl #  extra argument: --with-threads
414 dnl #
415 WITH_THREADS=yes
416 AC_ARG_WITH(threads,
417 [  --with-threads          use threads, if available.  (default=yes) ],
418 [ case "$withval" in
419   yes)
420     ;;
421   *)
422     WITH_THREADS=no
423   esac ]
424 )
425
426 dnl #
427 dnl #  extra argument: --with-tcp
428 dnl #
429 WITH_TCP=yes
430 AC_ARG_WITH(tcp,
431 [  --with-tcp              compile in TCP support. (default=yes)],
432 [ case "$withval" in
433   yes)
434     ;;
435   *)
436     WITH_TCP=no
437   esac ]
438 )
439 if test "x$WITH_TCP" = "xyes"; then
440   AC_DEFINE(WITH_TCP, [1], [define if you want TCP support (For RADSec et al)])
441 fi
442
443 dnl #
444 dnl #  extra argument: --with-vmps
445 dnl #
446 WITH_VMPS=yes
447 AC_ARG_WITH(vmps,
448 [  --with-vmps             compile in VMPS support. (default=yes)],
449 [ case "$withval" in
450   yes)
451     ;;
452   *)
453     WITH_VMPS=no
454   esac ]
455 )
456 if test "x$WITH_VMPS" = "xyes"; then
457   AC_DEFINE(WITH_VMPS, [1], [define if you want VMPS support])
458 fi
459
460 dnl #
461 dnl #  extra argument: --with-dhcp
462 dnl #
463 WITH_DHCP=yes
464 AC_ARG_WITH(dhcp,
465 [  --with-dhcp             compile in DHCP support. (default=yes)],
466 [ case "$withval" in
467   yes)
468     ;;
469   *)
470     WITH_DHCP=no
471   esac ]
472 )
473 if test "x$WITH_DHCP" = "xyes"; then
474   AC_DEFINE(WITH_DHCP, [1], [define if you want DHCP support])
475 fi
476
477 dnl #
478 dnl #  Allow the user to specify a list of modules to be linked
479 dnl #  statically to the server.
480 dnl #
481 STATIC_MODULES=
482 AC_ARG_WITH(static_modules,
483 [  --with-static-modules=QUOTED-MODULE-LIST],[
484   for i in $withval; do
485     STATIC_MODULES="$STATIC_MODULES -dlpreopen ../modules/rlm_$i/rlm_$i.la"
486   done
487 ])
488
489 USE_SHARED_LIBS=yes
490 AC_ARG_WITH(shared-libs,
491 [  --with-shared-libs               build dynamic libraries and link against them. (default=yes)],
492 [ case "$withval" in
493   no)
494     USE_SHARED_LIBS=no
495     ;;
496   *)
497   esac
498 ])
499
500 MODULES=
501 AC_ARG_WITH(modules,
502 [  --with-modules=QUOTED-MODULE-LIST],[
503  for i in $withval; do
504    MODULES="$MODULES $i"
505  done
506 ])
507
508 dnl #
509 dnl #  extra argument: --with-experimental-modules
510 dnl #
511 EXPERIMENTAL=
512 AC_ARG_WITH(experimental-modules,
513 [  --with-experimental-modules      use experimental and unstable modules. (default=no, unless --enable-developer=yes) ],
514 [ case "$withval" in
515   yes)
516     EXPERIMENTAL=yes
517     ;;
518   no)
519     EXPERIMENTAL=no
520     ;;
521   *)
522   esac ]
523 )
524
525 dnl #
526 dnl #  extra argument: --with-udpfromto
527 dnl #
528 WITH_UDPFROMTO=yes
529 AC_ARG_WITH(udpfromto,
530 [  --with-udpfromto                 compile in UDPFROMTO support. (default=yes)],
531 [ case "$withval" in
532   yes)
533     WITH_UDPFROMTO=yes
534     ;;
535   *)
536     WITH_UDPFROMTO=no
537   esac ]
538 )
539
540 if test "x$WITH_UDPFROMTO" = "xyes"; then
541   AC_DEFINE(WITH_UDPFROMTO, [], [define if you want udpfromto])
542 fi
543
544 dnl #
545 dnl #  extra argument: --with-openssl
546 dnl #
547 WITH_OPENSSL=yes
548 AC_ARG_WITH(openssl,
549 [  --with-openssl                   use OpenSSL. (default=yes)],
550 [ case "$withval" in
551   no)
552     WITH_OPENSSL=no
553     ;;
554   *)
555     WITH_OPENSSL=yes
556     ;;
557   esac ]
558 )
559
560 dnl #
561 dnl #  extra argument: --with-openssl-includes=dir
562 dnl #
563 OPENSSL_INCLUDE_DIR=
564 AC_ARG_WITH(openssl-includes,
565 [  --with-openssl-includes=DIR      directory to look for OpenSSL include files in],
566 [ case "$withval" in
567   *) OPENSSL_INCLUDE_DIR="$withval"
568     ;;
569   esac ]
570 )
571
572 dnl #
573 dnl #  extra argument: --with-openssl-libraries=dir
574 dnl #
575 OPENSSL_LIB_DIR=
576 AC_ARG_WITH(openssl-libraries,
577 [  --with-openssl-libraries=DIR     directory to look for OpenSSL library files in],
578 [ case "$withval" in
579   *) OPENSSL_LIB_DIR="$withval"
580     ;;
581   esac ]
582 )
583
584 dnl #
585 dnl #  These next two arguments don't actually do anything.  They're
586 dnl #  place holders so that the top-level configure script can tell
587 dnl #  the user how to configure lower-level modules
588 dnl #
589
590 dnl #
591 dnl #  extra argument: --with-rlm-FOO-lib-dir
592 dnl #
593 AC_ARG_WITH(rlm-FOO-lib-dir,
594 [  --with-rlm-FOO-lib-dir=DIR       directory to look for library files used by module FOO in],
595 [ case "$withval" in
596   *)
597     ;;
598   esac ]
599 )
600
601 dnl #
602 dnl #  extra argument: --with-rlm-FOO-include-dir
603 dnl #
604 AC_ARG_WITH(rlm-FOO-include-dir,
605 [  --with-rlm-FOO-include-dir=DIR   directory to look for include files used by module FOO in],
606 [ case "$withval" in
607   *)
608     ;;
609   esac ]
610 )
611
612 dnl #############################################################
613 dnl #
614 dnl #  1. Checks for programs
615 dnl #
616 dnl #############################################################
617
618 CHECKRAD=checkrad
619 AC_PATH_PROG(PERL, perl, /usr/local/bin/perl)
620 if test "x$ac_cv_path_PERL" = "x"; then
621   AC_MSG_WARN([perl not found - Simultaneous-Use and checkrad may not work])
622 fi
623 AC_PATH_PROG(SNMPGET, snmpget)
624 if test "x$ac_cv_path_SNMPGET" = "x"; then
625   AC_MSG_WARN([snmpget not found - Simultaneous-Use and checkrad may not work])
626 fi
627
628 AC_PATH_PROG(SNMPWALK, snmpwalk)
629 if test "x$ac_cv_path_SNMPWALK" = "x"; then
630   AC_MSG_WARN([snmpwalk not found - Simultaneous-Use and checkrad may not work])
631 fi
632
633 AC_PATH_PROG(RUSERS, rusers, /usr/bin/rusers)
634
635 dnl #
636 dnl #  FIXME This is truly gross.
637 dnl #
638 missing_dir=`cd $ac_aux_dir && pwd`
639 AM_MISSING_PROG(ACLOCAL, aclocal, $missing_dir)
640 AM_MISSING_PROG(AUTOCONF, autoconf, $missing_dir)
641 AM_MISSING_PROG(AUTOHEADER, autoheader, $missing_dir)
642
643 AC_PATH_PROG(LOCATE,locate)
644 AC_PATH_PROG(DIRNAME,dirname)
645 AC_PATH_PROG(GREP,grep)
646
647 dnl #############################################################
648 dnl #
649 dnl #  2. Checks for libraries
650 dnl #
651 dnl #############################################################
652
653 dnl #
654 dnl #  If using pthreads, check for -lpthread (posix) or -lc_r (*BSD)
655 dnl #
656 old_CFLAGS=$CFLAGS
657 if test "x$WITH_THREADS" = "xyes"; then
658   if test $ac_cv_prog_suncc = "yes"; then
659     CFLAGS="$CFLAGS -mt"
660   fi
661
662   AC_CHECK_HEADERS(pthread.h, [], [ WITH_THREADS="no" ])
663
664   dnl #
665   dnl #  pthread stuff is usually in -lpthread
666   dnl #  or in -lc_r, on *BSD
667   dnl #
668   dnl #  On Some systems, we need extra pre-processor flags, to get them to
669   dnl #  to do the threading properly.
670   dnl #
671   AC_CHECK_LIB(pthread, pthread_create,
672     [
673       CFLAGS="$CFLAGS -D_REENTRANT -D_POSIX_PTHREAD_SEMANTICS"
674       LIBS="-lpthread $LIBS"
675     ],
676     [
677       AC_CHECK_LIB(c_r, pthread_create,
678         [ CFLAGS="$CFLAGS -pthread -D_THREAD_SAFE" ],
679         [ WITH_THREADS="no" ]
680       )
681     ]
682   )
683 fi
684
685 dnl #
686 dnl #  If we have NO pthread libraries, remove any knowledge of threads.
687 dnl #
688 if test "x$WITH_THREADS" != "xyes"; then
689   CFLAGS=$old_CFLAGS
690   ac_cv_header_pthread_h="no"
691   WITH_THREADS=no
692 else
693   dnl #
694   dnl #  We need sem_init() and friends, as they're the friendliest
695   dnl #  semaphore functions for threading.
696   dnl #
697   dnl #  HP/UX requires linking with librt, too, to get the sem_* symbols.
698   dnl #  Some systems have them in -lsem
699   dnl #  Solaris has them in -lposix4
700   dnl #  NetBSD has them in -lsemaphore
701   dnl #
702
703   AC_SEARCH_LIBS(sem_init, pthread sem posix4 rt semaphore,
704     [],
705     [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]])]
706   )
707 fi
708
709 if test "x$WITH_THREADS" = "xyes"; then
710   AC_DEFINE(WITH_THREADS, [1], [define if you want thread support])
711 fi
712
713 dnl #
714 dnl #  Check if we need -lsocket
715 dnl #
716 AC_CHECK_LIB(dl, dlopen)
717
718 dnl #
719 dnl #  Check if we need -lsocket
720 dnl #
721 AC_CHECK_LIB(socket, getsockname)
722
723 dnl #
724 dnl #  Check for -lresolv
725 dnl #  This library may be needed later.
726 dnl #
727 AC_CHECK_LIB(resolv, inet_aton)
728
729 dnl #
730 dnl #  Check if we need -lnsl. Usually if we want to
731 dnl #  link against -lsocket we need to include -lnsl as well.
732 dnl #
733 AC_CHECK_LIB(nsl, inet_ntoa)
734 AC_CHECK_LIB(ws2_32, htonl)
735
736 dnl #
737 dnl #  Check the pcap library for the RADIUS sniffer.
738 dnl #
739 smart_try_dir="$pcap_lib_dir"
740 FR_SMART_CHECK_LIB(pcap, pcap_open_live)
741 if test "x$ac_cv_lib_pcap_pcap_open_live" != "xyes"; then
742   AC_MSG_WARN([pcap library not found. Use --with-pcap-lib-dir=<path>.])
743   AC_MSG_WARN([pcap library not found, silently disabling the RADIUS sniffer and ARP listener.])
744 else
745   PCAP_LIBS="${smart_lib}"
746   LIBS=$old_LIBS
747   AC_DEFINE(HAVE_LIBPCAP, 1,
748     [Define to 1 if you have the `pcap' library (-lpcap).]
749   )
750 fi
751
752 VL_LIB_READLINE
753
754 dnl #############################################################
755 dnl #
756 dnl #  3. Checks for header files
757 dnl #
758 dnl #############################################################
759
760 dnl #
761 dnl #  Interix requires us to set -D_ALL_SOURCE, otherwise
762 dnl #  getopt will be #included, but won't link.  <sigh>
763 dnl #
764 dnl #
765 case "$host" in
766   *-interix*)
767     CFLAGS="$CFLAGS -D_ALL_SOURCE"
768     ;;
769   *-darwin*)
770     CFLAGS="$CFLAGS -DDARWIN"
771     LIBS="-framework DirectoryService $LIBS"
772     ;;
773 esac
774
775 AC_HEADER_DIRENT
776 AC_HEADER_STDC
777 AC_HEADER_TIME
778 AC_HEADER_SYS_WAIT
779
780 AC_CHECK_HEADERS( \
781   dlfcn.h \
782   unistd.h \
783   crypt.h \
784   errno.h \
785   execinfo.h \
786   features.h \
787   resource.h \
788   sys/resource.h \
789   getopt.h \
790   malloc.h \
791   utmp.h \
792   utmpx.h \
793   signal.h \
794   sys/select.h \
795   syslog.h \
796   inttypes.h \
797   stdint.h \
798   stdio.h \
799   netdb.h \
800   semaphore.h \
801   arpa/inet.h \
802   netinet/in.h \
803   sys/types.h \
804   sys/socket.h \
805   winsock.h \
806   utime.h \
807   sys/time.h \
808   sys/wait.h \
809   sys/security.h \
810   fcntl.h \
811   sys/fcntl.h \
812   sys/prctl.h \
813   sys/un.h \
814   glob.h \
815   prot.h \
816   pwd.h \
817   grp.h \
818   stddef.h \
819   fnmatch.h \
820   sia.h \
821   siad.h
822 )
823
824 dnl #
825 dnl #  FreeBSD requires sys/socket.h before net/if.h
826 dnl #
827 AC_CHECK_HEADERS(net/if.h, [], [],
828 [
829   #ifdef HAVE_SYS_SOCKET_H
830   #  include <sys/socket.h>
831   #endif
832 ])
833
834 dnl #
835 dnl #  other checks which require headers
836 dnl #
837 if test "x$ac_cv_header_sys_security_h" = "xyes" && test "x$ac_cv_header_prot_h" = "xyes"
838 then
839   AC_DEFINE(OSFC2, [], [define if you have OSFC2 authentication])
840 fi
841
842 if test "x$ac_cv_header_sia_h" = "xyes" && test "x$ac_cv_header_siad_h" = "xyes"
843 then
844   AC_DEFINE(OSFSIA, [], [define if you have OSFSIA authentication])
845 fi
846
847 dnl #
848 dnl #  Were we told to use OpenSSL, if we were and we find an error, call AC_MSG_FAILURE and exit
849 dnl #
850 if test "x$WITH_OPENSSL" = xyes; then
851   old_LIBS=$LIBS
852   old_LDFLAGS="$LDFLAGS"
853
854   OPENSSL_INCLUDE="-DNO_OPENSSL"
855   OPENSSL_LIBS=
856   if test "x$OPENSSL_LIB_DIR" != "x"; then
857     LDFLAGS="-L$OPENSSL_LIB_DIR $LDFLAGS"
858   fi
859
860   dnl #
861   dnl #  Check we can link to libssl
862   dnl #
863   AC_CHECK_LIB(crypto, DH_new,
864     [
865       LIBS="-lcrypto $LIBS"
866       AC_DEFINE(HAVE_LIBCRYPTO, 1, [Define to 1 if you have the `crypto' library (-lcrypto).])
867       AC_CHECK_LIB(ssl, SSL_new,
868         [
869           AC_DEFINE(HAVE_LIBSSL, 1, [Define to 1 if you have the `ssl' library (-lssl).])
870           if test "x$OPENSSL_LIB_DIR" != "x"; then
871             OPENSSL_LIBS="-L$OPENSSL_LIB_DIR"
872           fi
873           OPENSSL_LIBS="$OPENSSL_LIBS -lcrypto -lssl -lcrypto"
874         ],
875         [
876           AC_MSG_FAILURE([failed linking to libssl])
877         ]
878       )
879     ],
880     []
881   )
882
883   dnl #
884   dnl #  Check we can find required headers
885   dnl #
886   old_CPPFLAGS=$CPPFLAGS
887   old_CFLAGS=$CFLAGS
888   if test "x$OPENSSL_INCLUDE_DIR" != "x"; then
889     CPPFLAGS="-isystem $OPENSSL_INCLUDE_DIR $CPPFLAGS"
890     CFLAGS="-isystem $OPENSSL_INCLUDE_DIR $CFLAGS"
891   fi
892
893   dnl #
894   dnl #  Stupid RedHat shit
895   dnl #
896   CPPFLAGS="$CPPFLAGS -DOPENSSL_NO_KRB5"
897   AC_CHECK_HEADERS( \
898     openssl/ssl.h \
899     openssl/crypto.h \
900     openssl/err.h \
901     openssl/evp.h \
902     openssl/md5.h \
903     openssl/md4.h \
904     openssl/sha.h \
905     openssl/ocsp.h \
906     openssl/engine.h,
907     [],
908     [
909       AC_MSG_FAILURE([failed locating OpenSSL headers])
910     ]
911   )
912
913   AC_MSG_CHECKING([for OpenSSL version >= 0.9.7])
914   AC_EGREP_CPP(yes,
915     [#include <openssl/crypto.h>
916      #if (OPENSSL_VERSION_NUMBER >= 0x00907000L)
917      yes
918      #endif
919     ],
920     [
921       AC_MSG_RESULT(yes)
922     ],
923     [
924       AC_MSG_RESULT(no)
925       AC_MSG_FAILURE([OpenSSL version too old])
926     ]
927   )
928
929   if test "x$OPENSSL_INCLUDE_DIR" != "x"; then
930     OPENSSL_INCLUDE="-isystem $OPENSSL_INCLUDE_DIR -DOPENSSL_NO_KRB5"
931   else
932     OPENSSL_INCLUDE="-DOPENSSL_NO_KRB5"
933   fi
934
935   dnl #
936   dnl #  Now check that the header versions match the library
937   dnl #
938   AC_MSG_CHECKING([OpenSSL library and header version consistency])
939   AC_RUN_IFELSE(
940     [AC_LANG_PROGRAM(
941       [[
942         #include <stdio.h>
943         #include <openssl/opensslv.h>
944         #include <openssl/crypto.h>
945       ]],
946       [[
947         if (SSLeay() == OPENSSL_VERSION_NUMBER) {
948           return 0;
949         } else {
950           printf("library: %lx header: %lx... ", (unsigned long) SSLeay(), (unsigned long) OPENSSL_VERSION_NUMBER);
951           return 1;
952         }
953       ]]
954     )],
955     [
956       AC_MSG_RESULT(yes)
957     ],
958     [
959       AC_MSG_RESULT(no)
960       AC_MSG_FAILURE([OpenSSL library version does not match header version])
961     ]
962   )
963
964   if test "x$OPENSSL_LIBS" = x; then
965     LIBS=$old_LIBS
966     LDFLAGS="$old_LDFLAGS"
967   fi
968   if test "x$OPENSSL_INCLUDE" = x; then
969     CPPFLAGS=$old_CPPFLAGS
970     CFLAGS=$old_CFLAGS
971   fi
972 fi
973
974 AC_SUBST(OPENSSL_INCLUDE)
975 AC_SUBST(OPENSSL_LIBS)
976 export OPENSSL_LIBS
977
978 dnl #
979 dnl #  Check the pcap includes for the RADIUS sniffer.
980 dnl #
981 if test "x$PCAP_LIBS" = x; then
982   AC_MSG_NOTICE([skipping test for pcap.h.])
983 else
984   smart_try_dir="$pcap_include_dir"
985   FR_SMART_CHECK_INCLUDE([pcap.h])
986   if test "x$ac_cv_header_pcap_h" != "xyes"; then
987     AC_MSG_WARN([pcap headers not found. Use --with-pcap-include-dir=<path>.])
988     AC_MSG_WARN([pcap.h not found, silently disabling the RADIUS sniffer, and ARP listener.])
989   else
990     AC_DEFINE(HAVE_PCAP_H, 1, [Define to 1 if you have the <pcap.h> header file.])
991
992     AC_CHECK_LIB(pcap, pcap_fopen_offline,
993       [
994         AC_DEFINE(HAVE_PCAP_FOPEN_OFFLINE, 1, [Define to 1 if you have the function pcap_fopen_offline.])
995       ]
996     )
997
998     AC_CHECK_LIB(pcap, pcap_dump_fopen,
999       [
1000         AC_DEFINE(HAVE_PCAP_DUMP_FOPEN, 1, [Define to 1 if you have the function pcap_dump_fopen.])
1001       ]
1002     )
1003   fi
1004 fi
1005 AC_SUBST(PCAP_LIBS)
1006
1007 dnl #############################################################
1008 dnl #
1009 dnl #  4. Checks for typedefs
1010 dnl #
1011 dnl #############################################################
1012
1013 dnl #
1014 dnl #  Ensure that these are defined
1015 dnl #
1016 AC_TYPE_OFF_T
1017 AC_TYPE_PID_T
1018 AC_TYPE_SIZE_T
1019 AC_TYPE_UID_T
1020
1021 dnl #
1022 dnl #  Check for socklen_t
1023 dnl #
1024 FR_CHECK_TYPE_INCLUDE(
1025   [
1026     #ifdef HAVE_SYS_TYPES_H
1027     #  include <sys/types.h>
1028     #endif
1029
1030     #ifdef HAVE_SYS_SOCKET_H
1031     #  include <sys/socket.h>
1032     #endif
1033   ],
1034   socklen_t, int, [socklen_t is generally 'int' on systems which don't use it]
1035 )
1036
1037 dnl #
1038 dnl #  Check for uint8_t
1039 dnl #
1040 FR_CHECK_TYPE_INCLUDE(
1041   [
1042     #ifdef HAVE_INTTYPES_H
1043     #  include <inttypes.h>
1044     #endif
1045
1046     #ifdef HAVE_STDINT_H
1047     #  include <stdint.h>
1048     #endif
1049   ],
1050   uint8_t, unsigned char, [uint8_t should be the canonical 'octet' for network traffic]
1051 )
1052
1053 dnl #
1054 dnl #  Check for uint16_t
1055 dnl #
1056 FR_CHECK_TYPE_INCLUDE(
1057   [
1058     #ifdef HAVE_INTTYPES_H
1059     #  include <inttypes.h>
1060     #endif
1061
1062     #ifdef HAVE_STDINT_H
1063     #  include <stdint.h>
1064     #endif
1065   ],
1066   uint16_t, unsigned short, [uint16_t should be the canonical '2 octets' for network traffic]
1067 )
1068
1069 dnl #
1070 dnl #  Check for uint32_t
1071 dnl #
1072 FR_CHECK_TYPE_INCLUDE(
1073   [
1074     #ifdef HAVE_INTTYPES_H
1075     #  include <inttypes.h>
1076     #endif
1077
1078     #ifdef HAVE_STDINT_H
1079     #  include <stdint.h>
1080     #endif
1081   ],
1082   uint32_t, unsigned int, [uint32_t should be the canonical 'network integer']
1083 )
1084
1085 dnl #
1086 dnl #  Check for uint64_t
1087 dnl #
1088 FR_CHECK_TYPE_INCLUDE(
1089   [
1090     #ifdef HAVE_INTTYPES_H
1091     #  include <inttypes.h>
1092     #endif
1093
1094     #ifdef HAVE_STDINT_H
1095     #  include <stdint.h>
1096     #endif
1097   ],
1098   uint64_t, unsigned long long, [uint64_t is required for larger counters]
1099 )
1100
1101 FR_CHECK_TYPE_INCLUDE(
1102   [
1103     #ifdef HAVE_SIGNAL_H
1104     #  include <signal.h>
1105     #endif
1106   ],
1107   sig_t, void(*sig_t)(int), [signal action callback function]
1108 )
1109
1110 dnl #
1111 dnl #  Check for __uint128_t (compiler builtin)
1112 dnl #
1113 AC_CHECK_TYPE(__uint128_t, AC_DEFINE(HAVE___UINT128_T, 1, [compiler specific 128 bit unsigned integer]), [], [])
1114
1115 dnl #
1116 dnl #  Check for uint128_t (fictitious future data type)
1117 dnl #
1118 AC_CHECK_TYPE(uint128_t, AC_DEFINE(HAVE_UINT128_T, 1, [128 bit unsigned integer]), [],
1119   [
1120     #ifdef HAVE_INTTYPES_H
1121     #  include <inttypes.h>
1122     #endif
1123
1124     #ifdef HAVE_STDINT_H
1125     #  include <stdint.h>
1126     #endif
1127   ]
1128 )
1129
1130 AC_CHECK_TYPE(struct in6_addr, AC_DEFINE(HAVE_STRUCT_IN6_ADDR, 1, [IPv6 address structure]), [],
1131   [
1132     #ifdef HAVE_NETINET_IN_H
1133     #  include <netinet/in.h>
1134     #endif
1135   ]
1136 )
1137
1138 AC_CHECK_TYPE(struct sockaddr_storage, AC_DEFINE(HAVE_STRUCT_SOCKADDR_STORAGE, 1, [Generic socket addresses]), [],
1139   [
1140     #ifdef HAVE_NETINET_IN_H
1141     #  include <netinet/in.h>
1142     #endif
1143
1144     #ifdef HAVE_SYS_SOCKET_H
1145     #  include <sys/socket.h>
1146     #endif
1147 ])
1148
1149 AC_CHECK_TYPE(struct sockaddr_in6, AC_DEFINE(HAVE_STRUCT_SOCKADDR_IN6, 1, [IPv6 socket addresses]), [],
1150   [
1151     #ifdef HAVE_NETINET_IN_H
1152     #  include <netinet/in.h>
1153     #endif
1154 ])
1155
1156 AC_CHECK_TYPE(struct addrinfo, AC_DEFINE(HAVE_STRUCT_ADDRINFO, 1, [Generic DNS lookups]), [],
1157   [
1158     #ifdef HAVE_SYS_TYPES_H
1159     #  include <sys/types.h>
1160     #endif
1161
1162     #ifdef HAVE_SYS_SOCKET_H
1163     #  include <sys/socket.h>
1164     #endif
1165
1166     #ifdef HAVE_NETDB_H
1167     #  include <netdb.h>
1168     #endif
1169   ]
1170 )
1171
1172 dnl #############################################################
1173 dnl #
1174 dnl #  5. Checks for structures and functions
1175 dnl #
1176 dnl #############################################################
1177 AC_CHECK_FUNCS( \
1178   getopt_long \
1179   fcntl \
1180   strsignal \
1181   sigaction \
1182   sigprocmask \
1183   pthread_sigmask \
1184   snprintf \
1185   vsnprintf \
1186   setsid \
1187   strncasecmp \
1188   strcasecmp \
1189   localtime_r \
1190   ctime_r \
1191   gmtime_r \
1192   strsep \
1193   inet_aton \
1194   inet_pton \
1195   inet_ntop \
1196   setlinebuf \
1197   setvbuf \
1198   getusershell \
1199   initgroups \
1200   getaddrinfo \
1201   getnameinfo \
1202   closefrom \
1203   gettimeofday \
1204   getpeereid \
1205   setuid \
1206   setresuid \
1207   getresuid \
1208   strlcat \
1209   strlcpy
1210 )
1211
1212 AC_TYPE_SIGNAL
1213
1214 dnl #
1215 dnl #  Check if we have utmpx.h
1216 dnl #  if so, check if struct utmpx has entry ut_xtime
1217 dnl #  if not, set it to define ut_xtime == ut_tv.tv_sec
1218 dnl #
1219 if test "x$ac_cv_header_utmpx_h" = "xyes"; then
1220  FR_CHECK_STRUCT_HAS_MEMBER([#include <utmpx.h>], [struct utmpx], ut_xtime)
1221  if test "x$ac_cv_type_struct_utmpx_has_ut_xtime" = "x"; then
1222    AC_DEFINE(ut_xtime, ut_tv.tv_sec, [define to something if you don't have ut_xtime in struct utmpx])
1223  fi
1224 fi
1225
1226 dnl #
1227 dnl #  struct ip_pktinfo
1228 dnl #
1229 FR_CHECK_STRUCT_HAS_MEMBER([#include <netinet/in.h>], [struct in_pktinfo], ipi_addr)
1230 if test "x$ac_cv_type_struct_in_pktinfo_has_ipi_addr" = "xyes"; then
1231   AC_DEFINE(HAVE_IP_PKTINFO, [], [define if you have IP_PKTINFO (Linux)])
1232 fi
1233
1234 dnl #
1235 dnl #  struct in6_pktinfo
1236 dnl #
1237 FR_CHECK_STRUCT_HAS_MEMBER([#include <netinet/in.h>], [struct in6_pktinfo], ipi6_addr)
1238 if test "x$ac_cv_type_struct_in6_pktinfo_has_ipi6_addr" = "xyes"; then
1239   AC_DEFINE(HAVE_IN6_PKTINFO, [], [define if you have IN6_PKTINFO (Linux)])
1240 fi
1241
1242 dnl #############################################################
1243 dnl #
1244 dnl #  6. Checks for compiler characteristics
1245 dnl #
1246 dnl #############################################################
1247
1248 dnl #
1249 dnl #  Ensure that these are defined
1250 dnl #
1251 AC_C_CONST
1252
1253 dnl #
1254 dnl #  See if this is OS/2
1255 dnl #
1256 AC_MSG_CHECKING([type of OS])
1257 OS=`uname -s`
1258 AC_MSG_RESULT($OS)
1259 if test "$OS" = "OS/2"; then
1260   LIBPREFIX=
1261 else
1262   LIBPREFIX=lib
1263 fi
1264 AC_SUBST(LIBPREFIX)
1265
1266 if test "x$developer" = "xyes"; then
1267   AC_MSG_NOTICE([Setting additional developer CFLAGS])
1268
1269   dnl #
1270   dnl #  Tell the compiler to parse doxygen documentation and verify it against function and variable declarations
1271   dnl #
1272   AX_CC_WDOCUMENTATION_FLAG
1273   if test "x$ax_cv_cc_wdocumentation_flag" = "xyes"; then
1274     devflags="-Wdocumentation"
1275   fi
1276
1277   if test "x$GCC" = "xyes"; then
1278     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"
1279     INSTALLSTRIP=""
1280   fi
1281
1282   AC_MSG_NOTICE([Developer CFLAGS are "$devflags"])
1283
1284   CFLAGS="$CFLAGS $devflags"
1285   dnl #
1286   dnl #  Enable experimental modules (we want to know if code changes breaks one of them)
1287   dnl #
1288   if test "x$EXPERIMENTAL" != "xno"; then
1289     AC_MSG_NOTICE([is developer build, enabling experimental modules implicitly, disable with --without-experimental-modules])
1290     EXPERIMENTAL=yes
1291   fi
1292 else
1293   devflags=""
1294   CFLAGS="$CFLAGS -DNDEBUG"
1295   INSTALLSTRIP=""
1296 fi
1297
1298 dnl #
1299 dnl #  May of been set outside of this configure script
1300 dnl #
1301 AC_MSG_CHECKING([if building with -DNDEBUG])
1302 if echo "$CFLAGS" | grep '\-DNDEBUG' > /dev/null; then
1303   AC_MSG_RESULT([yes])
1304   AC_DEFINE([WITH_NDEBUG], [1], [define if the server was built with -DNDEBUG])
1305 else
1306   AC_MSG_RESULT([no])
1307 fi
1308
1309 export EXPERIMENTAL
1310
1311 dnl #
1312 dnl #  append the current git hash onto the version string
1313 dnl #
1314 if test -d $srcdir/.git -a "x$GIT" = "xyes"; then
1315   RADIUSD_VERSION_COMMIT=`git log --pretty=format:'%h' -n 1`
1316   AC_DEFINE_UNQUOTED([RADIUSD_VERSION_COMMIT],[${RADIUSD_VERSION_COMMIT}],[Commit HEAD at time of configuring])
1317 fi
1318
1319 FR_TLS
1320
1321 dnl #############################################################
1322 dnl #
1323 dnl #  7. Checks for library functions
1324 dnl #
1325 dnl #############################################################
1326
1327 dnl Check for talloc
1328 dnl extra argument: --with-talloc-include-dir=DIR
1329 talloc_include_dir=
1330 AC_ARG_WITH(talloc-include-dir,
1331   [  --with-talloc-include-dir=DIR    directory to look for talloc include files in],
1332   [case "$withval" in
1333     no)
1334       AC_MSG_ERROR([Need talloc-include-dir])
1335       ;;
1336     yes)
1337       ;;
1338     *)
1339       talloc_include_dir="$withval"
1340       ;;
1341   esac])
1342
1343 dnl Check for talloc
1344 dnl extra argument: --with-talloc-lib-dir=DIR
1345 talloc_lib_dir=
1346 AC_ARG_WITH(talloc-lib-dir,
1347   [  --with-talloc-lib-dir=DIR        directory to look for talloc library files in],
1348   [case "$withval" in
1349     no)
1350       AC_MSG_ERROR([Need talloc-lib-dir])
1351       ;;
1352     yes)
1353       ;;
1354     *)
1355       talloc_lib_dir="$withval"
1356       ;;
1357   esac])
1358
1359 dnl Check for pcap
1360 dnl extra argument: --with-pcap-include-dir=DIR
1361 pcap_include_dir=
1362 AC_ARG_WITH(pcap-include-dir,
1363   [  --with-pcap-include-dir=DIR    directory to look for pcap include files in],
1364   [case "$withval" in
1365     no)
1366       AC_MSG_ERROR([Need pcap-include-dir])
1367       ;;
1368     yes)
1369       ;;
1370     *)
1371       pcap_include_dir="$withval"
1372       ;;
1373   esac])
1374
1375 dnl Check for pcap
1376 dnl extra argument: --with-pcap-lib-dir=DIR
1377 pcap_lib_dir=
1378 AC_ARG_WITH(pcap-lib-dir,
1379   [  --with-pcap-lib-dir=DIR        directory to look for pcap library files in],
1380   [case "$withval" in
1381     no)
1382       AC_MSG_ERROR([Need pcap-lib-dir])
1383       ;;
1384     yes)
1385       ;;
1386     *)
1387       pcap_lib_dir="$withval"
1388       ;;
1389   esac])
1390
1391 dnl #
1392 dnl # Check for talloc header files
1393 dnl #
1394 smart_try_dir="$talloc_include_dir"
1395 FR_SMART_CHECK_INCLUDE([talloc.h])
1396 if test "x$ac_cv_header_talloc_h" != "xyes"; then
1397   AC_MSG_WARN([talloc headers not found. Use --with-talloc-include-dir=<path>.])
1398   AC_MSG_ERROR([FreeRADIUS requires libtalloc])
1399 fi
1400
1401 smart_try_dir="$talloc_lib_dir"
1402 FR_SMART_CHECK_LIB(talloc, _talloc)
1403 if test "x$ac_cv_lib_talloc__talloc" != "xyes"; then
1404   AC_MSG_WARN([talloc library not found. Use --with-talloc-lib-dir=<path>.])
1405   AC_MSG_ERROR([FreeRADIUS requires libtalloc])
1406 fi
1407
1408 dnl #
1409 dnl # Check for libcrypt
1410 dnl # We use crypt(3) which may be in libc, or in libcrypt (eg FreeBSD)
1411 dnl #
1412 AC_CHECK_LIB(crypt, crypt,
1413   CRYPTLIB="-lcrypt"
1414 )
1415
1416 if test "$CRYPTLIB" != ""; then
1417   AC_DEFINE(HAVE_CRYPT, [], [Do we have the crypt function])
1418 else
1419   AC_CHECK_FUNC(crypt, AC_DEFINE(HAVE_CRYPT, [], [Do we have the crypt function]))
1420 fi
1421
1422 dnl Check for libcipher
1423 AC_CHECK_LIB(cipher, setkey,
1424    CRYPTLIB="${CRYPTLIB} -lcipher"
1425 )
1426 AC_SUBST(CRYPTLIB)
1427
1428
1429 dnl #
1430 dnl #  Check for regular expression support, if were using PCRE it MUST be included
1431 dnl #  before all others, else we seem to still pickup the posix symbols for regcomp
1432 dnl #  and regexec, which results in crashes as soon as we call any posix regex
1433 dnl #  functions.
1434 dnl #
1435 dnl extra argument: --with-pcre-lib-dir
1436 pcre_lib_dir=
1437 AC_ARG_WITH(rlm-pcre-lib-dir,
1438 [  --with-pcre-lib-dir=DIR          directory to look for PCRE library files in],
1439 [ case "$withval" in
1440     no)
1441         AC_MSG_ERROR(Need rlm-pcre-lib-dir)
1442         ;;
1443     yes)
1444         ;;
1445     *)
1446         pcre_lib_dir="$withval"
1447         ;;
1448   esac ]
1449 )
1450
1451 dnl extra argument: --with-pcre-include--dir
1452 pcre_include_dir=
1453 AC_ARG_WITH(rlm-pcre-include-dir,
1454 [  --with-pcre-include-dir=DIR      directory to look for PCRE include files in],
1455 [ case "$withval" in
1456     no)
1457         AC_MSG_ERROR(Need rlm-pcre-include-dir)
1458         ;;
1459     yes)
1460         ;;
1461     *)
1462         pcre_include_dir="$withval"
1463         ;;
1464   esac ]
1465 )
1466
1467 REGEX=no
1468 REGEX_EXTENDED=no
1469 REGEX_PCRE=no
1470
1471 dnl #
1472 dnl #  First look for PCRE
1473 dnl #
1474 smart_try_dir=$pcre_include_dir
1475 FR_SMART_CHECK_INCLUDE(pcreposix.h)
1476 if test "x$ac_cv_header_pcreposix_h" = "xyes"; then
1477   AC_DEFINE(HAVE_REGEX_H, [1], [define if we have any regex])
1478   AC_DEFINE(HAVE_PCREPOSIX_H, [1], [define this if we have the <pcreposix.h> header file])
1479   REGEX=yes
1480   REGEX_EXTENDED=yes
1481   REGEX_PCRE=yes
1482   LIBS="-lpcre -lpcreposix $LIBS"
1483
1484 dnl #
1485 dnl #  Then fallback to POSIX regular expressions
1486 dnl #
1487 else
1488   smart_try_dir=
1489   FR_SMART_CHECK_INCLUDE(regex.h)
1490   if test "x$ac_cv_header_regex_h" = "xyes"; then
1491     AC_DEFINE(HAVE_REGEX_H, [1], [define if we have any regex])
1492     REGEX=yes
1493     AC_EGREP_CPP(yes,
1494       [
1495         #include <regex.h>
1496         #ifdef REG_EXTENDED
1497         yes
1498         #endif
1499        ],
1500     [AC_DEFINE(HAVE_REG_EXTENDED, [1], [define this if we have REG_EXTENDED (from <regex.h>)]) REGEX_EXTENDED=yes]
1501     )
1502 dnl #
1503 dnl # Fixme, this is needed for mingw builds, but not available on some Linux systems
1504 dnl # despite the presence of regex.h
1505 dnl #
1506 dnl # LIBS="$LIBS -lregex"
1507   fi
1508 fi
1509
1510 AC_SUBST(REGEX)
1511 AC_SUBST(REGEX_PCRE)
1512 AC_SUBST(REGEX_EXTENDED)
1513
1514 dnl #
1515 dnl #  Check the style of gethostbyaddr, in order of preference
1516 dnl #  GNU (_r eight args)
1517 dnl #
1518 AC_DEFINE(GNUSTYLE, [1], [GNU-Style get*byaddr_r])
1519
1520 dnl #
1521 dnl #  SYSV (_r six args)
1522 dnl #
1523 AC_DEFINE(SYSVSTYLE, [2], [SYSV-Style get*byaddr_r])
1524
1525 dnl #
1526 dnl #  BSD (three args, may not be thread safe)
1527 dnl #
1528 AC_DEFINE(BSDSTYLE, [3], [BSD-Style get*byaddr_r])
1529
1530 dnl #
1531 dnl #  Tru64 has BSD version, but it is thread safe
1532 dnl #  http://h30097.www3.hp.com/docs/base_doc/DOCUMENTATION/V51B_HTML/MAN/MAN3/1739____.HTM
1533 dnl #  We need #stdio.h to define NULL on FreeBSD (at least)
1534 dnl #
1535 gethostbyaddrrstyle=""
1536 AC_MSG_CHECKING([gethostbyaddr_r() syntax])
1537 case "$host" in
1538   *-freebsd*)
1539     dnl #
1540     dnl #  With FreeBSD, check if there's a prototype for gethostbyaddr_r.
1541     dnl #  Some versions (FreeBSD 5.1?) have a symbol but no prototype - so we
1542     dnl #  override this test to BSDSTYLE. FreeBSD 6.2 and up have proper GNU
1543     dnl #  style support.
1544     dnl #
1545     AC_CHECK_DECLS([gethostbyaddr_r], [],
1546       [
1547         AC_DEFINE(GETHOSTBYADDRRSTYLE, BSDSTYLE,
1548           [style of gethostbyaddr_r functions ])
1549         gethostbyaddrrstyle=BSD
1550         AC_MSG_WARN([FreeBSD overridden to BSD-style])
1551       ],
1552       [
1553         #ifdef HAVE_NETDB_H
1554         #include <netdb.h>
1555         #endif
1556       ])
1557     ;;
1558 esac
1559
1560 if test "x$gethostbyaddrrstyle" = "x"; then
1561   AC_TRY_LINK(
1562     [
1563       #include <stdio.h>
1564       #include <netdb.h>
1565     ],
1566     [ gethostbyaddr_r(NULL, 0, 0, NULL, NULL, 0, NULL, NULL) ],
1567     [
1568       AC_DEFINE(GETHOSTBYADDRRSTYLE, GNUSTYLE, [style of gethostbyaddr_r functions ])
1569       gethostbyaddrrstyle=GNU
1570     ]
1571   )
1572 fi
1573
1574 if test "x$gethostbyaddrrstyle" = "x"; then
1575   AC_TRY_LINK(
1576     [
1577       #include <stdio.h>
1578       #include <netdb.h>
1579     ],
1580     [ gethostbyaddr_r(NULL, 0, 0, NULL, NULL, 0, NULL) ] ,
1581     [
1582       AC_DEFINE(GETHOSTBYADDRRSTYLE, SYSVSTYLE, [style of gethostbyaddr_r functions ])
1583       gethostbyaddrrstyle=SYSV
1584     ]
1585   )
1586 fi
1587
1588
1589 if test "x$gethostbyaddrrstyle" = "x"; then
1590   AC_TRY_LINK(
1591     [
1592       #include <stdio.h>
1593       #include <netdb.h>
1594     ],
1595     [ gethostbyaddr(NULL, 0, 0)  ],
1596     [
1597       AC_DEFINE(GETHOSTBYADDRRSTYLE, BSDSTYLE, [style of gethostbyaddr_r functions ])
1598       gethostbyaddrrstyle=BSD
1599     ]
1600   )
1601 fi
1602
1603 if test "x$gethostbyaddrrstyle" = "x"; then
1604   AC_MSG_RESULT([none!  It must not exist, here.])
1605 else
1606   AC_MSG_RESULT([${gethostbyaddrrstyle}-style])
1607 fi
1608
1609 if test "x$gethostbyaddrrstyle" = "xBSD"; then
1610   AC_MSG_WARN([ ****** BSD-style gethostbyaddr might NOT be thread-safe! ****** ])
1611 fi
1612
1613 dnl #
1614 dnl #  Check the style of gethostbyname, in order of preference
1615 dnl #  GNU (_r seven args)
1616 dnl #  SYSV (_r five args)
1617 dnl #  BSD (two args, may not be thread safe)
1618 dnl #  Tru64 has BSD version, but it _is_ thread safe
1619 dnl #    http://h30097.www3.hp.com/docs/base_doc/DOCUMENTATION/V51B_HTML/MAN/MAN3/1946____.HTM
1620 dnl #  We need #stdio.h to define NULL on FreeBSD (at least)
1621 dnl #
1622 gethostbynamerstyle=""
1623 AC_MSG_CHECKING([gethostbyname_r() syntax])
1624 AC_TRY_LINK(
1625   [
1626     #include <stdio.h>
1627     #include <netdb.h>
1628   ],
1629   [ gethostbyname_r(NULL, NULL, NULL, 0, NULL, NULL) ],
1630   [
1631     AC_DEFINE(GETHOSTBYNAMERSTYLE, GNUSTYLE, [style of gethostbyname_r functions ])
1632     gethostbynamerstyle=GNU
1633   ]
1634 )
1635
1636 if test "x$gethostbynamerstyle" = "x"; then
1637   AC_TRY_LINK(
1638     [
1639       #include <stdio.h>
1640       #include <netdb.h>
1641     ],
1642     [ gethostbyname_r(NULL, NULL, NULL, 0, NULL) ] ,
1643     [
1644       AC_DEFINE(GETHOSTBYNAMERSTYLE, SYSVSTYLE, [style of gethostbyname_r functions ])
1645       gethostbynamerstyle=SYSV
1646     ]
1647   )
1648 fi
1649
1650 if test "x$gethostbynamerstyle" = "x"; then
1651   AC_TRY_LINK(
1652     [
1653       #include <stdio.h>
1654       #include <netdb.h>
1655     ],
1656     [ gethostbyname(NULL) ],
1657     [
1658       AC_DEFINE(GETHOSTBYNAMERSTYLE, BSDSTYLE, [style of gethostbyname_r functions ])
1659       gethostbynamerstyle=BSD
1660     ]
1661   )
1662 fi
1663
1664 if test "x$gethostbynamerstyle" = "x"; then
1665   AC_MSG_RESULT([none!  It must not exist, here.])
1666 else
1667   AC_MSG_RESULT([${gethostbynamerstyle}-style])
1668 fi
1669
1670 if test "x$gethostbynamerstyle" = "xBSD"; then
1671   AC_MSG_WARN([ ****** BSD-style gethostbyname might NOT be thread-safe! ****** ])
1672 fi
1673
1674 dnl #
1675 dnl #  Check for non-posix solaris ctime_r (extra buflen int arg)
1676 dnl #
1677 AC_DEFINE(POSIXSTYLE, [1], [Posix-Style ctime_r])
1678 AC_DEFINE(SOLARISSTYLE, [2], [Solaris-Style ctime_r])
1679 ctimerstyle=""
1680 AC_MSG_CHECKING([ctime_r() syntax])
1681 AC_TRY_LINK(
1682   [
1683     #include <time.h>
1684   ],
1685   [ ctime_r(NULL, NULL, 0) ],
1686   [
1687     AC_DEFINE(CTIMERSTYLE, SOLARISSTYLE, [style of ctime_r function])
1688     ctimerstyle="SOLARIS"
1689   ]
1690 )
1691
1692 if test "x$ctimerstyle" = "x"; then
1693   AC_TRY_LINK(
1694     [
1695       #include <time.h>
1696     ],
1697     [ ctime_r(NULL, NULL) ],
1698     [
1699       AC_DEFINE(CTIMERSTYLE, POSIXSTYLE, [style of ctime_r function])
1700       ctimerstyle="POSIX"
1701     ]
1702   )
1703 fi
1704
1705 if test "x$ctimerstyle" = "x"; then
1706     AC_MSG_RESULT([none!  It must not exist, here.])
1707 else
1708     AC_MSG_RESULT([${ctimerstyle}-style])
1709 fi
1710
1711 AC_SUBST(HOSTINFO, $host)
1712
1713 dnl #############################################################
1714 dnl #
1715 dnl #  8. Checks for system services
1716 dnl #
1717 dnl #############################################################
1718
1719 dnl #
1720 dnl #  Figure out where libtool is located,
1721 dnl #
1722 top_builddir=`pwd`
1723 export top_builddir
1724 AC_MSG_RESULT([top_builddir=$top_builddir])
1725 dnl #  AC_SUBST(top_builddir)
1726
1727 dnl #
1728 dnl #  import libtool stuff
1729 dnl #
1730 dnl #############################################################
1731 dnl #
1732 dnl #  Configure in any module directories.
1733 dnl #
1734 dnl #############################################################
1735
1736 dnl ############################################################
1737 dnl #  Remove any conflicting definitions if autoconf.h
1738 dnl #  is being included by a module.
1739 dnl #############################################################
1740 AH_BOTTOM([#include <freeradius-devel/automask.h>])
1741
1742 dnl ############################################################
1743 dnl #  make modules by list
1744 dnl #############################################################
1745 if test "x$EXPERIMENTAL" = "xyes"; then
1746   for foo in `ls -1 "${srcdir}"/src/modules | grep rlm_`; do
1747     MODULES="$MODULES $foo"
1748   done
1749 else
1750    dnl #
1751    dnl #  make ONLY the stable modules
1752    dnl #
1753    for foo in `cat "${srcdir}"/src/modules/stable`; do
1754       MODULES="$MODULES $foo"
1755    done
1756 fi
1757
1758 dnl ############################################################
1759 dnl #  Add autoconf subdirs, based on the module list we
1760 dnl #  previously created.
1761 dnl #############################################################
1762 mysubdirs=""
1763 for bar in $MODULES; do
1764   if test -f "${srcdir}"/src/modules/$bar/configure; then
1765     mysubdirs="$mysubdirs src/modules/$bar"
1766   fi
1767 done
1768
1769 dnl #
1770 dnl #  Don't change the variable name here.  Autoconf goes bonkers
1771 dnl #  if you do.
1772 dnl #
1773 AC_CONFIG_SUBDIRS($mysubdirs)
1774 AC_SUBST(MODULES)
1775
1776 dnl #############################################################
1777 dnl #
1778 dnl #  Add -Werror last, so it doesn't interfere with autoconf's
1779 dnl #  test programs.
1780 dnl #
1781 dnl #############################################################
1782 if test "x$werror" == "xyes"; then
1783   CFLAGS="-Werror $CFLAGS"
1784 fi
1785
1786 dnl #############################################################
1787 dnl #
1788 dnl #  And finally, output the results.
1789 dnl #
1790 dnl #############################################################
1791 AC_CONFIG_COMMANDS([stamp-h], [echo timestamp > src/include/stamp-h])
1792 AC_CONFIG_COMMANDS([build-radpaths-h], [(cd ./src/include && /bin/sh ./build-radpaths-h)])
1793 AC_CONFIG_COMMANDS([main-chmod], [(cd ./src/main && chmod +x checkrad radlast radtest)])
1794 AC_CONFIG_COMMANDS([scripts-chmod], [(cd ./scripts && chmod +x rc.radiusd cron/radiusd.cron.daily cron/radiusd.cron.monthly cryptpasswd)])
1795
1796 dnl #
1797 dnl #  Substitute whatever libraries we found to be necessary
1798 dnl #
1799 AC_SUBST(LIBS)
1800 AC_SUBST(INSTALLSTRIP)
1801
1802 AC_SUBST(USE_SHARED_LIBS)
1803 USE_STATIC_LIBS="yes"
1804 AC_SUBST(USE_STATIC_LIBS)
1805 AC_SUBST(STATIC_MODULES)
1806
1807 AC_OUTPUT(\
1808   ./Make.inc \
1809   ./src/include/build-radpaths-h \
1810   ./src/main/radsniff.mk \
1811   ./src/main/checkrad \
1812   ./src/main/radlast \
1813   ./src/main/radtest \
1814   ./scripts/rc.radiusd \
1815   ./scripts/cron/radiusd.cron.daily \
1816   ./scripts/cron/radiusd.cron.monthly \
1817   ./scripts/cryptpasswd \
1818   ./raddb/radrelay.conf \
1819   ./raddb/radiusd.conf
1820 )