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