update copyright year
[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   features.h \
786   resource.h \
787   sys/resource.h \
788   getopt.h \
789   malloc.h \
790   utmp.h \
791   utmpx.h \
792   signal.h \
793   sys/select.h \
794   syslog.h \
795   inttypes.h \
796   stdint.h \
797   stdio.h \
798   netdb.h \
799   semaphore.h \
800   arpa/inet.h \
801   netinet/in.h \
802   sys/types.h \
803   sys/socket.h \
804   winsock.h \
805   utime.h \
806   sys/time.h \
807   sys/wait.h \
808   sys/security.h \
809   fcntl.h \
810   sys/fcntl.h \
811   sys/prctl.h \
812   sys/un.h \
813   glob.h \
814   prot.h \
815   pwd.h \
816   grp.h \
817   stddef.h \
818   fnmatch.h \
819   sia.h \
820   siad.h
821 )
822
823 dnl #
824 dnl #  FreeBSD requires sys/socket.h before net/if.h
825 dnl #
826 AC_CHECK_HEADERS(net/if.h, [], [],
827 [
828   #ifdef HAVE_SYS_SOCKET_H
829   #  include <sys/socket.h>
830   #endif
831 ])
832
833 dnl #
834 dnl #  other checks which require headers
835 dnl #
836 if test "x$ac_cv_header_sys_security_h" = "xyes" && test "x$ac_cv_header_prot_h" = "xyes"
837 then
838   AC_DEFINE(OSFC2, [], [define if you have OSFC2 authentication])
839 fi
840
841 if test "x$ac_cv_header_sia_h" = "xyes" && test "x$ac_cv_header_siad_h" = "xyes"
842 then
843   AC_DEFINE(OSFSIA, [], [define if you have OSFSIA authentication])
844 fi
845
846 dnl #
847 dnl #  Were we told to use OpenSSL, if we were and we find an error, call AC_MSG_FAILURE and exit
848 dnl #
849 if test "x$WITH_OPENSSL" = xyes; then
850   old_LIBS=$LIBS
851   old_LDFLAGS="$LDFLAGS"
852
853   OPENSSL_INCLUDE="-DNO_OPENSSL"
854   OPENSSL_LIBS=
855   if test "x$OPENSSL_LIB_DIR" != "x"; then
856     LDFLAGS="-L$OPENSSL_LIB_DIR $LDFLAGS"
857   fi
858
859   dnl #
860   dnl #  Check we can link to libssl
861   dnl #
862   AC_CHECK_LIB(crypto, DH_new,
863     [
864       LIBS="-lcrypto $LIBS"
865       AC_DEFINE(HAVE_LIBCRYPTO, 1, [Define to 1 if you have the `crypto' library (-lcrypto).])
866       AC_CHECK_LIB(ssl, SSL_new,
867         [
868           AC_DEFINE(HAVE_LIBSSL, 1, [Define to 1 if you have the `ssl' library (-lssl).])
869           if test "x$OPENSSL_LIB_DIR" != "x"; then
870             OPENSSL_LIBS="-L$OPENSSL_LIB_DIR"
871           fi
872           OPENSSL_LIBS="$OPENSSL_LIBS -lcrypto -lssl -lcrypto"
873         ],
874         [
875           AC_MSG_FAILURE([failed linking to libssl])
876         ]
877       )
878     ],
879     []
880   )
881
882   dnl #
883   dnl #  Check we can find required headers
884   dnl #
885   old_CPPFLAGS=$CPPFLAGS
886   old_CFLAGS=$CFLAGS
887   if test "x$OPENSSL_INCLUDE_DIR" != "x"; then
888     CPPFLAGS="-isystem $OPENSSL_INCLUDE_DIR $CPPFLAGS"
889     CFLAGS="-isystem $OPENSSL_INCLUDE_DIR $CFLAGS"
890   fi
891
892   dnl #
893   dnl #  Stupid RedHat shit
894   dnl #
895   CPPFLAGS="$CPPFLAGS -DOPENSSL_NO_KRB5"
896   AC_CHECK_HEADERS( \
897     openssl/ssl.h \
898     openssl/crypto.h \
899     openssl/err.h \
900     openssl/evp.h \
901     openssl/md5.h \
902     openssl/md4.h \
903     openssl/sha.h \
904     openssl/ocsp.h \
905     openssl/engine.h,
906     [],
907     [
908       AC_MSG_FAILURE([failed locating OpenSSL headers])
909     ]
910   )
911
912   AC_MSG_CHECKING([for OpenSSL version >= 0.9.7])
913   AC_EGREP_CPP(yes,
914     [#include <openssl/crypto.h>
915      #if (OPENSSL_VERSION_NUMBER >= 0x00907000L)
916      yes
917      #endif
918     ],
919     [
920       AC_MSG_RESULT(yes)
921     ],
922     [
923       AC_MSG_RESULT(no)
924       AC_MSG_FAILURE([OpenSSL version too old])
925     ]
926   )
927
928   if test "x$OPENSSL_INCLUDE_DIR" != "x"; then
929     OPENSSL_INCLUDE="-isystem $OPENSSL_INCLUDE_DIR -DOPENSSL_NO_KRB5"
930   else
931     OPENSSL_INCLUDE="-DOPENSSL_NO_KRB5"
932   fi
933
934   dnl #
935   dnl #  Now check that the header versions match the library
936   dnl #
937   AC_MSG_CHECKING([OpenSSL library and header version consistency])
938   AC_RUN_IFELSE(
939     [AC_LANG_PROGRAM(
940       [[
941         #include <stdio.h>
942         #include <openssl/opensslv.h>
943         #include <openssl/crypto.h>
944       ]],
945       [[
946         if (SSLeay() == OPENSSL_VERSION_NUMBER) {
947           return 0;
948         } else {
949           printf("library: %lx header: %lx... ", (unsigned long) SSLeay(), (unsigned long) OPENSSL_VERSION_NUMBER);
950           return 1;
951         }
952       ]]
953     )],
954     [
955       AC_MSG_RESULT(yes)
956     ],
957     [
958       AC_MSG_RESULT(no)
959       AC_MSG_FAILURE([OpenSSL library version does not match header version])
960     ]
961   )
962
963   if test "x$OPENSSL_LIBS" = x; then
964     LIBS=$old_LIBS
965     LDFLAGS="$old_LDFLAGS"
966   fi
967   if test "x$OPENSSL_INCLUDE" = x; then
968     CPPFLAGS=$old_CPPFLAGS
969     CFLAGS=$old_CFLAGS
970   fi
971 fi
972
973 AC_SUBST(OPENSSL_INCLUDE)
974 AC_SUBST(OPENSSL_LIBS)
975 export OPENSSL_LIBS
976
977 dnl #
978 dnl #  Check the pcap includes for the RADIUS sniffer.
979 dnl #
980 if test "x$PCAP_LIBS" = x; then
981   AC_MSG_NOTICE([skipping test for pcap.h.])
982 else
983   smart_try_dir="$pcap_include_dir"
984   FR_SMART_CHECK_INCLUDE([pcap.h])
985   if test "x$ac_cv_header_pcap_h" != "xyes"; then
986     AC_MSG_WARN([pcap headers not found. Use --with-pcap-include-dir=<path>.])
987     AC_MSG_WARN([pcap.h not found, silently disabling the RADIUS sniffer, and ARP listener.])
988   else
989     AC_DEFINE(HAVE_PCAP_H, 1, [Define to 1 if you have the <pcap.h> header file.])
990
991     AC_CHECK_LIB(pcap, pcap_fopen_offline,
992       [
993         AC_DEFINE(HAVE_PCAP_FOPEN_OFFLINE, 1, [Define to 1 if you have the function pcap_fopen_offline.])
994       ]
995     )
996
997     AC_CHECK_LIB(pcap, pcap_dump_fopen,
998       [
999         AC_DEFINE(HAVE_PCAP_DUMP_FOPEN, 1, [Define to 1 if you have the function pcap_dump_fopen.])
1000       ]
1001     )
1002   fi
1003 fi
1004 AC_SUBST(PCAP_LIBS)
1005
1006 dnl #############################################################
1007 dnl #
1008 dnl #  4. Checks for typedefs
1009 dnl #
1010 dnl #############################################################
1011
1012 dnl #
1013 dnl #  Ensure that these are defined
1014 dnl #
1015 AC_TYPE_OFF_T
1016 AC_TYPE_PID_T
1017 AC_TYPE_SIZE_T
1018 AC_TYPE_UID_T
1019
1020 dnl #
1021 dnl #  Check for socklen_t
1022 dnl #
1023 FR_CHECK_TYPE_INCLUDE(
1024   [
1025     #ifdef HAVE_SYS_TYPES_H
1026     #  include <sys/types.h>
1027     #endif
1028
1029     #ifdef HAVE_SYS_SOCKET_H
1030     #  include <sys/socket.h>
1031     #endif
1032   ],
1033   socklen_t, int, [socklen_t is generally 'int' on systems which don't use it]
1034 )
1035
1036 dnl #
1037 dnl #  Check for uint8_t
1038 dnl #
1039 FR_CHECK_TYPE_INCLUDE(
1040   [
1041     #ifdef HAVE_INTTYPES_H
1042     #  include <inttypes.h>
1043     #endif
1044
1045     #ifdef HAVE_STDINT_H
1046     #  include <stdint.h>
1047     #endif
1048   ],
1049   uint8_t, unsigned char, [uint8_t should be the canonical 'octet' for network traffic]
1050 )
1051
1052 dnl #
1053 dnl #  Check for uint16_t
1054 dnl #
1055 FR_CHECK_TYPE_INCLUDE(
1056   [
1057     #ifdef HAVE_INTTYPES_H
1058     #  include <inttypes.h>
1059     #endif
1060
1061     #ifdef HAVE_STDINT_H
1062     #  include <stdint.h>
1063     #endif
1064   ],
1065   uint16_t, unsigned short, [uint16_t should be the canonical '2 octets' for network traffic]
1066 )
1067
1068 dnl #
1069 dnl #  Check for uint32_t
1070 dnl #
1071 FR_CHECK_TYPE_INCLUDE(
1072   [
1073     #ifdef HAVE_INTTYPES_H
1074     #  include <inttypes.h>
1075     #endif
1076
1077     #ifdef HAVE_STDINT_H
1078     #  include <stdint.h>
1079     #endif
1080   ],
1081   uint32_t, unsigned int, [uint32_t should be the canonical 'network integer']
1082 )
1083
1084 dnl #
1085 dnl #  Check for uint64_t
1086 dnl #
1087 FR_CHECK_TYPE_INCLUDE(
1088   [
1089     #ifdef HAVE_INTTYPES_H
1090     #  include <inttypes.h>
1091     #endif
1092
1093     #ifdef HAVE_STDINT_H
1094     #  include <stdint.h>
1095     #endif
1096   ],
1097   uint64_t, unsigned long long, [uint64_t is required for larger counters]
1098 )
1099
1100 FR_CHECK_TYPE_INCLUDE(
1101   [
1102     #ifdef HAVE_SIGNAL_H
1103     #  include <signal.h>
1104     #endif
1105   ],
1106   sig_t, void(*sig_t)(int), [signal action callback function]
1107 )
1108
1109 dnl #
1110 dnl #  Check for __uint128_t (compiler builtin)
1111 dnl #
1112 AC_CHECK_TYPE(__uint128_t, AC_DEFINE(HAVE___UINT128_T, 1, [compiler specific 128 bit unsigned integer]), [], [])
1113
1114 dnl #
1115 dnl #  Check for uint128_t (fictitious future data type)
1116 dnl #
1117 AC_CHECK_TYPE(uint128_t, AC_DEFINE(HAVE_UINT128_T, 1, [128 bit unsigned integer]), [],
1118   [
1119     #ifdef HAVE_INTTYPES_H
1120     #  include <inttypes.h>
1121     #endif
1122
1123     #ifdef HAVE_STDINT_H
1124     #  include <stdint.h>
1125     #endif
1126   ]
1127 )
1128
1129 AC_CHECK_TYPE(struct in6_addr, AC_DEFINE(HAVE_STRUCT_IN6_ADDR, 1, [IPv6 address structure]), [],
1130   [
1131     #ifdef HAVE_NETINET_IN_H
1132     #  include <netinet/in.h>
1133     #endif
1134   ]
1135 )
1136
1137 AC_CHECK_TYPE(struct sockaddr_storage, AC_DEFINE(HAVE_STRUCT_SOCKADDR_STORAGE, 1, [Generic socket addresses]), [],
1138   [
1139     #ifdef HAVE_NETINET_IN_H
1140     #  include <netinet/in.h>
1141     #endif
1142
1143     #ifdef HAVE_SYS_SOCKET_H
1144     #  include <sys/socket.h>
1145     #endif
1146 ])
1147
1148 AC_CHECK_TYPE(struct sockaddr_in6, AC_DEFINE(HAVE_STRUCT_SOCKADDR_IN6, 1, [IPv6 socket addresses]), [],
1149   [
1150     #ifdef HAVE_NETINET_IN_H
1151     #  include <netinet/in.h>
1152     #endif
1153 ])
1154
1155 AC_CHECK_TYPE(struct addrinfo, AC_DEFINE(HAVE_STRUCT_ADDRINFO, 1, [Generic DNS lookups]), [],
1156   [
1157     #ifdef HAVE_SYS_TYPES_H
1158     #  include <sys/types.h>
1159     #endif
1160
1161     #ifdef HAVE_SYS_SOCKET_H
1162     #  include <sys/socket.h>
1163     #endif
1164
1165     #ifdef HAVE_NETDB_H
1166     #  include <netdb.h>
1167     #endif
1168   ]
1169 )
1170
1171 dnl #############################################################
1172 dnl #
1173 dnl #  5. Checks for structures and functions
1174 dnl #
1175 dnl #############################################################
1176 AC_CHECK_FUNCS( \
1177   getopt_long \
1178   fcntl \
1179   strsignal \
1180   sigaction \
1181   sigprocmask \
1182   pthread_sigmask \
1183   snprintf \
1184   vsnprintf \
1185   setsid \
1186   strncasecmp \
1187   strcasecmp \
1188   localtime_r \
1189   ctime_r \
1190   gmtime_r \
1191   strsep \
1192   inet_aton \
1193   inet_pton \
1194   inet_ntop \
1195   setlinebuf \
1196   setvbuf \
1197   getusershell \
1198   initgroups \
1199   getaddrinfo \
1200   getnameinfo \
1201   closefrom \
1202   gettimeofday \
1203   getpeereid \
1204   setuid \
1205   setresuid \
1206   getresuid \
1207   strlcat \
1208   strlcpy
1209 )
1210
1211 AC_TYPE_SIGNAL
1212
1213 dnl #
1214 dnl #  Check if we have utmpx.h
1215 dnl #  if so, check if struct utmpx has entry ut_xtime
1216 dnl #  if not, set it to define ut_xtime == ut_tv.tv_sec
1217 dnl #
1218 if test "x$ac_cv_header_utmpx_h" = "xyes"; then
1219  FR_CHECK_STRUCT_HAS_MEMBER([#include <utmpx.h>], [struct utmpx], ut_xtime)
1220  if test "x$ac_cv_type_struct_utmpx_has_ut_xtime" = "x"; then
1221    AC_DEFINE(ut_xtime, ut_tv.tv_sec, [define to something if you don't have ut_xtime in struct utmpx])
1222  fi
1223 fi
1224
1225 dnl #
1226 dnl #  struct ip_pktinfo
1227 dnl #
1228 FR_CHECK_STRUCT_HAS_MEMBER([#include <netinet/in.h>], [struct in_pktinfo], ipi_addr)
1229 if test "x$ac_cv_type_struct_in_pktinfo_has_ipi_addr" = "xyes"; then
1230   AC_DEFINE(HAVE_IP_PKTINFO, [], [define if you have IP_PKTINFO (Linux)])
1231 fi
1232
1233 dnl #
1234 dnl #  struct in6_pktinfo
1235 dnl #
1236 FR_CHECK_STRUCT_HAS_MEMBER([#include <netinet/in.h>], [struct in6_pktinfo], ipi6_addr)
1237 if test "x$ac_cv_type_struct_in6_pktinfo_has_ipi6_addr" = "xyes"; then
1238   AC_DEFINE(HAVE_IN6_PKTINFO, [], [define if you have IN6_PKTINFO (Linux)])
1239 fi
1240
1241 dnl #############################################################
1242 dnl #
1243 dnl #  6. Checks for compiler characteristics
1244 dnl #
1245 dnl #############################################################
1246
1247 dnl #
1248 dnl #  Ensure that these are defined
1249 dnl #
1250 AC_C_CONST
1251
1252 dnl #
1253 dnl #  See if this is OS/2
1254 dnl #
1255 AC_MSG_CHECKING([type of OS])
1256 OS=`uname -s`
1257 AC_MSG_RESULT($OS)
1258 if test "$OS" = "OS/2"; then
1259   LIBPREFIX=
1260 else
1261   LIBPREFIX=lib
1262 fi
1263 AC_SUBST(LIBPREFIX)
1264
1265 if test "x$developer" = "xyes"; then
1266   AC_MSG_NOTICE([Setting additional developer CFLAGS])
1267
1268   dnl #
1269   dnl #  Tell the compiler to parse doxygen documentation and verify it against function and variable declarations
1270   dnl #
1271   AX_CC_WDOCUMENTATION_FLAG
1272   if test "x$ax_cv_cc_wdocumentation_flag" = "xyes"; then
1273     devflags="-Wdocumentation"
1274   fi
1275
1276   if test "x$GCC" = "xyes"; then
1277     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"
1278     INSTALLSTRIP=""
1279   fi
1280
1281   AC_MSG_NOTICE([Developer CFLAGS are "$devflags"])
1282
1283   CFLAGS="$CFLAGS $devflags"
1284   dnl #
1285   dnl #  Enable experimental modules (we want to know if code changes breaks one of them)
1286   dnl #
1287   if test "x$EXPERIMENTAL" != "xno"; then
1288     AC_MSG_NOTICE([is developer build, enabling experimental modules implicitly, disable with --without-experimental-modules])
1289     EXPERIMENTAL=yes
1290   fi
1291 else
1292   devflags=""
1293   CFLAGS="$CFLAGS -DNDEBUG"
1294   INSTALLSTRIP=""
1295 fi
1296
1297 dnl #
1298 dnl #  May of been set outside of this configure script
1299 dnl #
1300 AC_MSG_CHECKING([if building with -DNDEBUG])
1301 if echo "$CFLAGS" | grep '\-DNDEBUG' > /dev/null; then
1302   AC_MSG_RESULT([yes])
1303   AC_DEFINE([WITH_NDEBUG], [1], [define if the server was built with -DNDEBUG])
1304 else
1305   AC_MSG_RESULT([no])
1306 fi
1307
1308 export EXPERIMENTAL
1309
1310 dnl #
1311 dnl #  append the current git hash onto the version string
1312 dnl #
1313 if test -d $srcdir/.git -a "x$GIT" = "xyes"; then
1314   RADIUSD_VERSION_COMMIT=`git log --pretty=format:'%h' -n 1`
1315   AC_DEFINE_UNQUOTED([RADIUSD_VERSION_COMMIT],[${RADIUSD_VERSION_COMMIT}],[Commit HEAD at time of configuring])
1316 fi
1317
1318 FR_TLS
1319
1320 dnl #############################################################
1321 dnl #
1322 dnl #  7. Checks for library functions
1323 dnl #
1324 dnl #############################################################
1325
1326 dnl Check for talloc
1327 dnl extra argument: --with-talloc-include-dir=DIR
1328 talloc_include_dir=
1329 AC_ARG_WITH(talloc-include-dir,
1330   [  --with-talloc-include-dir=DIR    directory to look for talloc include files in],
1331   [case "$withval" in
1332     no)
1333       AC_MSG_ERROR([Need talloc-include-dir])
1334       ;;
1335     yes)
1336       ;;
1337     *)
1338       talloc_include_dir="$withval"
1339       ;;
1340   esac])
1341
1342 dnl Check for talloc
1343 dnl extra argument: --with-talloc-lib-dir=DIR
1344 talloc_lib_dir=
1345 AC_ARG_WITH(talloc-lib-dir,
1346   [  --with-talloc-lib-dir=DIR        directory to look for talloc library files in],
1347   [case "$withval" in
1348     no)
1349       AC_MSG_ERROR([Need talloc-lib-dir])
1350       ;;
1351     yes)
1352       ;;
1353     *)
1354       talloc_lib_dir="$withval"
1355       ;;
1356   esac])
1357
1358 dnl Check for pcap
1359 dnl extra argument: --with-pcap-include-dir=DIR
1360 pcap_include_dir=
1361 AC_ARG_WITH(pcap-include-dir,
1362   [  --with-pcap-include-dir=DIR      directory to look for pcap include files in],
1363   [case "$withval" in
1364     no)
1365       AC_MSG_ERROR([Need pcap-include-dir])
1366       ;;
1367     yes)
1368       ;;
1369     *)
1370       pcap_include_dir="$withval"
1371       ;;
1372   esac])
1373
1374 dnl Check for pcap
1375 dnl extra argument: --with-pcap-lib-dir=DIR
1376 pcap_lib_dir=
1377 AC_ARG_WITH(pcap-lib-dir,
1378   [  --with-pcap-lib-dir=DIR          directory to look for pcap library files in],
1379   [case "$withval" in
1380     no)
1381       AC_MSG_ERROR([Need pcap-lib-dir])
1382       ;;
1383     yes)
1384       ;;
1385     *)
1386       pcap_lib_dir="$withval"
1387       ;;
1388   esac])
1389
1390 dnl #
1391 dnl # Check for talloc header files
1392 dnl #
1393 smart_try_dir="$talloc_include_dir"
1394 FR_SMART_CHECK_INCLUDE([talloc.h])
1395 if test "x$ac_cv_header_talloc_h" != "xyes"; then
1396   AC_MSG_WARN([talloc headers not found. Use --with-talloc-include-dir=<path>.])
1397   AC_MSG_ERROR([FreeRADIUS requires libtalloc])
1398 fi
1399
1400 smart_try_dir="$talloc_lib_dir"
1401 FR_SMART_CHECK_LIB(talloc, _talloc)
1402 if test "x$ac_cv_lib_talloc__talloc" != "xyes"; then
1403   AC_MSG_WARN([talloc library not found. Use --with-talloc-lib-dir=<path>.])
1404   AC_MSG_ERROR([FreeRADIUS requires libtalloc])
1405 fi
1406
1407 dnl #
1408 dnl # Check for libcrypt
1409 dnl # We use crypt(3) which may be in libc, or in libcrypt (eg FreeBSD)
1410 dnl #
1411 AC_CHECK_LIB(crypt, crypt,
1412   CRYPTLIB="-lcrypt"
1413 )
1414
1415 if test "$CRYPTLIB" != ""; then
1416   AC_DEFINE(HAVE_CRYPT, [], [Do we have the crypt function])
1417 else
1418   AC_CHECK_FUNC(crypt, AC_DEFINE(HAVE_CRYPT, [], [Do we have the crypt function]))
1419 fi
1420
1421 dnl Check for libcipher
1422 AC_CHECK_LIB(cipher, setkey,
1423    CRYPTLIB="${CRYPTLIB} -lcipher"
1424 )
1425 AC_SUBST(CRYPTLIB)
1426
1427 dnl #
1428 dnl #  Check for libexecinfo support, on some systems this is built into libc
1429 dnl #  on others it's a separate library.
1430 dnl #
1431 dnl extra argument: --with-execinfo-lib-dir
1432 execinfo_lib_dir=
1433 AC_ARG_WITH(execinfo-lib-dir,
1434 [  --with-execinfo-lib-dir=DIR      directory to look for execinfo library files in],
1435 [ case "$withval" in
1436     no)
1437         AC_MSG_ERROR([Need execinfo-lib-dir])
1438         ;;
1439     yes)
1440         ;;
1441     *)
1442         execinfo_lib_dir="$withval"
1443         ;;
1444   esac ]
1445 )
1446
1447 dnl extra argument: --with-execinfo-include-dir
1448 execinfo_include_dir=
1449 AC_ARG_WITH(execinfo-include-dir,
1450 [  --with-execinfo-include-dir=DIR  directory to look for execinfo include files in],
1451 [ case "$withval" in
1452     no)
1453         AC_MSG_ERROR(Need execinfo-include-dir)
1454         ;;
1455     yes)
1456         ;;
1457     *)
1458         execinfo_include_dir="$withval"
1459         ;;
1460   esac ]
1461 )
1462
1463 dnl #
1464 dnl #  Look for execinfo.h and symbols
1465 dnl #
1466 smart_try_dir=$execinfo_include_dir
1467 FR_SMART_CHECK_INCLUDE(execinfo.h)
1468 if test "x$ac_cv_header_execinfo_h" = "xyes"; then
1469   smart_try_dir=$execinfo_lib_dir
1470   FR_SMART_CHECK_LIB(execinfo, backtrace_symbols)
1471   if test "x$ac_cv_lib_execinfo_backtrace_symbols" != "xyes"; then
1472     dnl # Might be provided as part of libc
1473     AC_MSG_CHECKING([if execinfo provided as part of libc])
1474     AC_TRY_LINK(
1475       [
1476         #include <execinfo.h>
1477       ],
1478       [
1479         void *sym[1];
1480         backtrace_symbols(&sym, sizeof(sym)) ],
1481       [
1482         AC_MSG_RESULT(yes)
1483         ac_cv_lib_execinfo_backtrace_symbols=yes
1484       ],
1485       [
1486         AC_MSG_RESULT(no)
1487         ac_cv_lib_execinfo_backtrace_symbols=no
1488       ]
1489     )
1490   fi
1491
1492   if test "x$ac_cv_lib_execinfo_backtrace_symbols" = "xyes"; then
1493     AC_DEFINE(HAVE_EXECINFO, [1], [define this if we have <execinfo.h> and symbols])
1494   fi
1495 fi
1496
1497 dnl #
1498 dnl #  Check for regular expression support, if were using PCRE it MUST be included
1499 dnl #  before all others, else we seem to still pickup the posix symbols for regcomp
1500 dnl #  and regexec, which results in crashes as soon as we call any posix regex
1501 dnl #  functions.
1502 dnl #
1503 dnl extra argument: --with-pcre-lib-dir
1504 pcre_lib_dir=
1505 AC_ARG_WITH(pcre-lib-dir,
1506   [  --with-pcre-lib-dir=DIR          directory to look for pcre library files in],
1507   [ case "$withval" in
1508     no)
1509         AC_MSG_ERROR([Need pcre-lib-dir])
1510         ;;
1511     yes)
1512         ;;
1513     *)
1514         pcre_lib_dir="$withval"
1515         ;;
1516     esac ]
1517 )
1518
1519 dnl extra argument: --with-pcre-include--dir
1520 pcre_include_dir=
1521 AC_ARG_WITH(pcre-include-dir,
1522   [  --with-pcre-include-dir=DIR      directory to look for PCRE include files in],
1523   [ case "$withval" in
1524     no)
1525         AC_MSG_ERROR(Need pcre-include-dir)
1526         ;;
1527     yes)
1528         ;;
1529     *)
1530         pcre_include_dir="$withval"
1531         ;;
1532     esac ]
1533 )
1534
1535 REGEX=no
1536 REGEX_EXTENDED=no
1537 REGEX_PCRE=no
1538
1539 dnl #
1540 dnl #  First look for PCRE
1541 dnl #
1542 smart_try_dir=$pcre_include_dir
1543 FR_SMART_CHECK_INCLUDE(pcreposix.h)
1544 if test "x$ac_cv_header_pcreposix_h" = "xyes"; then
1545   AC_DEFINE(HAVE_REGEX_H, [1], [define if we have any regex])
1546   AC_DEFINE(HAVE_PCREPOSIX_H, [1], [define this if we have the <pcreposix.h> header file])
1547   REGEX=yes
1548   REGEX_EXTENDED=yes
1549   REGEX_PCRE=yes
1550   LIBS="-lpcre -lpcreposix $LIBS"
1551
1552 dnl #
1553 dnl #  Then fallback to POSIX regular expressions
1554 dnl #
1555 else
1556   smart_try_dir=
1557   FR_SMART_CHECK_INCLUDE(regex.h)
1558   if test "x$ac_cv_header_regex_h" = "xyes"; then
1559     AC_DEFINE(HAVE_REGEX_H, [1], [define if we have any regex])
1560     REGEX=yes
1561     AC_EGREP_CPP(yes,
1562       [
1563         #include <regex.h>
1564         #ifdef REG_EXTENDED
1565         yes
1566         #endif
1567        ],
1568     [AC_DEFINE(HAVE_REG_EXTENDED, [1], [define this if we have REG_EXTENDED (from <regex.h>)]) REGEX_EXTENDED=yes]
1569     )
1570 dnl #
1571 dnl # Fixme, this is needed for mingw builds, but not available on some Linux systems
1572 dnl # despite the presence of regex.h
1573 dnl #
1574 dnl # LIBS="$LIBS -lregex"
1575   fi
1576 fi
1577
1578 AC_SUBST(REGEX)
1579 AC_SUBST(REGEX_PCRE)
1580 AC_SUBST(REGEX_EXTENDED)
1581
1582 dnl #
1583 dnl #  Check the style of gethostbyaddr, in order of preference
1584 dnl #  GNU (_r eight args)
1585 dnl #
1586 AC_DEFINE(GNUSTYLE, [1], [GNU-Style get*byaddr_r])
1587
1588 dnl #
1589 dnl #  SYSV (_r six args)
1590 dnl #
1591 AC_DEFINE(SYSVSTYLE, [2], [SYSV-Style get*byaddr_r])
1592
1593 dnl #
1594 dnl #  BSD (three args, may not be thread safe)
1595 dnl #
1596 AC_DEFINE(BSDSTYLE, [3], [BSD-Style get*byaddr_r])
1597
1598 dnl #
1599 dnl #  Tru64 has BSD version, but it is thread safe
1600 dnl #  http://h30097.www3.hp.com/docs/base_doc/DOCUMENTATION/V51B_HTML/MAN/MAN3/1739____.HTM
1601 dnl #  We need #stdio.h to define NULL on FreeBSD (at least)
1602 dnl #
1603 gethostbyaddrrstyle=""
1604 AC_MSG_CHECKING([gethostbyaddr_r() syntax])
1605 case "$host" in
1606   *-freebsd*)
1607     dnl #
1608     dnl #  With FreeBSD, check if there's a prototype for gethostbyaddr_r.
1609     dnl #  Some versions (FreeBSD 5.1?) have a symbol but no prototype - so we
1610     dnl #  override this test to BSDSTYLE. FreeBSD 6.2 and up have proper GNU
1611     dnl #  style support.
1612     dnl #
1613     AC_CHECK_DECLS([gethostbyaddr_r], [],
1614       [
1615         AC_DEFINE(GETHOSTBYADDRRSTYLE, BSDSTYLE,
1616           [style of gethostbyaddr_r functions ])
1617         gethostbyaddrrstyle=BSD
1618         AC_MSG_WARN([FreeBSD overridden to BSD-style])
1619       ],
1620       [
1621         #ifdef HAVE_NETDB_H
1622         #include <netdb.h>
1623         #endif
1624       ])
1625     ;;
1626 esac
1627
1628 if test "x$gethostbyaddrrstyle" = "x"; then
1629   AC_TRY_LINK(
1630     [
1631       #include <stdio.h>
1632       #include <netdb.h>
1633     ],
1634     [ gethostbyaddr_r(NULL, 0, 0, NULL, NULL, 0, NULL, NULL) ],
1635     [
1636       AC_DEFINE(GETHOSTBYADDRRSTYLE, GNUSTYLE, [style of gethostbyaddr_r functions ])
1637       gethostbyaddrrstyle=GNU
1638     ]
1639   )
1640 fi
1641
1642 if test "x$gethostbyaddrrstyle" = "x"; then
1643   AC_TRY_LINK(
1644     [
1645       #include <stdio.h>
1646       #include <netdb.h>
1647     ],
1648     [ gethostbyaddr_r(NULL, 0, 0, NULL, NULL, 0, NULL) ] ,
1649     [
1650       AC_DEFINE(GETHOSTBYADDRRSTYLE, SYSVSTYLE, [style of gethostbyaddr_r functions ])
1651       gethostbyaddrrstyle=SYSV
1652     ]
1653   )
1654 fi
1655
1656
1657 if test "x$gethostbyaddrrstyle" = "x"; then
1658   AC_TRY_LINK(
1659     [
1660       #include <stdio.h>
1661       #include <netdb.h>
1662     ],
1663     [ gethostbyaddr(NULL, 0, 0)  ],
1664     [
1665       AC_DEFINE(GETHOSTBYADDRRSTYLE, BSDSTYLE, [style of gethostbyaddr_r functions ])
1666       gethostbyaddrrstyle=BSD
1667     ]
1668   )
1669 fi
1670
1671 if test "x$gethostbyaddrrstyle" = "x"; then
1672   AC_MSG_RESULT([none!  It must not exist, here.])
1673 else
1674   AC_MSG_RESULT([${gethostbyaddrrstyle}-style])
1675 fi
1676
1677 if test "x$gethostbyaddrrstyle" = "xBSD"; then
1678   AC_MSG_WARN([ ****** BSD-style gethostbyaddr might NOT be thread-safe! ****** ])
1679 fi
1680
1681 dnl #
1682 dnl #  Check the style of gethostbyname, in order of preference
1683 dnl #  GNU (_r seven args)
1684 dnl #  SYSV (_r five args)
1685 dnl #  BSD (two args, may not be thread safe)
1686 dnl #  Tru64 has BSD version, but it _is_ thread safe
1687 dnl #    http://h30097.www3.hp.com/docs/base_doc/DOCUMENTATION/V51B_HTML/MAN/MAN3/1946____.HTM
1688 dnl #  We need #stdio.h to define NULL on FreeBSD (at least)
1689 dnl #
1690 gethostbynamerstyle=""
1691 AC_MSG_CHECKING([gethostbyname_r() syntax])
1692 AC_TRY_LINK(
1693   [
1694     #include <stdio.h>
1695     #include <netdb.h>
1696   ],
1697   [ gethostbyname_r(NULL, NULL, NULL, 0, NULL, NULL) ],
1698   [
1699     AC_DEFINE(GETHOSTBYNAMERSTYLE, GNUSTYLE, [style of gethostbyname_r functions ])
1700     gethostbynamerstyle=GNU
1701   ]
1702 )
1703
1704 if test "x$gethostbynamerstyle" = "x"; then
1705   AC_TRY_LINK(
1706     [
1707       #include <stdio.h>
1708       #include <netdb.h>
1709     ],
1710     [ gethostbyname_r(NULL, NULL, NULL, 0, NULL) ] ,
1711     [
1712       AC_DEFINE(GETHOSTBYNAMERSTYLE, SYSVSTYLE, [style of gethostbyname_r functions ])
1713       gethostbynamerstyle=SYSV
1714     ]
1715   )
1716 fi
1717
1718 if test "x$gethostbynamerstyle" = "x"; then
1719   AC_TRY_LINK(
1720     [
1721       #include <stdio.h>
1722       #include <netdb.h>
1723     ],
1724     [ gethostbyname(NULL) ],
1725     [
1726       AC_DEFINE(GETHOSTBYNAMERSTYLE, BSDSTYLE, [style of gethostbyname_r functions ])
1727       gethostbynamerstyle=BSD
1728     ]
1729   )
1730 fi
1731
1732 if test "x$gethostbynamerstyle" = "x"; then
1733   AC_MSG_RESULT([none!  It must not exist, here.])
1734 else
1735   AC_MSG_RESULT([${gethostbynamerstyle}-style])
1736 fi
1737
1738 if test "x$gethostbynamerstyle" = "xBSD"; then
1739   AC_MSG_WARN([ ****** BSD-style gethostbyname might NOT be thread-safe! ****** ])
1740 fi
1741
1742 dnl #
1743 dnl #  Check for non-posix solaris ctime_r (extra buflen int arg)
1744 dnl #
1745 AC_DEFINE(POSIXSTYLE, [1], [Posix-Style ctime_r])
1746 AC_DEFINE(SOLARISSTYLE, [2], [Solaris-Style ctime_r])
1747 ctimerstyle=""
1748 AC_MSG_CHECKING([ctime_r() syntax])
1749 AC_TRY_LINK(
1750   [
1751     #include <time.h>
1752   ],
1753   [ ctime_r(NULL, NULL, 0) ],
1754   [
1755     AC_DEFINE(CTIMERSTYLE, SOLARISSTYLE, [style of ctime_r function])
1756     ctimerstyle="SOLARIS"
1757   ]
1758 )
1759
1760 if test "x$ctimerstyle" = "x"; then
1761   AC_TRY_LINK(
1762     [
1763       #include <time.h>
1764     ],
1765     [ ctime_r(NULL, NULL) ],
1766     [
1767       AC_DEFINE(CTIMERSTYLE, POSIXSTYLE, [style of ctime_r function])
1768       ctimerstyle="POSIX"
1769     ]
1770   )
1771 fi
1772
1773 if test "x$ctimerstyle" = "x"; then
1774     AC_MSG_RESULT([none!  It must not exist, here.])
1775 else
1776     AC_MSG_RESULT([${ctimerstyle}-style])
1777 fi
1778
1779 AC_SUBST(HOSTINFO, $host)
1780
1781 dnl #############################################################
1782 dnl #
1783 dnl #  8. Checks for system services
1784 dnl #
1785 dnl #############################################################
1786
1787 dnl #
1788 dnl #  Figure out where libtool is located,
1789 dnl #
1790 top_builddir=`pwd`
1791 export top_builddir
1792 AC_MSG_RESULT([top_builddir=$top_builddir])
1793 dnl #  AC_SUBST(top_builddir)
1794
1795 dnl #
1796 dnl #  import libtool stuff
1797 dnl #
1798 dnl #############################################################
1799 dnl #
1800 dnl #  Configure in any module directories.
1801 dnl #
1802 dnl #############################################################
1803
1804 dnl ############################################################
1805 dnl #  Remove any conflicting definitions if autoconf.h
1806 dnl #  is being included by a module.
1807 dnl #############################################################
1808 AH_BOTTOM([#include <freeradius-devel/automask.h>])
1809
1810 dnl ############################################################
1811 dnl #  make modules by list
1812 dnl #############################################################
1813 if test "x$EXPERIMENTAL" = "xyes"; then
1814   for foo in `ls -1 "${srcdir}"/src/modules | grep rlm_`; do
1815     MODULES="$MODULES $foo"
1816   done
1817 else
1818    dnl #
1819    dnl #  make ONLY the stable modules
1820    dnl #
1821    for foo in `cat "${srcdir}"/src/modules/stable`; do
1822       MODULES="$MODULES $foo"
1823    done
1824 fi
1825
1826 dnl ############################################################
1827 dnl #  Add autoconf subdirs, based on the module list we
1828 dnl #  previously created.
1829 dnl #############################################################
1830 mysubdirs=""
1831 for bar in $MODULES; do
1832   if test -f "${srcdir}"/src/modules/$bar/configure; then
1833     mysubdirs="$mysubdirs src/modules/$bar"
1834   fi
1835 done
1836
1837 dnl #
1838 dnl #  Don't change the variable name here.  Autoconf goes bonkers
1839 dnl #  if you do.
1840 dnl #
1841 AC_CONFIG_SUBDIRS($mysubdirs)
1842 AC_SUBST(MODULES)
1843
1844 dnl #############################################################
1845 dnl #
1846 dnl #  Add -Werror last, so it doesn't interfere with autoconf's
1847 dnl #  test programs.
1848 dnl #
1849 dnl #############################################################
1850 if test "x$werror" == "xyes"; then
1851   CFLAGS="-Werror $CFLAGS"
1852 fi
1853
1854 dnl #############################################################
1855 dnl #
1856 dnl #  And finally, output the results.
1857 dnl #
1858 dnl #############################################################
1859 AC_CONFIG_COMMANDS([stamp-h], [echo timestamp > src/include/stamp-h])
1860 AC_CONFIG_COMMANDS([build-radpaths-h], [(cd ./src/include && /bin/sh ./build-radpaths-h)])
1861 AC_CONFIG_COMMANDS([main-chmod], [(cd ./src/main && chmod +x checkrad radlast radtest)])
1862 AC_CONFIG_COMMANDS([scripts-chmod], [(cd ./scripts && chmod +x rc.radiusd cron/radiusd.cron.daily cron/radiusd.cron.monthly cryptpasswd)])
1863
1864 dnl #
1865 dnl #  Substitute whatever libraries we found to be necessary
1866 dnl #
1867 AC_SUBST(LIBS)
1868 AC_SUBST(INSTALLSTRIP)
1869
1870 AC_SUBST(USE_SHARED_LIBS)
1871 USE_STATIC_LIBS="yes"
1872 AC_SUBST(USE_STATIC_LIBS)
1873 AC_SUBST(STATIC_MODULES)
1874
1875 AC_OUTPUT(\
1876   ./Make.inc \
1877   ./src/include/build-radpaths-h \
1878   ./src/main/radsniff.mk \
1879   ./src/main/checkrad \
1880   ./src/main/radlast \
1881   ./src/main/radtest \
1882   ./scripts/rc.radiusd \
1883   ./scripts/cron/radiusd.cron.daily \
1884   ./scripts/cron/radiusd.cron.monthly \
1885   ./scripts/cryptpasswd \
1886   ./raddb/radrelay.conf \
1887   ./raddb/radiusd.conf
1888 )