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