Revert "Configure rules to look for <endian.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(BIGENDIAN, 1, [Define if your processor stores words with the most significant byte first])],
210   [AC_DEFINE(LITTLEENDIAN, 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 dnl #
1102 dnl #  Check for __uint128_t (compiler builtin)
1103 dnl #
1104 AC_CHECK_TYPE(__uint128_t, AC_DEFINE(HAVE___UINT128_T, 1, [compiler specific 128 bit unsigned integer]), [], [])
1105
1106 dnl #
1107 dnl #  Check for uint128_t (fictitious future data type)
1108 dnl #
1109 AC_CHECK_TYPE(uint128_t, AC_DEFINE(HAVE_UINT128_T, 1, [128 bit unsigned integer]), [],
1110   [
1111     #ifdef HAVE_INTTYPES_H
1112     #  include <inttypes.h>
1113     #endif
1114
1115     #ifdef HAVE_STDINT_H
1116     #  include <stdint.h>
1117     #endif
1118   ]
1119 )
1120
1121 AC_CHECK_TYPE(struct in6_addr, AC_DEFINE(HAVE_STRUCT_IN6_ADDR, 1, [IPv6 address structure]), [],
1122   [
1123     #ifdef HAVE_NETINET_IN_H
1124     #  include <netinet/in.h>
1125     #endif
1126   ]
1127 )
1128
1129 AC_CHECK_TYPE(struct sockaddr_storage, AC_DEFINE(HAVE_STRUCT_SOCKADDR_STORAGE, 1, [Generic socket addresses]), [],
1130   [
1131     #ifdef HAVE_NETINET_IN_H
1132     #  include <netinet/in.h>
1133     #endif
1134
1135     #ifdef HAVE_SYS_SOCKET_H
1136     #  include <sys/socket.h>
1137     #endif
1138 ])
1139
1140 AC_CHECK_TYPE(struct sockaddr_in6, AC_DEFINE(HAVE_STRUCT_SOCKADDR_IN6, 1, [IPv6 socket addresses]), [],
1141   [
1142     #ifdef HAVE_NETINET_IN_H
1143     #  include <netinet/in.h>
1144     #endif
1145 ])
1146
1147 AC_CHECK_TYPE(struct addrinfo, AC_DEFINE(HAVE_STRUCT_ADDRINFO, 1, [Generic DNS lookups]), [],
1148   [
1149     #ifdef HAVE_SYS_TYPES_H
1150     #  include <sys/types.h>
1151     #endif
1152
1153     #ifdef HAVE_SYS_SOCKET_H
1154     #  include <sys/socket.h>
1155     #endif
1156
1157     #ifdef HAVE_NETDB_H
1158     #  include <netdb.h>
1159     #endif
1160   ]
1161 )
1162
1163 dnl #############################################################
1164 dnl #
1165 dnl #  5. Checks for structures and functions
1166 dnl #
1167 dnl #############################################################
1168 AC_CHECK_FUNCS( \
1169   getopt_long \
1170   fcntl \
1171   strsignal \
1172   sigaction \
1173   sigprocmask \
1174   pthread_sigmask \
1175   snprintf \
1176   vsnprintf \
1177   setsid \
1178   strncasecmp \
1179   strcasecmp \
1180   localtime_r \
1181   ctime_r \
1182   gmtime_r \
1183   strsep \
1184   inet_aton \
1185   inet_pton \
1186   inet_ntop \
1187   setlinebuf \
1188   setvbuf \
1189   getusershell \
1190   initgroups \
1191   getaddrinfo \
1192   getnameinfo \
1193   closefrom \
1194   gettimeofday \
1195   getpeereid \
1196   setuid \
1197   setresuid \
1198   getresuid \
1199   strlcat \
1200   strlcpy
1201 )
1202
1203 AC_TYPE_SIGNAL
1204
1205 dnl #
1206 dnl #  Check if we have utmpx.h
1207 dnl #  if so, check if struct utmpx has entry ut_xtime
1208 dnl #  if not, set it to define ut_xtime == ut_tv.tv_sec
1209 dnl #
1210 if test "x$ac_cv_header_utmpx_h" = "xyes"; then
1211  FR_CHECK_STRUCT_HAS_MEMBER([#include <utmpx.h>], [struct utmpx], ut_xtime)
1212  if test "x$ac_cv_type_struct_utmpx_has_ut_xtime" = "x"; then
1213    AC_DEFINE(ut_xtime, ut_tv.tv_sec, [define to something if you don't have ut_xtime in struct utmpx])
1214  fi
1215 fi
1216
1217 dnl #
1218 dnl #  struct ip_pktinfo
1219 dnl #
1220 FR_CHECK_STRUCT_HAS_MEMBER([#include <netinet/in.h>], [struct in_pktinfo], ipi_addr)
1221 if test "x$ac_cv_type_struct_in_pktinfo_has_ipi_addr" = "xyes"; then
1222   AC_DEFINE(HAVE_IP_PKTINFO, [], [define if you have IP_PKTINFO (Linux)])
1223 fi
1224
1225 dnl #
1226 dnl #  struct in6_pktinfo
1227 dnl #
1228 FR_CHECK_STRUCT_HAS_MEMBER([#include <netinet/in.h>], [struct in6_pktinfo], ipi6_addr)
1229 if test "x$ac_cv_type_struct_in6_pktinfo_has_ipi6_addr" = "xyes"; then
1230   AC_DEFINE(HAVE_IN6_PKTINFO, [], [define if you have IN6_PKTINFO (Linux)])
1231 fi
1232
1233 dnl #############################################################
1234 dnl #
1235 dnl #  6. Checks for compiler characteristics
1236 dnl #
1237 dnl #############################################################
1238
1239 dnl #
1240 dnl #  Ensure that these are defined
1241 dnl #
1242 AC_C_CONST
1243
1244 dnl #
1245 dnl #  See if this is OS/2
1246 dnl #
1247 AC_MSG_CHECKING([type of OS])
1248 OS=`uname -s`
1249 AC_MSG_RESULT($OS)
1250 if test "$OS" = "OS/2"; then
1251   LIBPREFIX=
1252 else
1253   LIBPREFIX=lib
1254 fi
1255 AC_SUBST(LIBPREFIX)
1256
1257 if test "x$developer" = "xyes"; then
1258   AC_MSG_NOTICE([Setting additional developer CFLAGS])
1259
1260   dnl #
1261   dnl #  Tell the compiler to parse doxygen documentation and verify it against function and variable declarations
1262   dnl #
1263   AX_CC_WDOCUMENTATION_FLAG
1264   if test "x$ax_cv_cc_wdocumentation_flag" = "xyes"; then
1265     devflags="-Wdocumentation"
1266   fi
1267
1268   if test "x$GCC" = "xyes"; then
1269     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"
1270     INSTALLSTRIP=""
1271   fi
1272
1273   AC_MSG_NOTICE([Developer CFLAGS are "$devflags"])
1274
1275   CFLAGS="$CFLAGS $devflags"
1276   dnl #
1277   dnl #  Enable experimental modules (we want to know if code changes breaks one of them)
1278   dnl #
1279   if test "x$EXPERIMENTAL" != "xno"; then
1280     AC_MSG_NOTICE([is developer build, enabling experimental modules implicitly, disable with --without-experimental-modules])
1281     EXPERIMENTAL=yes
1282   fi
1283 else
1284   devflags=""
1285   CFLAGS="$CFLAGS -DNDEBUG"
1286   INSTALLSTRIP=""
1287 fi
1288
1289 dnl #
1290 dnl #  May of been set outside of this configure script
1291 dnl #
1292 AC_MSG_CHECKING([if building with -DNDEBUG])
1293 if echo "$CFLAGS" | grep '\-DNDEBUG' > /dev/null; then
1294   AC_MSG_RESULT([yes])
1295   AC_DEFINE([WITH_NDEBUG], [1], [define if the server was built with -DNDEBUG])
1296 else
1297   AC_MSG_RESULT([no])
1298 fi
1299
1300 export EXPERIMENTAL
1301
1302 dnl #
1303 dnl #  append the current git hash onto the version string
1304 dnl #
1305 if test -d $srcdir/.git -a "x$GIT" = "xyes"; then
1306   RADIUSD_VERSION_COMMIT=`git log --pretty=format:'%h' -n 1`
1307   AC_DEFINE_UNQUOTED([RADIUSD_VERSION_COMMIT],[${RADIUSD_VERSION_COMMIT}],[Commit HEAD at time of configuring])
1308 fi
1309
1310 FR_TLS
1311
1312 dnl #############################################################
1313 dnl #
1314 dnl #  7. Checks for library functions
1315 dnl #
1316 dnl #############################################################
1317
1318 dnl Check for talloc
1319 dnl extra argument: --with-talloc-include-dir=DIR
1320 talloc_include_dir=
1321 AC_ARG_WITH(talloc-include-dir,
1322   [  --with-talloc-include-dir=DIR    directory to look for talloc include files in],
1323   [case "$withval" in
1324     no)
1325       AC_MSG_ERROR([Need talloc-include-dir])
1326       ;;
1327     yes)
1328       ;;
1329     *)
1330       talloc_include_dir="$withval"
1331       ;;
1332   esac])
1333
1334 dnl Check for talloc
1335 dnl extra argument: --with-talloc-lib-dir=DIR
1336 talloc_lib_dir=
1337 AC_ARG_WITH(talloc-lib-dir,
1338   [  --with-talloc-lib-dir=DIR        directory to look for talloc library files in],
1339   [case "$withval" in
1340     no)
1341       AC_MSG_ERROR([Need talloc-lib-dir])
1342       ;;
1343     yes)
1344       ;;
1345     *)
1346       talloc_lib_dir="$withval"
1347       ;;
1348   esac])
1349
1350 dnl Check for pcap
1351 dnl extra argument: --with-pcap-include-dir=DIR
1352 pcap_include_dir=
1353 AC_ARG_WITH(pcap-include-dir,
1354   [  --with-pcap-include-dir=DIR    directory to look for pcap include files in],
1355   [case "$withval" in
1356     no)
1357       AC_MSG_ERROR([Need pcap-include-dir])
1358       ;;
1359     yes)
1360       ;;
1361     *)
1362       pcap_include_dir="$withval"
1363       ;;
1364   esac])
1365
1366 dnl Check for pcap
1367 dnl extra argument: --with-pcap-lib-dir=DIR
1368 pcap_lib_dir=
1369 AC_ARG_WITH(pcap-lib-dir,
1370   [  --with-pcap-lib-dir=DIR        directory to look for pcap library files in],
1371   [case "$withval" in
1372     no)
1373       AC_MSG_ERROR([Need pcap-lib-dir])
1374       ;;
1375     yes)
1376       ;;
1377     *)
1378       pcap_lib_dir="$withval"
1379       ;;
1380   esac])
1381
1382 dnl #
1383 dnl # Check for talloc header files
1384 dnl #
1385 smart_try_dir="$talloc_include_dir"
1386 FR_SMART_CHECK_INCLUDE([talloc.h])
1387 if test "x$ac_cv_header_talloc_h" != "xyes"; then
1388   AC_MSG_WARN([talloc headers not found. Use --with-talloc-include-dir=<path>.])
1389   AC_MSG_ERROR([FreeRADIUS requires libtalloc])
1390 fi
1391
1392 smart_try_dir="$talloc_lib_dir"
1393 FR_SMART_CHECK_LIB(talloc, _talloc)
1394 if test "x$ac_cv_lib_talloc__talloc" != "xyes"; then
1395   AC_MSG_WARN([talloc library not found. Use --with-talloc-lib-dir=<path>.])
1396   AC_MSG_ERROR([FreeRADIUS requires libtalloc])
1397 fi
1398
1399 dnl #
1400 dnl # Check for libcrypt
1401 dnl # We use crypt(3) which may be in libc, or in libcrypt (eg FreeBSD)
1402 dnl #
1403 AC_CHECK_LIB(crypt, crypt,
1404   CRYPTLIB="-lcrypt"
1405 )
1406
1407 if test "$CRYPTLIB" != ""; then
1408   AC_DEFINE(HAVE_CRYPT, [], [Do we have the crypt function])
1409 else
1410   AC_CHECK_FUNC(crypt, AC_DEFINE(HAVE_CRYPT, [], [Do we have the crypt function]))
1411 fi
1412
1413 dnl Check for libcipher
1414 AC_CHECK_LIB(cipher, setkey,
1415    CRYPTLIB="${CRYPTLIB} -lcipher"
1416 )
1417 AC_SUBST(CRYPTLIB)
1418
1419
1420 dnl #
1421 dnl #  Check for regular expression support, if were using PCRE it MUST be included
1422 dnl #  before all others, else we seem to still pickup the posix symbols for regcomp
1423 dnl #  and regexec, which results in crashes as soon as we call any posix regex
1424 dnl #  functions.
1425 dnl #
1426 dnl extra argument: --with-pcre-lib-dir
1427 pcre_lib_dir=
1428 AC_ARG_WITH(rlm-pcre-lib-dir,
1429 [  --with-pcre-lib-dir=DIR          directory to look for PCRE library files in],
1430 [ case "$withval" in
1431     no)
1432         AC_MSG_ERROR(Need rlm-pcre-lib-dir)
1433         ;;
1434     yes)
1435         ;;
1436     *)
1437         pcre_lib_dir="$withval"
1438         ;;
1439   esac ]
1440 )
1441
1442 dnl extra argument: --with-pcre-include--dir
1443 pcre_include_dir=
1444 AC_ARG_WITH(rlm-pcre-include-dir,
1445 [  --with-pcre-include-dir=DIR      directory to look for PCRE include files in],
1446 [ case "$withval" in
1447     no)
1448         AC_MSG_ERROR(Need rlm-pcre-include-dir)
1449         ;;
1450     yes)
1451         ;;
1452     *)
1453         pcre_include_dir="$withval"
1454         ;;
1455   esac ]
1456 )
1457
1458 REGEX=no
1459 REGEX_EXTENDED=no
1460 REGEX_PCRE=no
1461
1462 dnl #
1463 dnl #  First look for PCRE
1464 dnl #
1465 smart_try_dir=$pcre_include_dir
1466 FR_SMART_CHECK_INCLUDE(pcreposix.h)
1467 if test "x$ac_cv_header_pcreposix_h" = "xyes"; then
1468   AC_DEFINE(HAVE_REGEX_H, [1], [define if we have any regex])
1469   AC_DEFINE(HAVE_PCREPOSIX_H, [1], [define this if we have the <pcreposix.h> header file])
1470   REGEX=yes
1471   REGEX_EXTENDED=yes
1472   REGEX_PCRE=yes
1473   LIBS="-lpcre -lpcreposix $LIBS"
1474
1475 dnl #
1476 dnl #  Then fallback to POSIX regular expressions
1477 dnl #
1478 else
1479   smart_try_dir=
1480   FR_SMART_CHECK_INCLUDE(regex.h)
1481   if test "x$ac_cv_header_regex_h" = "xyes"; then
1482     AC_DEFINE(HAVE_REGEX_H, [1], [define if we have any regex])
1483     REGEX=yes
1484     AC_EGREP_CPP(yes,
1485       [
1486         #include <regex.h>
1487         #ifdef REG_EXTENDED
1488         yes
1489         #endif
1490        ],
1491     [AC_DEFINE(HAVE_REG_EXTENDED, [1], [define this if we have REG_EXTENDED (from <regex.h>)]) REGEX_EXTENDED=yes]
1492     )
1493 dnl #
1494 dnl # Fixme, this is needed for mingw builds, but not available on some Linux systems
1495 dnl # despite the presence of regex.h
1496 dnl #
1497 dnl # LIBS="$LIBS -lregex"
1498   fi
1499 fi
1500
1501 AC_SUBST(REGEX)
1502 AC_SUBST(REGEX_PCRE)
1503 AC_SUBST(REGEX_EXTENDED)
1504
1505 dnl #
1506 dnl #  Check the style of gethostbyaddr, in order of preference
1507 dnl #  GNU (_r eight args)
1508 dnl #
1509 AC_DEFINE(GNUSTYLE, [1], [GNU-Style get*byaddr_r])
1510
1511 dnl #
1512 dnl #  SYSV (_r six args)
1513 dnl #
1514 AC_DEFINE(SYSVSTYLE, [2], [SYSV-Style get*byaddr_r])
1515
1516 dnl #
1517 dnl #  BSD (three args, may not be thread safe)
1518 dnl #
1519 AC_DEFINE(BSDSTYLE, [3], [BSD-Style get*byaddr_r])
1520
1521 dnl #
1522 dnl #  Tru64 has BSD version, but it is thread safe
1523 dnl #  http://h30097.www3.hp.com/docs/base_doc/DOCUMENTATION/V51B_HTML/MAN/MAN3/1739____.HTM
1524 dnl #  We need #stdio.h to define NULL on FreeBSD (at least)
1525 dnl #
1526 gethostbyaddrrstyle=""
1527 AC_MSG_CHECKING([gethostbyaddr_r() syntax])
1528 case "$host" in
1529   *-freebsd*)
1530     dnl #
1531     dnl #  With FreeBSD, check if there's a prototype for gethostbyaddr_r.
1532     dnl #  Some versions (FreeBSD 5.1?) have a symbol but no prototype - so we
1533     dnl #  override this test to BSDSTYLE. FreeBSD 6.2 and up have proper GNU
1534     dnl #  style support.
1535     dnl #
1536     AC_CHECK_DECLS([gethostbyaddr_r], [],
1537       [
1538         AC_DEFINE(GETHOSTBYADDRRSTYLE, BSDSTYLE,
1539           [style of gethostbyaddr_r functions ])
1540         gethostbyaddrrstyle=BSD
1541         AC_MSG_WARN([FreeBSD overridden to BSD-style])
1542       ],
1543       [
1544         #ifdef HAVE_NETDB_H
1545         #include <netdb.h>
1546         #endif
1547       ])
1548     ;;
1549 esac
1550
1551 if test "x$gethostbyaddrrstyle" = "x"; then
1552   AC_TRY_LINK(
1553     [
1554       #include <stdio.h>
1555       #include <netdb.h>
1556     ],
1557     [ gethostbyaddr_r(NULL, 0, 0, NULL, NULL, 0, NULL, NULL) ],
1558     [
1559       AC_DEFINE(GETHOSTBYADDRRSTYLE, GNUSTYLE, [style of gethostbyaddr_r functions ])
1560       gethostbyaddrrstyle=GNU
1561     ]
1562   )
1563 fi
1564
1565 if test "x$gethostbyaddrrstyle" = "x"; then
1566   AC_TRY_LINK(
1567     [
1568       #include <stdio.h>
1569       #include <netdb.h>
1570     ],
1571     [ gethostbyaddr_r(NULL, 0, 0, NULL, NULL, 0, NULL) ] ,
1572     [
1573       AC_DEFINE(GETHOSTBYADDRRSTYLE, SYSVSTYLE, [style of gethostbyaddr_r functions ])
1574       gethostbyaddrrstyle=SYSV
1575     ]
1576   )
1577 fi
1578
1579
1580 if test "x$gethostbyaddrrstyle" = "x"; then
1581   AC_TRY_LINK(
1582     [
1583       #include <stdio.h>
1584       #include <netdb.h>
1585     ],
1586     [ gethostbyaddr(NULL, 0, 0)  ],
1587     [
1588       AC_DEFINE(GETHOSTBYADDRRSTYLE, BSDSTYLE, [style of gethostbyaddr_r functions ])
1589       gethostbyaddrrstyle=BSD
1590     ]
1591   )
1592 fi
1593
1594 if test "x$gethostbyaddrrstyle" = "x"; then
1595   AC_MSG_RESULT([none!  It must not exist, here.])
1596 else
1597   AC_MSG_RESULT([${gethostbyaddrrstyle}-style])
1598 fi
1599
1600 if test "x$gethostbyaddrrstyle" = "xBSD"; then
1601   AC_MSG_WARN([ ****** BSD-style gethostbyaddr might NOT be thread-safe! ****** ])
1602 fi
1603
1604 dnl #
1605 dnl #  Check the style of gethostbyname, in order of preference
1606 dnl #  GNU (_r seven args)
1607 dnl #  SYSV (_r five args)
1608 dnl #  BSD (two args, may not be thread safe)
1609 dnl #  Tru64 has BSD version, but it _is_ thread safe
1610 dnl #    http://h30097.www3.hp.com/docs/base_doc/DOCUMENTATION/V51B_HTML/MAN/MAN3/1946____.HTM
1611 dnl #  We need #stdio.h to define NULL on FreeBSD (at least)
1612 dnl #
1613 gethostbynamerstyle=""
1614 AC_MSG_CHECKING([gethostbyname_r() syntax])
1615 AC_TRY_LINK(
1616   [
1617     #include <stdio.h>
1618     #include <netdb.h>
1619   ],
1620   [ gethostbyname_r(NULL, NULL, NULL, 0, NULL, NULL) ],
1621   [
1622     AC_DEFINE(GETHOSTBYNAMERSTYLE, GNUSTYLE, [style of gethostbyname_r functions ])
1623     gethostbynamerstyle=GNU
1624   ]
1625 )
1626
1627 if test "x$gethostbynamerstyle" = "x"; then
1628   AC_TRY_LINK(
1629     [
1630       #include <stdio.h>
1631       #include <netdb.h>
1632     ],
1633     [ gethostbyname_r(NULL, NULL, NULL, 0, NULL) ] ,
1634     [
1635       AC_DEFINE(GETHOSTBYNAMERSTYLE, SYSVSTYLE, [style of gethostbyname_r functions ])
1636       gethostbynamerstyle=SYSV
1637     ]
1638   )
1639 fi
1640
1641 if test "x$gethostbynamerstyle" = "x"; then
1642   AC_TRY_LINK(
1643     [
1644       #include <stdio.h>
1645       #include <netdb.h>
1646     ],
1647     [ gethostbyname(NULL) ],
1648     [
1649       AC_DEFINE(GETHOSTBYNAMERSTYLE, BSDSTYLE, [style of gethostbyname_r functions ])
1650       gethostbynamerstyle=BSD
1651     ]
1652   )
1653 fi
1654
1655 if test "x$gethostbynamerstyle" = "x"; then
1656   AC_MSG_RESULT([none!  It must not exist, here.])
1657 else
1658   AC_MSG_RESULT([${gethostbynamerstyle}-style])
1659 fi
1660
1661 if test "x$gethostbynamerstyle" = "xBSD"; then
1662   AC_MSG_WARN([ ****** BSD-style gethostbyname might NOT be thread-safe! ****** ])
1663 fi
1664
1665 dnl #
1666 dnl #  Check for non-posix solaris ctime_r (extra buflen int arg)
1667 dnl #
1668 AC_DEFINE(POSIXSTYLE, [1], [Posix-Style ctime_r])
1669 AC_DEFINE(SOLARISSTYLE, [2], [Solaris-Style ctime_r])
1670 ctimerstyle=""
1671 AC_MSG_CHECKING([ctime_r() syntax])
1672 AC_TRY_LINK(
1673   [
1674     #include <time.h>
1675   ],
1676   [ ctime_r(NULL, NULL, 0) ],
1677   [
1678     AC_DEFINE(CTIMERSTYLE, SOLARISSTYLE, [style of ctime_r function])
1679     ctimerstyle="SOLARIS"
1680   ]
1681 )
1682
1683 if test "x$ctimerstyle" = "x"; then
1684   AC_TRY_LINK(
1685     [
1686       #include <time.h>
1687     ],
1688     [ ctime_r(NULL, NULL) ],
1689     [
1690       AC_DEFINE(CTIMERSTYLE, POSIXSTYLE, [style of ctime_r function])
1691       ctimerstyle="POSIX"
1692     ]
1693   )
1694 fi
1695
1696 if test "x$ctimerstyle" = "x"; then
1697     AC_MSG_RESULT([none!  It must not exist, here.])
1698 else
1699     AC_MSG_RESULT([${ctimerstyle}-style])
1700 fi
1701
1702 AC_SUBST(HOSTINFO, $host)
1703
1704 dnl #############################################################
1705 dnl #
1706 dnl #  8. Checks for system services
1707 dnl #
1708 dnl #############################################################
1709
1710 dnl #
1711 dnl #  Figure out where libtool is located,
1712 dnl #
1713 top_builddir=`pwd`
1714 export top_builddir
1715 AC_MSG_RESULT([top_builddir=$top_builddir])
1716 dnl #  AC_SUBST(top_builddir)
1717
1718 dnl #
1719 dnl #  import libtool stuff
1720 dnl #
1721 dnl #############################################################
1722 dnl #
1723 dnl #  Configure in any module directories.
1724 dnl #
1725 dnl #############################################################
1726
1727 dnl ############################################################
1728 dnl #  Remove any conflicting definitions if autoconf.h
1729 dnl #  is being included by a module.
1730 dnl #############################################################
1731 AH_BOTTOM([#include <freeradius-devel/automask.h>])
1732
1733 dnl ############################################################
1734 dnl #  make modules by list
1735 dnl #############################################################
1736 if test "x$EXPERIMENTAL" = "xyes"; then
1737   for foo in `ls -1 "${srcdir}"/src/modules | grep rlm_`; do
1738     MODULES="$MODULES $foo"
1739   done
1740 else
1741    dnl #
1742    dnl #  make ONLY the stable modules
1743    dnl #
1744    for foo in `cat "${srcdir}"/src/modules/stable`; do
1745       MODULES="$MODULES $foo"
1746    done
1747 fi
1748
1749 dnl ############################################################
1750 dnl #  Add autoconf subdirs, based on the module list we
1751 dnl #  previously created.
1752 dnl #############################################################
1753 mysubdirs=""
1754 for bar in $MODULES; do
1755   if test -f "${srcdir}"/src/modules/$bar/configure; then
1756     mysubdirs="$mysubdirs src/modules/$bar"
1757   fi
1758 done
1759
1760 dnl #
1761 dnl #  Don't change the variable name here.  Autoconf goes bonkers
1762 dnl #  if you do.
1763 dnl #
1764 AC_CONFIG_SUBDIRS($mysubdirs)
1765 AC_SUBST(MODULES)
1766
1767 dnl #############################################################
1768 dnl #
1769 dnl #  Add -Werror last, so it doesn't interfere with autoconf's
1770 dnl #  test programs.
1771 dnl #
1772 dnl #############################################################
1773 if test "x$werror" == "xyes"; then
1774   CFLAGS="-Werror $CFLAGS"
1775 fi
1776
1777 dnl #############################################################
1778 dnl #
1779 dnl #  And finally, output the results.
1780 dnl #
1781 dnl #############################################################
1782 AC_CONFIG_COMMANDS([stamp-h], [echo timestamp > src/include/stamp-h])
1783 AC_CONFIG_COMMANDS([build-radpaths-h], [(cd ./src/include && /bin/sh ./build-radpaths-h)])
1784 AC_CONFIG_COMMANDS([main-chmod], [(cd ./src/main && chmod +x checkrad radlast radtest)])
1785 AC_CONFIG_COMMANDS([scripts-chmod], [(cd ./scripts && chmod +x rc.radiusd cron/radiusd.cron.daily cron/radiusd.cron.monthly cryptpasswd)])
1786
1787 dnl #
1788 dnl #  Substitute whatever libraries we found to be necessary
1789 dnl #
1790 AC_SUBST(LIBS)
1791 AC_SUBST(INSTALLSTRIP)
1792
1793 AC_SUBST(USE_SHARED_LIBS)
1794 USE_STATIC_LIBS="yes"
1795 AC_SUBST(USE_STATIC_LIBS)
1796 AC_SUBST(STATIC_MODULES)
1797
1798 AC_OUTPUT(\
1799   ./Make.inc \
1800   ./src/include/build-radpaths-h \
1801   ./src/main/radsniff.mk \
1802   ./src/main/checkrad \
1803   ./src/main/radlast \
1804   ./src/main/radtest \
1805   ./scripts/rc.radiusd \
1806   ./scripts/cron/radiusd.cron.daily \
1807   ./scripts/cron/radiusd.cron.monthly \
1808   ./scripts/cryptpasswd \
1809   ./raddb/radrelay.conf \
1810   ./raddb/radiusd.conf
1811 )