a118c5756b728d91f7f2da861b8f4b15d26881a8
[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 #  Check for regular expression support
750 dnl #
751 dnl extra argument: --with-pcre-lib-dir
752 pcre_lib_dir=
753 AC_ARG_WITH(rlm-pcre-lib-dir,
754 [  --with-pcre-lib-dir=DIR       directory for PCRE library files []],
755 [ case "$withval" in
756     no)
757         AC_MSG_ERROR(Need rlm-pcre-lib-dir)
758         ;;
759     yes)
760         ;;
761     *)
762         pcre_lib_dir="$withval"
763         ;;
764   esac ]
765 )
766
767 dnl extra argument: --with-pcre-include--dir
768 pcre_include_dir=
769 AC_ARG_WITH(rlm-pcre-include-dir,
770 [  --with-pcre-include-dir=DIR   directory for PCRE include files []],
771 [ case "$withval" in
772     no)
773         AC_MSG_ERROR(Need rlm-pcre-include-dir)
774         ;;
775     yes)
776         ;;
777     *)
778         pcre_include_dir="$withval"
779         ;;
780   esac ]
781 )
782
783 REGEX=no
784 REGEX_EXTENDED=no
785 REGEX_PCRE=no
786
787 dnl #
788 dnl #  First look for PCRE
789 dnl #
790 smart_try_dir=$pcre_include_dir
791 FR_SMART_CHECK_INCLUDE(pcreposix.h)
792 if test "x$ac_cv_header_pcreposix_h" = "xyes"; then
793   AC_DEFINE(HAVE_REGEX_H, [1], [define if we have any regex])
794   AC_DEFINE(HAVE_PCREPOSIX_H, [1], [define this if we have the <pcreposix.h> header file])
795   REGEX=yes
796   REGEX_EXTENDED=yes
797   REGEX_PCRE=yes
798   LIBS="$LIBS -lpcre -lpcreposix"
799   
800 dnl #
801 dnl #  Then fallback to POSIX regular expressions
802 dnl #
803 else
804   smart_try_dir=
805   FR_SMART_CHECK_INCLUDE(regex.h)
806   if test "x$ac_cv_header_regex_h" = "xyes"; then
807     AC_DEFINE(HAVE_REGEX_H, [1], [define if we have any regex])
808     REGEX=yes
809     AC_EGREP_CPP(yes,
810       [
811         #include <regex.h>
812         #ifdef REG_EXTENDED
813         yes
814         #endif
815        ],
816     [AC_DEFINE(HAVE_REG_EXTENDED, [1], [define this if we have REG_EXTENDED (from <regex.h>)]) REGEX_EXTENDED=yes]
817     )
818   fi
819 fi
820
821 AC_SUBST(REGEX)
822 AC_SUBST(REGEX_PCRE)
823 AC_SUBST(REGEX_EXTENDED)
824
825 dnl #
826 dnl #  other checks which require headers
827 dnl #
828 if test "x$ac_cv_header_sys_security_h" = "xyes" && test "x$ac_cv_header_prot_h" = "xyes"
829 then
830   AC_DEFINE(OSFC2, [], [define if you have OSFC2 authentication])
831 fi
832
833 if test "x$ac_cv_header_sia_h" = "xyes" && test "x$ac_cv_header_siad_h" = "xyes"
834 then
835   AC_DEFINE(OSFSIA, [], [define if you have OSFSIA authentication])
836 fi
837
838 dnl #
839 dnl #  Were we told to use OpenSSL, if we were and we find an error, call AC_MSG_FAILURE and exit
840 dnl #
841 if test "x$WITH_OPENSSL" = xyes; then
842   old_LIBS=$LIBS
843   old_LDFLAGS="$LDFLAGS"
844   
845   OPENSSL_INCLUDE="-DNO_OPENSSL"
846   OPENSSL_LIBS=
847   if test "x$OPENSSL_LIB_DIR" != "x"; then
848     LDFLAGS="$LDFLAGS -L$OPENSSL_LIB_DIR"
849   fi
850
851   dnl #
852   dnl #  Check we can link to libssl
853   dnl #
854   AC_CHECK_LIB(crypto, DH_new,
855     [
856       LIBS="-lcrypto $LIBS"
857       AC_DEFINE(HAVE_LIBCRYPTO, 1, [Define to 1 if you have the `crypto' library (-lcrypto).])
858       AC_CHECK_LIB(ssl, SSL_new,
859         [
860           AC_DEFINE(HAVE_LIBSSL, 1, [Define to 1 if you have the `ssl' library (-lssl).])
861           if test "x$OPENSSL_LIB_DIR" != "x"; then
862             OPENSSL_LIBS="-L$OPENSSL_LIB_DIR"
863           fi
864           OPENSSL_LIBS="$OPENSSL_LIBS -lcrypto -lssl -lcrypto"
865         ],
866         [
867           AC_MSG_FAILURE([failed linking to libssl])
868         ]
869       )
870     ],
871     []
872   )
873
874   dnl #
875   dnl #  Check we can find required headers
876   dnl #
877   old_CPPFLAGS=$CPPFLAGS
878   if test "x$OPENSSL_INCLUDE_DIR" != "x"; then
879     CPPFLAGS="$CPPFLAGS -I$OPENSSL_INCLUDE_DIR"
880   fi
881  
882   dnl # 
883   dnl #  Stupid RedHat shit
884   dnl #
885   CPPFLAGS="$CPPFLAGS -DOPENSSL_NO_KRB5"
886   AC_CHECK_HEADERS( \
887     openssl/ssl.h \
888     openssl/crypto.h \
889     openssl/err.h \
890     openssl/evp.h \
891     openssl/md5.h \
892     openssl/md4.h \
893     openssl/sha.h \
894     openssl/ocsp.h \
895     openssl/engine.h,
896     [],
897     [
898       AC_MSG_FAILURE([failed locating OpenSSL headers])
899     ]
900   )
901   
902   AC_MSG_CHECKING([for OpenSSL version >= 0.9.7])
903   AC_EGREP_CPP(yes,
904     [#include <openssl/crypto.h>
905      #if (OPENSSL_VERSION_NUMBER >= 0x00907000L)
906      yes
907      #endif
908     ],
909     [
910       AC_MSG_RESULT(yes)
911     ],
912     [
913       AC_MSG_RESULT(no)
914       AC_MSG_FAILURE([OpenSSL version too old])
915     ]
916   )
917
918   if test "x$OPENSSL_INCLUDE_DIR" != "x"; then
919     OPENSSL_INCLUDE="-I$OPENSSL_INCLUDE_DIR -DOPENSSL_NO_KRB5"
920   else
921     OPENSSL_INCLUDE="-DOPENSSL_NO_KRB5"
922   fi
923
924   dnl #
925   dnl #  Now check that the header versions match the library
926   dnl #
927   AC_MSG_CHECKING([OpenSSL library and header version consistency])
928   AC_RUN_IFELSE(
929     [AC_LANG_PROGRAM(
930       [[
931         #include <stdio.h>
932         #include <openssl/opensslv.h>
933         #include <openssl/crypto.h>
934       ]],
935       [[
936         if (SSLeay() == OPENSSL_VERSION_NUMBER) {
937           return 0;
938         } else {
939           printf("library: %lx header: %lx... ", (unsigned long) SSLeay(), (unsigned long) OPENSSL_VERSION_NUMBER);
940           return 1;
941         }
942       ]]
943     )],
944     [
945       AC_MSG_RESULT(yes)
946     ],
947     [
948       AC_MSG_RESULT(no)
949       AC_MSG_FAILURE([OpenSSL library version does not match header version])
950     ]
951   )
952   
953   CPPFLAGS=$old_CPPFLAGS 
954   LIBS=$old_LIBS
955   LDFLAGS="$old_LDFLAGS"
956 fi
957
958 AC_SUBST(OPENSSL_INCLUDE)
959 AC_SUBST(OPENSSL_LIBS)
960 export OPENSSL_LIBS
961
962 dnl #
963 dnl #  Check the pcap includes for the RADIUS sniffer.
964 dnl #
965 if test "x$PCAP_LIBS" = x; then
966   AC_MSG_NOTICE([skipping test for pcap.h.])
967 else
968   AC_CHECK_HEADER(pcap.h,
969     [
970       AC_DEFINE(HAVE_PCAP_H, 1, [Define to 1 if you have the <pcap.h> header file.])
971       
972       AC_CHECK_LIB(pcap, pcap_fopen_offline,
973         [
974           AC_DEFINE(HAVE_PCAP_FOPEN_OFFLINE, 1, [Define to 1 if you have the function pcap_fopen_offline.])
975         ]
976       )
977       
978       AC_CHECK_LIB(pcap, pcap_dump_fopen,
979         [
980           AC_DEFINE(HAVE_PCAP_DUMP_FOPEN, 1, [Define to 1 if you have the function pcap_dump_fopen.])
981         ]
982       )
983     ],
984     [
985       PCAP_LIBS=
986       AC_MSG_WARN([pcap.h not found, silently disabling the RADIUS sniffer.])
987     ]
988   )
989 fi
990 AC_SUBST(PCAP_LIBS)
991
992 dnl #############################################################
993 dnl #
994 dnl #  4. Checks for typedefs
995 dnl #
996 dnl #############################################################
997
998 dnl #
999 dnl #  Ensure that these are defined
1000 dnl #
1001 AC_TYPE_OFF_T
1002 AC_TYPE_PID_T
1003 AC_TYPE_SIZE_T
1004 AC_TYPE_UID_T
1005
1006 dnl #
1007 dnl #  Check for socklen_t
1008 dnl #
1009 FR_CHECK_TYPE_INCLUDE(
1010   [
1011     #ifdef HAVE_SYS_TYPES_H
1012     #  include <sys/types.h>
1013     #endif
1014     
1015     #ifdef HAVE_SYS_SOCKET_H
1016     #  include <sys/socket.h>
1017     #endif
1018   ],
1019   socklen_t, int, [socklen_t is generally 'int' on systems which don't use it]
1020 )
1021
1022 dnl #
1023 dnl #  Check for uint8_t
1024 dnl #
1025 FR_CHECK_TYPE_INCLUDE(
1026   [
1027     #ifdef HAVE_INTTYPES_H
1028     #  include <inttypes.h>
1029     #endif
1030   
1031     #ifdef HAVE_STDINT_H
1032     #  include <stdint.h>
1033     #endif
1034   ],
1035   uint8_t, unsigned char, [uint8_t should be the canonical 'octet' for network traffic]
1036 )
1037
1038 dnl #
1039 dnl #  Check for uint16_t
1040 dnl #
1041 FR_CHECK_TYPE_INCLUDE(
1042   [
1043     #ifdef HAVE_INTTYPES_H
1044     #  include <inttypes.h>
1045     #endif
1046
1047     #ifdef HAVE_STDINT_H
1048     #  include <stdint.h>
1049     #endif
1050   ],
1051   uint16_t, unsigned short, [uint16_t should be the canonical '2 octets' for network traffic]
1052 )
1053
1054 dnl #
1055 dnl #  Check for uint32_t
1056 dnl #
1057 FR_CHECK_TYPE_INCLUDE(
1058   [
1059     #ifdef HAVE_INTTYPES_H
1060     #  include <inttypes.h>
1061     #endif
1062
1063     #ifdef HAVE_STDINT_H
1064     #  include <stdint.h>
1065     #endif
1066   ],
1067   uint32_t, unsigned int, [uint32_t should be the canonical 'network integer']
1068 )
1069
1070 AC_CHECK_TYPE(struct in6_addr, AC_DEFINE(HAVE_STRUCT_IN6_ADDR, 1, [IPv6 address structure]), [],
1071   [
1072     #ifdef HAVE_NETINET_IN_H
1073     #  include <netinet/in.h>
1074     #endif
1075   ]
1076 )
1077
1078 AC_CHECK_TYPE(struct sockaddr_storage, AC_DEFINE(HAVE_STRUCT_SOCKADDR_STORAGE, 1, [Generic socket addresses]), [],
1079   [
1080     #ifdef HAVE_NETINET_IN_H
1081     #  include <netinet/in.h>
1082     #endif
1083
1084     #ifdef HAVE_SYS_SOCKET_H
1085     #  include <sys/socket.h>
1086     #endif
1087 ])
1088
1089 AC_CHECK_TYPE(struct sockaddr_in6, AC_DEFINE(HAVE_STRUCT_SOCKADDR_IN6, 1, [IPv6 socket addresses]), [],
1090   [
1091     #ifdef HAVE_NETINET_IN_H
1092     #  include <netinet/in.h>
1093     #endif
1094 ])
1095
1096 AC_CHECK_TYPE(struct addrinfo, AC_DEFINE(HAVE_STRUCT_ADDRINFO, 1, [Generic DNS lookups]), [],
1097   [
1098     #ifdef HAVE_SYS_TYPES_H
1099     #  include <sys/types.h>
1100     #endif
1101
1102     #ifdef HAVE_SYS_SOCKET_H
1103     #  include <sys/socket.h>
1104     #endif
1105
1106     #ifdef HAVE_NETDB_H
1107     #  include <netdb.h>
1108     #endif
1109   ]
1110 )
1111
1112 dnl #############################################################
1113 dnl #
1114 dnl #  5. Checks for structures and functions
1115 dnl #
1116 dnl #############################################################
1117 AC_CHECK_FUNCS( \
1118   getopt_long \
1119   fcntl \
1120   strsignal \
1121   sigaction \
1122   sigprocmask \
1123   pthread_sigmask \
1124   snprintf \
1125   vsnprintf \
1126   setsid \
1127   strncasecmp \
1128   strcasecmp \
1129   localtime_r \
1130   ctime_r \
1131   gmtime_r \
1132   strsep \
1133   inet_aton \
1134   inet_pton \
1135   inet_ntop \
1136   setlinebuf \
1137   setvbuf \
1138   getusershell \
1139   initgroups \
1140   getaddrinfo \
1141   getnameinfo \
1142   closefrom \
1143   gettimeofday \
1144   getpeereid \
1145   setuid \
1146   setresuid \
1147   getresuid \
1148   strlcat \
1149   strlcpy
1150 )
1151
1152 AC_TYPE_SIGNAL
1153
1154 dnl #
1155 dnl #  Check if we have utmpx.h
1156 dnl #  if so, check if struct utmpx has entry ut_xtime
1157 dnl #  if not, set it to define ut_xtime == ut_tv.tv_sec
1158 dnl #
1159 if test "x$ac_cv_header_utmpx_h" = "xyes"; then
1160  FR_CHECK_STRUCT_HAS_MEMBER([#include <utmpx.h>], [struct utmpx], ut_xtime)
1161  if test "x$ac_cv_type_struct_utmpx_has_ut_xtime" = "x"; then
1162    AC_DEFINE(ut_xtime, ut_tv.tv_sec, [define to something if you don't have ut_xtime in struct utmpx])
1163  fi
1164 fi
1165
1166 dnl #
1167 dnl #  struct ip_pktinfo
1168 dnl #
1169 FR_CHECK_STRUCT_HAS_MEMBER([#include <netinet/in.h>], [struct in_pktinfo], ipi_addr)
1170 if test "x$ac_cv_type_struct_in_pktinfo_has_ipi_addr" = "xyes"; then
1171   AC_DEFINE(HAVE_IP_PKTINFO, [], [define if you have IP_PKTINFO (Linux)])
1172 fi
1173
1174 dnl #
1175 dnl #  struct in6_pktinfo
1176 dnl #
1177 FR_CHECK_STRUCT_HAS_MEMBER([#include <netinet/in.h>], [struct in6_pktinfo], ipi6_addr)
1178 if test "x$ac_cv_type_struct_in6_pktinfo_has_ipi6_addr" = "xyes"; then
1179   AC_DEFINE(HAVE_IN6_PKTINFO, [], [define if you have IN6_PKTINFO (Linux)])
1180 fi
1181
1182 dnl #############################################################
1183 dnl #
1184 dnl #  6. Checks for compiler characteristics
1185 dnl #
1186 dnl #############################################################
1187
1188 dnl #
1189 dnl #  Ensure that these are defined
1190 dnl #
1191 AC_C_CONST
1192
1193 dnl #
1194 dnl #  See if this is OS/2
1195 dnl #
1196 AC_MSG_CHECKING([type of OS])
1197 OS=`uname -s`
1198 AC_MSG_RESULT($OS)
1199 if test "$OS" = "OS/2"; then
1200   LIBPREFIX=
1201 else
1202   LIBPREFIX=lib
1203 fi
1204 AC_SUBST(LIBPREFIX)
1205
1206 if test "x$developer" = "xyes"; then
1207   AC_MSG_NOTICE([Setting additional developer CFLAGS])
1208   
1209   dnl #
1210   dnl #  Tell the compiler to parse doxygen documentation and verify it against function and variable declarations
1211   dnl #
1212   AX_CC_WDOCUMENTATION_FLAG
1213   if test "x$ax_cv_cc_wdocumentation_flag" = "xyes"; then
1214     devflags="-Wdocumentation"
1215   fi
1216
1217   if test "x$GCC" = "xyes"; then
1218     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"
1219     INSTALLSTRIP=""
1220   fi
1221   
1222   AC_MSG_NOTICE([Developer CFLAGS are "$devflags"])
1223   
1224   CFLAGS="$CFLAGS $devflags"
1225   dnl #
1226   dnl #  Enable experimental modules (we want to know if code changes breaks one of them)
1227   dnl #
1228   if test "x$EXPERIMENTAL" != "xno"; then
1229     AC_MSG_NOTICE([is developer build, enabling experimental modules implicitly, disable with --without-experimental-modules])
1230     EXPERIMENTAL=yes
1231   fi
1232 else
1233   devflags=""
1234   CFLAGS="$CFLAGS -DNDEBUG"
1235   INSTALLSTRIP=""
1236   AC_MSG_RESULT([no.])
1237 fi
1238
1239 export EXPERIMENTAL
1240
1241 dnl #
1242 dnl #  append the current git hash onto the version string
1243 dnl #
1244 if test -d $srcdir/.git -a "x$GIT" = "xyes"; then
1245   RADIUSD_VERSION_COMMIT=`git log --pretty=format:'%h' -n 1`
1246   AC_DEFINE_UNQUOTED([RADIUSD_VERSION_COMMIT],["${RADIUSD_VERSION_COMMIT}"],[Commit HEAD at time of configuring])
1247 fi
1248
1249 FR_TLS
1250
1251 dnl #############################################################
1252 dnl #
1253 dnl #  7. Checks for library functions
1254 dnl #
1255 dnl #############################################################
1256
1257 dnl Check for talloc
1258 dnl extra argument: --with-talloc-include-dir=DIR
1259 talloc_include_dir=
1260 AC_ARG_WITH(talloc-include-dir,
1261   [AS_HELP_STRING([--with-talloc-include-dir=DIR],
1262   [Directory where the talloc includes may be found])],
1263   [case "$withval" in
1264     no)
1265       AC_MSG_ERROR([Need talloc-include-dir])
1266       ;;
1267     yes)
1268       ;;
1269     *)
1270       talloc_include_dir="$withval"
1271       ;;
1272   esac])
1273
1274 dnl #
1275 dnl # Check for talloc header files
1276 dnl #
1277 smart_try_dir="$talloc_include_dir"
1278 FR_SMART_CHECK_INCLUDE([talloc.h])
1279 if test "x$ac_cv_header_talloc_h" != "xyes"; then
1280   AC_MSG_WARN([talloc headers not found. Use --with-talloc-include-dir=<path>.])
1281   AC_MSG_ERROR([FreeRADIUS requires libtalloc])
1282 else
1283   INCLUDE="${SMART_CFLAGS} ${INCLUDE}"
1284   LIBS="-ltalloc ${LIBS}"
1285 fi
1286
1287 dnl #
1288 dnl # Check for libcrypt
1289 dnl # We use crypt(3) which may be in libc, or in libcrypt (eg FreeBSD)
1290 dnl #
1291 AC_CHECK_LIB(crypt, crypt,
1292   CRYPTLIB="-lcrypt"
1293 )
1294
1295 if test "$CRYPTLIB" != ""; then
1296   AC_DEFINE(HAVE_CRYPT, [], [Do we have the crypt function])
1297 else
1298   AC_CHECK_FUNC(crypt, AC_DEFINE(HAVE_CRYPT, [], [Do we have the crypt function]))
1299 fi
1300
1301 dnl Check for libcipher
1302 AC_CHECK_LIB(cipher, setkey,
1303    CRYPTLIB="${CRYPTLIB} -lcipher"
1304 )
1305 AC_SUBST(CRYPTLIB)
1306
1307 dnl #
1308 dnl #  Check the style of gethostbyaddr, in order of preference
1309 dnl #  GNU (_r eight args)
1310 dnl #
1311 AC_DEFINE(GNUSTYLE, [1], [GNU-Style get*byaddr_r])
1312
1313 dnl #
1314 dnl #  SYSV (_r six args)
1315 dnl #
1316 AC_DEFINE(SYSVSTYLE, [2], [SYSV-Style get*byaddr_r])
1317
1318 dnl #
1319 dnl #  BSD (three args, may not be thread safe)
1320 dnl #
1321 AC_DEFINE(BSDSTYLE, [3], [BSD-Style get*byaddr_r])
1322
1323 dnl #
1324 dnl #  Tru64 has BSD version, but it is thread safe
1325 dnl #  http://h30097.www3.hp.com/docs/base_doc/DOCUMENTATION/V51B_HTML/MAN/MAN3/1739____.HTM
1326 dnl #  We need #stdio.h to define NULL on FreeBSD (at least)
1327 dnl #
1328 gethostbyaddrrstyle=""
1329 AC_MSG_CHECKING([gethostbyaddr_r() syntax])
1330 case "$host" in
1331   *-freebsd*)
1332     dnl #
1333     dnl #  With FreeBSD, check if there's a prototype for gethostbyaddr_r.
1334     dnl #  Some versions (FreeBSD 5.1?) have a symbol but no prototype - so we
1335     dnl #  override this test to BSDSTYLE. FreeBSD 6.2 and up have proper GNU
1336     dnl #  style support.
1337     dnl #
1338     AC_CHECK_DECLS([gethostbyaddr_r], [],
1339       [
1340         AC_DEFINE(GETHOSTBYADDRRSTYLE, BSDSTYLE,
1341           [style of gethostbyaddr_r functions ])
1342         gethostbyaddrrstyle=BSD
1343         AC_MSG_WARN([FreeBSD overridden to BSD-style])
1344       ], 
1345       [
1346         #ifdef HAVE_NETDB_H
1347         #include <netdb.h>
1348         #endif
1349       ])
1350     ;;
1351 esac
1352
1353 if test "x$gethostbyaddrrstyle" = "x"; then
1354   AC_TRY_LINK(
1355     [
1356       #include <stdio.h>
1357       #include <netdb.h>
1358     ],
1359     [ gethostbyaddr_r(NULL, 0, 0, NULL, NULL, 0, NULL, NULL) ],
1360     [
1361       AC_DEFINE(GETHOSTBYADDRRSTYLE, GNUSTYLE, [style of gethostbyaddr_r functions ])
1362       gethostbyaddrrstyle=GNU
1363     ]
1364   )
1365 fi
1366
1367 if test "x$gethostbyaddrrstyle" = "x"; then
1368   AC_TRY_LINK(
1369     [
1370       #include <stdio.h>
1371       #include <netdb.h>
1372     ],
1373     [ gethostbyaddr_r(NULL, 0, 0, NULL, NULL, 0, NULL) ] ,
1374     [
1375       AC_DEFINE(GETHOSTBYADDRRSTYLE, SYSVSTYLE, [style of gethostbyaddr_r functions ])
1376       gethostbyaddrrstyle=SYSV
1377     ]
1378   )
1379 fi
1380
1381
1382 if test "x$gethostbyaddrrstyle" = "x"; then
1383   AC_TRY_LINK(
1384     [
1385       #include <stdio.h>
1386       #include <netdb.h>
1387     ],
1388     [ gethostbyaddr(NULL, 0, 0)  ],
1389     [
1390       AC_DEFINE(GETHOSTBYADDRRSTYLE, BSDSTYLE, [style of gethostbyaddr_r functions ])
1391       gethostbyaddrrstyle=BSD
1392     ]
1393   )
1394 fi
1395
1396 if test "x$gethostbyaddrrstyle" = "x"; then
1397   AC_MSG_RESULT([none!  It must not exist, here.])
1398 else
1399   AC_MSG_RESULT([${gethostbyaddrrstyle}-style])
1400 fi
1401
1402 if test "x$gethostbyaddrrstyle" = "xBSD"; then
1403   AC_MSG_WARN([ ****** BSD-style gethostbyaddr might NOT be thread-safe! ****** ])
1404 fi
1405
1406 dnl #
1407 dnl #  Check the style of gethostbyname, in order of preference
1408 dnl #  GNU (_r seven args)
1409 dnl #  SYSV (_r five args)
1410 dnl #  BSD (two args, may not be thread safe)
1411 dnl #  Tru64 has BSD version, but it _is_ thread safe
1412 dnl #    http://h30097.www3.hp.com/docs/base_doc/DOCUMENTATION/V51B_HTML/MAN/MAN3/1946____.HTM
1413 dnl #  We need #stdio.h to define NULL on FreeBSD (at least)
1414 dnl #
1415 gethostbynamerstyle=""
1416 AC_MSG_CHECKING([gethostbyname_r() syntax])
1417 AC_TRY_LINK(
1418   [
1419     #include <stdio.h>
1420     #include <netdb.h>
1421   ],
1422   [ gethostbyname_r(NULL, NULL, NULL, 0, NULL, NULL) ],
1423   [
1424     AC_DEFINE(GETHOSTBYNAMERSTYLE, GNUSTYLE, [style of gethostbyname_r functions ])
1425     gethostbynamerstyle=GNU
1426   ]
1427 )
1428
1429 if test "x$gethostbynamerstyle" = "x"; then
1430   AC_TRY_LINK(
1431     [
1432       #include <stdio.h>
1433       #include <netdb.h>
1434     ],
1435     [ gethostbyname_r(NULL, NULL, NULL, 0, NULL) ] ,
1436     [
1437       AC_DEFINE(GETHOSTBYNAMERSTYLE, SYSVSTYLE, [style of gethostbyname_r functions ])
1438       gethostbynamerstyle=SYSV
1439     ]
1440   )
1441 fi
1442
1443 if test "x$gethostbynamerstyle" = "x"; then
1444   AC_TRY_LINK(
1445     [
1446       #include <stdio.h>
1447       #include <netdb.h>
1448     ],
1449     [ gethostbyname(NULL) ],
1450     [
1451       AC_DEFINE(GETHOSTBYNAMERSTYLE, BSDSTYLE, [style of gethostbyname_r functions ])
1452       gethostbynamerstyle=BSD
1453     ]
1454   )
1455 fi
1456
1457 if test "x$gethostbynamerstyle" = "x"; then
1458   AC_MSG_RESULT([none!  It must not exist, here.])
1459 else
1460   AC_MSG_RESULT([${gethostbynamerstyle}-style])
1461 fi
1462
1463 if test "x$gethostbynamerstyle" = "xBSD"; then
1464   AC_MSG_WARN([ ****** BSD-style gethostbyname might NOT be thread-safe! ****** ])
1465 fi
1466
1467 dnl #
1468 dnl #  Check for non-posix solaris ctime_r (extra buflen int arg)
1469 dnl #
1470 AC_DEFINE(POSIXSTYLE, [1], [Posix-Style ctime_r])
1471 AC_DEFINE(SOLARISSTYLE, [2], [Solaris-Style ctime_r])
1472 ctimerstyle=""
1473 AC_MSG_CHECKING([ctime_r() syntax])
1474 AC_TRY_LINK(
1475   [
1476     #include <time.h>
1477   ],
1478   [ ctime_r(NULL, NULL, 0) ],
1479   [
1480     AC_DEFINE(CTIMERSTYLE, SOLARISSTYLE, [style of ctime_r function])
1481     ctimerstyle="SOLARIS"
1482   ]
1483 )
1484
1485 if test "x$ctimerstyle" = "x"; then
1486   AC_TRY_LINK(
1487     [
1488       #include <time.h>
1489     ],
1490     [ ctime_r(NULL, NULL) ],
1491     [
1492       AC_DEFINE(CTIMERSTYLE, POSIXSTYLE, [style of ctime_r function])
1493       ctimerstyle="POSIX"
1494     ]
1495   )
1496 fi
1497
1498 if test "x$ctimerstyle" = "x"; then
1499     AC_MSG_RESULT([none!  It must not exist, here.])
1500 else
1501     AC_MSG_RESULT([${ctimerstyle}-style])
1502 fi
1503
1504 AC_SUBST(HOSTINFO, $host)
1505
1506 dnl #############################################################
1507 dnl #
1508 dnl #  8. Checks for system services
1509 dnl #
1510 dnl #############################################################
1511
1512 dnl #
1513 dnl #  Figure out where libtool is located,
1514 dnl #
1515 top_builddir=`pwd`
1516 export top_builddir
1517 AC_MSG_RESULT([top_builddir=$top_builddir])
1518 dnl #  AC_SUBST(top_builddir)
1519
1520 dnl #
1521 dnl #  import libtool stuff
1522 dnl #
1523 dnl #############################################################
1524 dnl #
1525 dnl #  Configure in any module directories.
1526 dnl #
1527 dnl #############################################################
1528
1529 dnl ############################################################
1530 dnl #  Remove any conflicting definitions if autoconf.h
1531 dnl #  is being included by a module.
1532 dnl #############################################################
1533 AH_BOTTOM([#include <freeradius-devel/automask.h>])
1534
1535 dnl ############################################################
1536 dnl #  make modules by list
1537 dnl #############################################################
1538 if test "x$EXPERIMENTAL" = "xyes"; then
1539   for foo in `ls -1 "${srcdir}"/src/modules | grep rlm_`; do
1540     MODULES="$MODULES $foo"
1541   done
1542 else
1543    dnl #
1544    dnl #  make ONLY the stable modules
1545    dnl #
1546    for foo in `cat "${srcdir}"/src/modules/stable`; do
1547       MODULES="$MODULES $foo"
1548    done
1549 fi
1550
1551 dnl ############################################################
1552 dnl #  Add autoconf subdirs, based on the module list we
1553 dnl #  previously created.
1554 dnl #############################################################
1555 mysubdirs=""
1556 for bar in $MODULES; do
1557   if test -f "${srcdir}"/src/modules/$bar/configure; then
1558     mysubdirs="$mysubdirs src/modules/$bar"
1559   fi
1560 done
1561
1562 dnl #
1563 dnl #  Don't change the variable name here.  Autoconf goes bonkers
1564 dnl #  if you do.
1565 dnl #
1566 AC_CONFIG_SUBDIRS($mysubdirs)
1567 AC_SUBST(MODULES)
1568
1569 dnl #############################################################
1570 dnl #
1571 dnl #  Add -Werror last, so it doesn't interfere with autoconf's
1572 dnl #  test programs.
1573 dnl #
1574 dnl #############################################################
1575 if test "x$werror" == "xyes"; then
1576   CFLAGS="-Werror $CFLAGS"
1577 fi  
1578
1579 dnl #############################################################
1580 dnl #
1581 dnl #  And finally, output the results.
1582 dnl #
1583 dnl #############################################################
1584 AC_CONFIG_COMMANDS([stamp-h], [echo timestamp > src/include/stamp-h])
1585 AC_CONFIG_COMMANDS([build-radpaths-h], [(cd ./src/include && /bin/sh ./build-radpaths-h)])
1586 AC_CONFIG_COMMANDS([main-chmod], [(cd ./src/main && chmod +x checkrad radlast radtest)])
1587 AC_CONFIG_COMMANDS([scripts-chmod], [(cd ./scripts && chmod +x rc.radiusd radiusd.cron.daily radiusd.cron.monthly cryptpasswd)])
1588
1589 dnl #
1590 dnl #  Substitute whatever libraries we found to be necessary
1591 dnl #
1592 AC_SUBST(LIBS)
1593 AC_SUBST(INSTALLSTRIP)
1594
1595 USE_SHARED_LIBS=$enable_shared
1596 AC_SUBST(USE_SHARED_LIBS)
1597 USE_STATIC_LIBS=$enable_static
1598 AC_SUBST(USE_STATIC_LIBS)
1599 AC_SUBST(STATIC_MODULES)
1600
1601 AC_OUTPUT(\
1602   ./Make.inc \
1603   ./src/include/build-radpaths-h \
1604   ./src/main/radsniff.mk \
1605   ./src/main/checkrad \
1606   ./src/main/radlast \
1607   ./src/main/radtest \
1608   ./scripts/rc.radiusd \
1609   ./scripts/radiusd.cron.daily \
1610   ./scripts/radiusd.cron.monthly \
1611   ./scripts/cryptpasswd \
1612   ./raddb/dictionary \
1613   ./raddb/radrelay.conf \
1614   ./raddb/radiusd.conf
1615 )