Protect pcap_fopen calls
[freeradius.git] / configure.in
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 AC_INIT(src/main/radiusd.c)
26 AC_CONFIG_HEADER(src/include/autoconf.h)
27 AC_REVISION($Revision$)dnl
28
29 dnl # The version of the software
30 RADIUSD_VERSION=`cat VERSION`
31 RADIUSD_MAJOR_VERSION=`cat VERSION | sed 's/\..*//'`
32 RADIUSD_MINOR_VERSION=`cat VERSION | sed 's/^2\.//'`
33 PACKAGE=freeradius
34
35 dnl #############################################################
36 dnl #
37 dnl #  0. Checks for compiler, libtool, and command line options.
38 dnl #
39 dnl #############################################################
40
41 dnl Check for GNU cc
42 AC_PROG_CC
43 AC_PROG_CXX
44
45 dnl #
46 dnl # check for AIX, to allow us to use some BSD functions
47 dnl # must be before macros that call the compiler.
48 dnl #
49 AC_AIX
50
51 AC_PROG_GCC_TRADITIONAL
52 AC_PROG_CC_SUNPRO
53 AC_PROG_RANLIB
54
55 dnl Compile in large (2G+) file support.
56 AC_SYS_LARGEFILE
57
58 dnl # check for system bytesex
59 dnl # AC_DEFINES WORDS_BIGENDIAN
60 AC_C_BIGENDIAN
61
62 dnl Find GNU Make.
63 AC_CHECK_PROG(GMAKE, gmake, yes, no)
64 if test $GMAKE = no; then
65   AC_PATH_PROG(MAKE, make, /usr/local/bin/make)
66 else
67   AC_PATH_PROG(MAKE, gmake, /usr/local/gnu/bin/make)
68 fi
69 makever=`$ac_cv_path_MAKE --version 2>&1 | grep "GNU Make"`
70 if test -z "$makever"; then
71   AC_MSG_ERROR(GNU Make is not installed.  Please download and install it
72                 from ftp://prep.ai.mit.edu/pub/gnu/make/ before continuing.)
73 fi
74
75 AC_ARG_WITH(system-libltdl,
76 [  --with-system-libltdl   Use the libltdl installed in your system (default=use our own)],
77 [
78 LIBLTDL="-lltdl"
79 INCLTDL=
80 LTDL_SUBDIRS=
81 enable_ltdl_install=no
82 ],
83 [
84 dnl If libltdl isn't installable, set it to be installable.
85 [test x"$enable_ltdl_install" = x && enable_ltdl_install=yes]
86 AC_LIBLTDL_INSTALLABLE
87
88 dnl tell Makefile to build ltdl if needed
89 if test x"$enable_ltdl_install" = x"yes"; then
90   LTDL_SUBDIRS=libltdl
91 fi
92 ])
93 AC_SUBST(LTDL_SUBDIRS)
94
95 dnl use system-wide libtool, if it exists
96 AC_ARG_WITH(system-libtool,
97 [  --with-system-libtool   Use the libtool installed in your system (default=use our own)],
98 [ AC_PATH_PROG(LIBTOOL, libtool,,$PATH:/usr/local/bin) ],
99 [
100   LIBTOOL="`pwd`/libtool"
101   AC_SUBST(LIBTOOL)
102   dnl ensure that we're looking for dlopen
103   AC_LIBTOOL_DLOPEN
104
105   dnl Figure out how to build shared libraries
106   AC_PROG_LIBTOOL
107 ])
108
109
110 dnl Put this in later, when all distributed modules use autoconf.
111 dnl AC_ARG_WITH(disablemodulefoo,
112 dnl [  --without-rlm_foo       Disables module compilation.  Module list:]
113 dnl esyscmd([find src/modules -type d -name rlm_\* -print |\
114 dnl     sed -e 's%src/modules/.*/% (sub)- %; s%.*/%- %' |\
115 dnl     awk '{print "                            "$0}']))
116
117 AC_ARG_ENABLE(strict-dependencies,
118 [  --enable-strict-dependencies  Fail configure on lack of module dependancy.])
119
120 dnl extra argument: --with-docdir
121 docdir='${datadir}/doc/freeradius'
122 AC_MSG_CHECKING(docdir)
123 AC_ARG_WITH(docdir,
124 [  --with-docdir=DIR       Directory for documentation [DATADIR/doc/freeradius] ],
125 [ case "$withval" in
126     no)
127         docdir=no
128         ;;
129     yes)
130         ;;
131     [[\\/$]]* | ?:[[\\/]]* )
132         docdir="$withval"
133         ;;
134     *)
135         AC_MSG_ERROR([expected an absolute directory name for --with-docdir: $withval])
136         ;;
137   esac ]
138 )
139 AC_SUBST(docdir)
140 AC_MSG_RESULT($docdir)
141 if test "x$docdir" = xno; then
142         AC_MSG_WARN(Documentation files will NOT be installed.)
143 fi
144
145 dnl extra argument: --with-logdir
146 logdir='${localstatedir}/log/radius'
147 AC_MSG_CHECKING(logdir)
148 AC_ARG_WITH(logdir,
149 [  --with-logdir=DIR       Directory for logfiles [LOCALSTATEDIR/log/radius] ],
150 [ case "$withval" in
151     no)
152         AC_MSG_ERROR(Need logdir)
153         ;;
154     yes)
155         ;;
156     [[\\/$]]* | ?:[[\\/]]* )
157         logdir="$withval"
158         ;;
159     *)
160         AC_MSG_ERROR([expected an absolute directory name for --with-logdir: $withval])
161         ;;
162   esac ]
163 )
164 AC_SUBST(logdir)
165 AC_MSG_RESULT($logdir)
166
167 dnl extra argument: --with-radacctdir
168 radacctdir='${logdir}/radacct'
169 AC_MSG_CHECKING(radacctdir)
170 AC_ARG_WITH(radacctdir,
171 [  --with-radacctdir=DIR   Directory for detail files [LOGDIR/radacct] ],
172 [ case "$withval" in
173     no)
174         AC_MSG_ERROR(Need radacctdir)
175         ;;
176     yes)
177         ;;
178     [[\\/$]]* | ?:[[\\/]]* )
179         radacctdir="$withval"
180         ;;
181     *)
182         AC_MSG_ERROR([expected an absolute directory name for --with-radacctdir: $withval])
183         ;;
184   esac ]
185 )
186 AC_SUBST(radacctdir)
187 AC_MSG_RESULT($radacctdir)
188
189 dnl extra argument: --with-raddbdir
190 raddbdir='${sysconfdir}/raddb'
191 AC_MSG_CHECKING(raddbdir)
192 AC_ARG_WITH(raddbdir,
193 [  --with-raddbdir=DIR     Directory for config files [SYSCONFDIR/raddb] ],
194 [ case "$withval" in
195     no)
196         AC_MSG_ERROR(Need raddbdir)
197         ;;
198     yes)
199         ;;
200     [[\\/$]]* | ?:[[\\/]]* )
201         raddbdir="$withval"
202         ;;
203     *)
204         AC_MSG_ERROR([expected an absolute directory name for --with-raddbdir: $withval])
205         ;;
206   esac ]
207 )
208 AC_SUBST(raddbdir)
209 AC_MSG_RESULT($raddbdir)
210
211 dnl extra argument: --with-ascend-binary
212 ASCEND_BINARY=yes
213 AC_ARG_WITH(ascend-binary,
214 [  --with-ascend-binary    Include support for Ascend binary filter attributes (default=yes)],
215 [ case "$withval" in
216     yes)
217         ;;
218     *)
219         ASCEND_BINARY=""
220   esac ]
221 )
222 if test "X$ASCEND_BINARY" = "Xyes"; then
223   AC_DEFINE(ASCEND_BINARY, [], [Include support for Ascend binary filter attributes])
224 fi
225
226 dnl extra argument: --with-threads
227 WITH_THREADS=yes
228 AC_ARG_WITH(threads,
229 [  --with-threads          Use threads, if available.  (default=yes) ],
230 [ case "$withval" in
231     yes)
232         ;;
233     *)
234         WITH_THREADS=""
235   esac ]
236 )
237
238 dnl extra argument: --with-vmps
239 WITH_VMPS=yes
240 AC_ARG_WITH(vmps,
241 [  --with-vmps             Compile in VMPS support. (default=yes)],
242 [ case "$withval" in
243     yes)
244         ;;
245     *)
246         WITH_VMPS=no
247   esac ]
248 )
249 if test "x$WITH_VMPS" = "xyes"; then
250         AC_DEFINE(WITH_VMPS, [1], [define if you want VMPS support])
251 fi
252
253 dnl extra argument: --with-dhcp
254 AC_ARG_WITH(dhcp,
255 [  --with-dhcp             Compile in DHCP support. (default=no)],
256 [ case "$withval" in
257     yes)
258         AC_DEFINE(WITH_DHCP, [1], [Include experimental support for DHCP])
259         ;;
260     *)
261         ;;
262   esac ]
263 )
264
265
266 dnl #
267 dnl #  Allow the user to specify a list of modules to be linked
268 dnl #  statically to the server.
269 dnl #
270 STATIC_MODULES=
271 AC_ARG_WITH(static_modules,
272 [  --with-static-modules=QUOTED-MODULE-LIST],[
273   for i in $withval; do
274     STATIC_MODULES="$STATIC_MODULES -dlpreopen ../modules/rlm_$i/rlm_$i.la"
275   done
276 ])
277
278 MODULES=
279 AC_ARG_WITH(modules,
280 [ --with-modules=QUOTED-MODULE-LIST],[
281  for i in $withval; do
282    MODULES="$MODULES $i"
283  done
284 ])
285
286 dnl #
287 dnl #  Enable developer C compiler warnings
288 dnl #
289 AC_ARG_ENABLE(developer,
290 [  --enable-developer               Enables features of interest to developers.],
291 [ case "$enableval" in
292     no)
293         developer=no
294         ;;
295     *)
296         developer=yes
297   esac ]
298 )
299
300 if test "x$developer" != "xno" -a -d $srcdir/CVS; then
301   dnl turn on the developer flag when taken from a CVS checkout (not a release)
302   developer="yes"
303 fi
304
305 if test "x$developer" != "xno" -a -d $srcdir/.git; then
306   dnl turn on the developer flag when taken from a git checkout (not a release)
307   developer="yes"
308 fi
309
310 dnl extra argument: --with-experimental-modules
311 EXPERIMENTAL=
312 AC_ARG_WITH(experimental-modules,
313 [  --with-experimental-modules      Use experimental and unstable modules. (default=no) ],
314 [ case "$withval" in
315     yes)
316         EXPERIMENTAL=yes
317         ;;
318     *)
319   esac ]
320 )
321
322 dnl extra argument: --with-openssl
323 WITH_OPENSSL=yes
324 AC_ARG_WITH(openssl,
325 [  --with-openssl                   Use OpenSSL. (default=yes)],
326 [ case "$withval" in
327     no)
328         WITH_OPENSSL=no
329         ;;
330     *)
331         WITH_OPENSSL=yes
332         ;;
333   esac ]
334 )
335
336 dnl #
337 dnl # extra argument: --with-openssl-includes=dir
338 dnl #
339 OPENSSL_INCLUDE_DIR=
340 AC_ARG_WITH(openssl-includes,
341 [  --with-openssl-includes=DIR      Directory to look for OpenSSL include files],
342 [ case "$withval" in
343     *) OPENSSL_INCLUDE_DIR="$withval"
344         ;;
345   esac ]
346 )
347
348 dnl #
349 dnl # extra argument: --with-openssl-libraries=dir
350 dnl #
351 OPENSSL_LIB_DIR=
352 AC_ARG_WITH(openssl-libraries,
353 [  --with-openssl-libraries=DIR     Directory to look for OpenSSL library files],
354 [ case "$withval" in
355     *) OPENSSL_LIB_DIR="$withval"
356         ;;
357   esac ]
358 )
359
360 dnl #
361 dnl #  These next two arguments don't actually do anything.  They're
362 dnl #  place holders so that the top-level configure script can tell
363 dnl #  the user how to configure lower-level modules
364 dnl #
365
366 dnl #
367 dnl # extra argument: --with-rlm-FOO-lib-dir
368 dnl #
369 AC_ARG_WITH(rlm-FOO-lib-dir,
370 [  --with-rlm-FOO-lib-dir=DIR       Directory to look for library files used by module FOO],
371 [ case "$withval" in
372     *)
373         ;;
374   esac ]
375 )
376
377 dnl #
378 dnl # extra argument: --with-rlm-FOO-include-dir
379 dnl #
380 AC_ARG_WITH(rlm-FOO-include-dir,
381 [  --with-rlm-FOO-include-dir=DIR   Directory to look for include files used by module FOO],
382 [ case "$withval" in
383     *)
384         ;;
385   esac ]
386 )
387
388 dnl See what include-style is used by the make program.
389 dnl AC_MSG_CHECKING(include style for make)
390 dnl echo "include /dev/null" > testmake.$$
391 dnl echo "all:" >> testmake.$$
392 dnl make -f testmake.$$ >/dev/null 2>&1
393 dnl if test $? = 0
394 dnl then
395 dnl     INCLUDE=include
396 dnl     IQUOTE=
397 dnl else
398 dnl     INCLUDE=.include
399 dnl     IQUOTE='"'
400 dnl fi
401 dnl rm -f testmake.$$
402 dnl AC_MSG_RESULT(" $INCLUDE")
403 dnl AC_SUBST(INCLUDE)
404 dnl AC_SUBST(IQUOTE)
405
406 dnl extra argument: --with-udpfromto
407 WITH_UDPFROMTO=no
408 AC_ARG_WITH(udpfromto,
409 [  --with-udpfromto        Compile in UDPFROMTO support. (default=no)],
410 [ case "$withval" in
411     yes)
412         WITH_UDPFROMTO=yes
413         ;;
414     *)
415         WITH_UDPFROMTO=no
416   esac ]
417 )
418
419 if test "x$WITH_UDPFROMTO" = "xyes"; then
420         AC_DEFINE(WITH_UDPFROMTO, [], [define if you want udpfromto])
421 fi
422
423 dnl #############################################################
424 dnl #
425 dnl #  1. Checks for programs
426 dnl #
427 dnl #############################################################
428
429 CHECKRAD=checkrad.pl
430 AC_PATH_PROG(PERL, perl, /usr/local/bin/perl)
431 if test "x$ac_cv_path_PERL" = "x"; then
432   AC_MSG_WARN(perl not found - Simultaneous-Use and checkrad.pl may not work)
433 fi
434 AC_PATH_PROG(SNMPGET, snmpget)
435 if test "x$ac_cv_path_SNMPGET" = "x"; then
436   AC_MSG_WARN(snmpget not found - Simultaneous-Use and checkrad.pl may not work)
437 fi
438
439 AC_PATH_PROG(SNMPWALK, snmpwalk)
440 if test "x$ac_cv_path_SNMPWALK" = "x"; then
441   AC_MSG_WARN(snmpwalk not found - Simultaneous-Use and checkrad.pl may not work)
442 fi
443
444 AC_PATH_PROG(RUSERS, rusers, /usr/bin/rusers)
445
446 dnl FIXME This is truly gross.
447 missing_dir=`cd $ac_aux_dir && pwd`
448 AM_MISSING_PROG(ACLOCAL, aclocal, $missing_dir)
449 AM_MISSING_PROG(AUTOCONF, autoconf, $missing_dir)
450 AM_MISSING_PROG(AUTOHEADER, autoheader, $missing_dir)
451
452 AC_PATH_PROG(LOCATE,locate)
453 AC_PATH_PROG(DIRNAME,dirname)
454 AC_PATH_PROG(GREP,grep)
455
456 dnl #############################################################
457 dnl #
458 dnl #  2. Checks for libraries
459 dnl #
460 dnl #############################################################
461
462 dnl If using pthreads, check for -lpthread (posix) or -lc_r (*BSD)
463 old_CFLAGS=$CFLAGS
464 if test "x$WITH_THREADS" = "xyes"; then
465   if test $ac_cv_prog_suncc = "yes"; then
466     CFLAGS="$CFLAGS -mt"
467   fi
468
469   AC_CHECK_HEADERS(pthread.h, [], [ WITH_THREADS="no" ])
470
471 dnl #
472 dnl # pthread stuff is usually in -lpthread
473 dnl # or in -lc_r, on *BSD
474 dnl #
475 dnl # On Some systems, we need extra pre-processor flags, to get them to
476 dnl # to do the threading properly.
477 dnl #
478   AC_CHECK_LIB(pthread, pthread_create,
479                 [ CFLAGS="$CFLAGS -D_REENTRANT -D_POSIX_PTHREAD_SEMANTICS"
480                   LIBS="$LIBS -lpthread" ],
481                 AC_CHECK_LIB(c_r, pthread_create,
482                             [ CFLAGS="$CFLAGS -pthread -D_THREAD_SAFE" ],
483                             [ WITH_THREADS="no" ]
484                             )
485                 )
486 fi
487
488 dnl #
489 dnl # If we have NO pthread libraries, remove any knowledge of threads.
490 dnl #
491 if test "x$WITH_THREADS" != "xyes"; then
492   CFLAGS=$old_CFLAGS
493   ac_cv_header_pthread_h="no"
494   WITH_THREADS=no
495 else
496   dnl #
497   dnl #  We need sem_init() and friends, as they're the friendliest
498   dnl #  semaphore functions for threading.
499   dnl #
500   dnl # HP/UX requires linking with librt, too, to get the sem_* symbols.
501   dnl # Some systems have them in -lsem
502   dnl # Solaris has them in -lposix4
503   dnl # NetBSD has them in -lsemaphore
504
505   AC_SEARCH_LIBS(sem_init, pthread sem posix4 rt semaphore,
506         [],
507         [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)]
508    )
509 fi
510
511 dnl Check if we need -lsocket
512 AC_CHECK_LIB(socket, getsockname)
513
514 dnl Check for -lresolv
515 dnl This library may be needed later.
516 AC_CHECK_LIB(resolv, inet_aton)
517
518 dnl Check if we need -lnsl. Usually if we want to
519 dnl link against -lsocket we need to include -lnsl as well.
520 AC_CHECK_LIB(nsl, inet_ntoa)
521
522 dnl Check for OpenSSL libraries.
523 OPENSSL_LIBS=
524 if test "x$WITH_OPENSSL" = xyes; then
525   old_LIBS=$LIBS
526   old_LDFLAGS="$LDFLAGS"
527   if test "x$OPENSSL_LIB_DIR" != "x"; then
528     LDFLAGS="$LDFLAGS -L$OPENSSL_LIB_DIR"
529   fi
530   AC_CHECK_LIB(crypto, DH_new,
531     [
532         LIBS="-lcrypto $LIBS"
533         AC_DEFINE(HAVE_LIBCRYPTO, 1,
534             [Define to 1 if you have the `crypto' library (-lcrypto).])
535         AC_CHECK_LIB(ssl, SSL_new,
536             [
537                 AC_DEFINE(HAVE_LIBSSL, 1,
538                     [Define to 1 if you have the `ssl' library (-lssl).])
539                 if test "x$OPENSSL_LIB_DIR" != "x"; then
540                     OPENSSL_LIBS="-L$OPENSSL_LIB_DIR"
541                 fi
542                 OPENSSL_LIBS="$OPENSSL_LIBS -lcrypto -lssl -lcrypto"
543             ], [])
544     ], [])
545   LIBS=$old_LIBS
546   LDFLAGS="$old_LDFLAGS"
547 fi
548
549 AC_CHECK_LIB(ws2_32, htonl)
550
551 dnl Check the pcap library for the RADIUS sniffer.
552 PCAP_LIBS=
553 AC_CHECK_LIB(pcap, pcap_open_live,
554         [ PCAP_LIBS="-lpcap"
555         AC_DEFINE(HAVE_LIBPCAP, 1,
556                 [Define to 1 if you have the `pcap' library (-lpcap).])
557         ],
558         [ AC_MSG_WARN([pcap library not found, silently disabling the RADIUS sniffer.]) ])
559
560 AC_LIB_READLINE
561
562 dnl #############################################################
563 dnl #
564 dnl #  3. Checks for header files
565 dnl #
566 dnl #############################################################
567
568 dnl #
569 dnl # Interix requires us to set -D_ALL_SOURCE, otherwise
570 dnl # getopt will be #included, but won't link.  <sigh>
571 dnl #
572 dnl #
573 case "$host" in
574 *-interix*)
575         CFLAGS="$CFLAGS -D_ALL_SOURCE"
576         ;;
577 *-darwin*)
578         CFLAGS="$CFLAGS -DDARWIN"
579         LIBS="-framework DirectoryService $LIBS"
580         ;;
581 esac
582
583 AC_HEADER_DIRENT
584 AC_HEADER_STDC
585 AC_HEADER_TIME
586 AC_HEADER_SYS_WAIT
587
588 AC_CHECK_HEADERS( \
589         unistd.h \
590         crypt.h \
591         errno.h \
592         resource.h \
593         sys/resource.h \
594         getopt.h \
595         malloc.h \
596         utmp.h \
597         utmpx.h \
598         signal.h \
599         sys/select.h \
600         syslog.h \
601         inttypes.h \
602         stdint.h \
603         stdio.h \
604         netdb.h \
605         semaphore.h \
606         arpa/inet.h \
607         netinet/in.h \
608         sys/types.h \
609         sys/socket.h \
610         winsock.h \
611         sys/time.h \
612         sys/wait.h \
613         sys/security.h \
614         fcntl.h \
615         sys/fcntl.h \
616         sys/prctl.h \
617         sys/un.h \
618         glob.h \
619         prot.h \
620         pwd.h \
621         grp.h \
622         sia.h \
623         siad.h
624 )
625
626 dnl FreeBSD requires sys/socket.h before net/if.h
627 AC_CHECK_HEADERS(net/if.h, [], [],
628 [#ifdef HAVE_SYS_SOCKET_H
629 # include <sys/socket.h>
630 # endif
631 ])
632
633 REGEX=no
634 AC_CHECK_HEADER(regex.h, AC_DEFINE(HAVE_REGEX_H, [], [define this if we have the <regex.h> header file]))
635 if test "x$ac_cv_header_regex_h" = "xyes"; then
636   REGEX_EXTENDED=no
637   REGEX=yes
638   AC_EGREP_CPP(yes,
639     [#include <regex.h>
640      #ifdef REG_EXTENDED
641        yes
642      #endif
643      ], [AC_DEFINE(HAVE_REG_EXTENDED, [], [define this if we have REG_EXTENDED (from <regex.h>)]) REGEX_EXTENDED=yes])
644 fi
645 AC_SUBST(REGEX)
646 AC_SUBST(REGEX_EXTENDED)
647
648 dnl #
649 dnl #  other checks which require headers
650 dnl #
651 if test "x$ac_cv_header_sys_security_h" = "xyes" && test "x$ac_cv_header_prot_h" = "xyes"
652 then
653   AC_DEFINE(OSFC2, [], [define if you have OSFC2 authentication])
654 fi
655
656 if test "x$ac_cv_header_sia_h" = "xyes" && test "x$ac_cv_header_siad_h" = "xyes"
657 then
658   AC_DEFINE(OSFSIA, [], [define if you have OSFSIA authentication])
659 fi
660
661 dnl Check for OpenSSL includes.
662 OPENSSL_INCLUDE="-DNO_OPENSSL"
663 if test "x$WITH_OPENSSL" = xyes; then
664   if test "x$OPENSSL_LIBS" = "x"; then
665     AC_MSG_NOTICE([skipping test for openssl/ssl.h])
666   else
667     old_CPPFLAGS=$CPPFLAGS
668     if test "x$OPENSSL_INCLUDE_DIR" != "x"; then
669         CPPFLAGS="$CPPFLAGS -I$OPENSSL_INCLUDE_DIR"
670     fi
671     dnl # stupid RedHat shit
672     CPPFLAGS="$CPPFLAGS -DOPENSSL_NO_KRB5"
673     AC_CHECK_HEADERS( \
674         openssl/ssl.h \
675         openssl/crypto.h \
676         openssl/err.h \
677         openssl/evp.h \
678         openssl/engine.h,
679         [],
680         OPENSSL_LIBS=
681     )
682     if test "x$OPENSSL_LIBS" != "x"; then
683         AC_MSG_CHECKING([for OpenSSL version >= 0.9.7])
684         AC_EGREP_CPP(yes,
685             [#include <openssl/crypto.h>
686              #if (OPENSSL_VERSION_NUMBER >= 0x00907000L)
687              yes
688              #endif
689             ], goodssl="yes")
690         if test "x$goodssl" != "xyes"; then
691             AC_MSG_RESULT(no)
692             OPENSSL_LIBS=
693         else
694             AC_MSG_RESULT(yes)
695             if test "x$OPENSSL_INCLUDE_DIR" != "x"; then
696                 OPENSSL_INCLUDE="-I$OPENSSL_INCLUDE_DIR -DOPENSSL_NO_KRB5"
697             else
698                 OPENSSL_INCLUDE="-DOPENSSL_NO_KRB5"
699             fi
700         fi
701     fi
702     CPPFLAGS=$old_CPPFLAGS
703   fi
704 fi
705 AC_SUBST(OPENSSL_INCLUDE)
706 AC_SUBST(OPENSSL_LIBS)
707 export OPENSSL_LIBS
708
709 dnl Check the pcap includes for the RADIUS sniffer.
710 if test "x$PCAP_LIBS" = x; then
711     AC_MSG_NOTICE([skipping test for pcap.h.])
712 else
713     AC_CHECK_HEADER(pcap.h,
714         AC_DEFINE(HAVE_PCAP_H, 1,
715                 [Define to 1 if you have the <pcap.h> header file.]),
716         [ PCAP_LIBS=
717         AC_MSG_WARN([pcap.h not found, silently disabling the RADIUS sniffer.])
718         ])
719
720     AC_CHECK_LIB(pcap, pcap_fopen_offline,
721         [ AC_DEFINE(HAVE_PCAP_FOPEN_OFFLINE, 1,
722                 [Define to 1 if you have the function pcap_fopen_offline.])
723         ])
724     AC_CHECK_LIB(pcap, pcap_dump_fopen,
725         [ AC_DEFINE(HAVE_PCAP_DUMP_FOPEN, 1,
726                 [Define to 1 if you have the function pcap_dump_fopen.])
727         ])
728 fi
729 AC_SUBST(PCAP_LIBS)
730
731 dnl #############################################################
732 dnl #
733 dnl #  4. Checks for typedefs
734 dnl #
735 dnl #############################################################
736
737 dnl #
738 dnl # Ensure that these are defined
739 dnl #
740 AC_TYPE_OFF_T
741 AC_TYPE_PID_T
742 AC_TYPE_SIZE_T
743 AC_TYPE_UID_T
744
745 dnl check for socklen_t
746 FR_CHECK_TYPE_INCLUDE([
747 #ifdef HAVE_SYS_TYPES_H
748 #include <sys/types.h>
749 #endif
750 #ifdef HAVE_SYS_SOCKET_H
751 #include <sys/socket.h>
752 #endif
753 ],socklen_t, int, [socklen_t is generally 'int' on systems which don't use it])
754
755 dnl check for uint8_t
756 FR_CHECK_TYPE_INCLUDE([
757 #ifdef HAVE_INTTYPES_H
758 #include <inttypes.h>
759 #endif
760 #ifdef HAVE_STDINT_H
761 #include <stdint.h>
762 #endif
763 ],uint8_t, unsigned char, [uint8_t should be the canonical 'octet' for network traffic])
764
765 dnl check for uint16_t
766 FR_CHECK_TYPE_INCLUDE([
767 #ifdef HAVE_INTTYPES_H
768 #include <inttypes.h>
769 #endif
770 #ifdef HAVE_STDINT_H
771 #include <stdint.h>
772 #endif
773 ],uint16_t, unsigned short, [uint16_t should be the canonical '2 octets' for network traffic])
774
775 dnl check for uint32_t
776 FR_CHECK_TYPE_INCLUDE([
777 #ifdef HAVE_INTTYPES_H
778 #include <inttypes.h>
779 #endif
780 #ifdef HAVE_STDINT_H
781 #include <stdint.h>
782 #endif
783 ],uint32_t, unsigned int, [uint32_t should be the canonical 'network integer])
784
785 AC_CHECK_TYPE(struct in6_addr, AC_DEFINE(HAVE_STRUCT_IN6_ADDR, 1, [IPv6 address structure]), [], [
786 #ifdef HAVE_NETINET_IN_H
787 #include <netinet/in.h>
788 #endif
789 ])
790
791 AC_CHECK_TYPE(struct sockaddr_storage, AC_DEFINE(HAVE_STRUCT_SOCKADDR_STORAGE, 1, [Generic socket addresses]), [], [
792 #ifdef HAVE_NETINET_IN_H
793 #include <netinet/in.h>
794 #endif
795 #ifdef HAVE_SYS_SOCKET_H
796 #include <sys/socket.h>
797 #endif
798 ])
799
800 AC_CHECK_TYPE(struct sockaddr_in6, AC_DEFINE(HAVE_STRUCT_SOCKADDR_IN6, 1, [IPv6 socket addresses]), [], [
801 #ifdef HAVE_NETINET_IN_H
802 #include <netinet/in.h>
803 #endif
804 ])
805
806 AC_CHECK_TYPE(struct addrinfo, AC_DEFINE(HAVE_STRUCT_ADDRINFO, 1, [Generic DNS lookups]), [], [
807 #ifdef HAVE_SYS_TYPES_H
808 #include <sys/types.h>
809 #endif
810 #ifdef HAVE_SYS_SOCKET_H
811 #include <sys/socket.h>
812 #endif
813 #ifdef HAVE_NETDB_H
814 #include <netdb.h>
815 #endif
816 ])
817
818 dnl #############################################################
819 dnl #
820 dnl #  5. Checks for structures and functions
821 dnl #
822 dnl #############################################################
823 AC_CHECK_FUNCS( \
824         getopt_long \
825         lockf \
826         strsignal \
827         sigaction \
828         sigprocmask \
829         pthread_sigmask \
830         snprintf \
831         vsnprintf \
832         setsid \
833         strncasecmp \
834         strcasecmp \
835         localtime_r \
836         ctime_r \
837         gmtime_r \
838         strsep \
839         inet_aton \
840         inet_pton \
841         inet_ntop \
842         setlinebuf \
843         setvbuf \
844         getusershell \
845         initgroups \
846         getaddrinfo \
847         getnameinfo \
848         closefrom \
849         gettimeofday \
850         getpeereid \
851         setuid \
852         setresuid \
853         getresuid \
854         strlcat \
855         strlcpy
856 )
857 RADIUSD_NEED_DECLARATIONS( \
858         crypt \
859         strncasecmp \
860         strcasecmp \
861         inet_aton \
862         setlinebuf \
863         getusershell \
864         endusershell
865 )
866
867 AC_TYPE_SIGNAL
868
869 dnl # check if we have utmpx.h
870 dnl # if so, check if struct utmpx has entry ut_xtime
871 dnl # if not, set it to define ut_xtime == ut_tv.tv_sec
872 if test "x$ac_cv_header_utmpx_h" = "xyes"
873 then
874  FR_CHECK_STRUCT_HAS_MEMBER([#include <utmpx.h>], [struct utmpx], ut_xtime)
875  if test "x$ac_cv_type_struct_utmpx_has_ut_xtime" = "x"
876  then
877    AC_DEFINE(ut_xtime,ut_tv.tv_sec, [define to something if you don't have ut_xtime in struct utmpx])
878  fi
879 fi
880
881 dnl # struct ip_pktinfo
882 FR_CHECK_STRUCT_HAS_MEMBER([#include <netinet/in.h>], [struct in_pktinfo], ipi_addr)
883 if test "x$ac_cv_type_struct_in_pktinfo_has_ipi_addr" = "xyes"
884 then
885         AC_DEFINE(HAVE_IP_PKTINFO, [], [define if you have IP_PKTINFO (Linux)])
886 fi
887
888 dnl # struct in6_pktinfo
889 FR_CHECK_STRUCT_HAS_MEMBER([#include <netinet/in.h>], [struct in6_pktinfo], ipi6_addr)
890 if test "x$ac_cv_type_struct_in6_pktinfo_has_ipi6_addr" = "xyes"
891 then
892         AC_DEFINE(HAVE_IN6_PKTINFO, [], [define if you have IN6_PKTINFO (Linux)])
893 fi
894
895 dnl #############################################################
896 dnl #
897 dnl #  6. Checks for compiler characteristics
898 dnl #
899 dnl #############################################################
900
901 dnl #
902 dnl # Ensure that these are defined
903 dnl #
904 AC_C_CONST
905
906 dnl #
907 dnl # See if this is OS/2
908 dnl #
909 AC_MSG_CHECKING(type of OS)
910 OS=`uname -s`
911 AC_MSG_RESULT($OS)
912 if test "$OS" = "OS/2"; then
913         LIBPREFIX=
914 else
915         LIBPREFIX=lib
916 fi
917 AC_SUBST(LIBPREFIX)
918
919 dnl #
920 dnl # Set Default CFLAGS
921 dnl #
922 if test "x$GCC" = "xyes"; then
923     CFLAGS="$CFLAGS -Wall -D_GNU_SOURCE"
924 fi
925
926 AC_MSG_CHECKING(for developer gcc flags)
927 if test "x$developer" = "xyes" -a "x$GCC" = "xyes"; then
928   devflags="-g -Wshadow -Wpointer-arith -Wcast-qual -Wcast-align -Wwrite-strings -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations -Wnested-externs -W -Wredundant-decls -Wundef"
929   CFLAGS="$CFLAGS $devflags"
930   INSTALLSTRIP=""
931   AC_MSG_RESULT(yes.  Using $devflags)
932 else
933   devflags=""
934   CFLAGS="$CFLAGS -DNDEBUG"
935   INSTALLSTRIP=""
936   AC_MSG_RESULT(no.)
937 fi
938
939 FR_TLS
940
941 dnl #############################################################
942 dnl #
943 dnl #  7. Checks for library functions
944 dnl #
945 dnl #############################################################
946
947 old_LIBS="$LIBS"
948 LIBS="$LIBS $LIBLTDL"
949 AC_CHECK_FUNC(lt_dladvise_init, AC_DEFINE(HAVE_HAVE_LT_DLADVISE_INIT, [], [Do we have the lt_dladvise_init function]))
950 LIBS="$old_LIBS"
951
952 dnl Check for libcrypt
953 dnl We use crypt(3) which may be in libc, or in libcrypt (eg FreeBSD)
954 AC_CHECK_LIB(crypt, crypt,
955   CRYPTLIB="-lcrypt"
956 )
957 if test "$CRYPTLIB" != ""; then
958   AC_DEFINE(HAVE_CRYPT, [], [Do we have the crypt function])
959 else
960   AC_CHECK_FUNC(crypt, AC_DEFINE(HAVE_CRYPT, [], [Do we have the crypt function]))
961 fi
962
963 dnl Check for libcipher
964 AC_CHECK_LIB(cipher, setkey,
965    CRYPTLIB="${CRYPTLIB} -lcipher"
966 )
967 AC_SUBST(CRYPTLIB)
968
969 dnl Check the style of gethostbyaddr, in order of preference
970 dnl GNU (_r eight args)
971 AC_DEFINE(GNUSTYLE, [1], [GNU-Style get*byaddr_r])
972 dnl SYSV (_r six args)
973 AC_DEFINE(SYSVSTYLE, [2], [SYSV-Style get*byaddr_r])
974 dnl BSD (three args, may not be thread safe)
975 AC_DEFINE(BSDSTYLE, [3], [BSD-Style get*byaddr_r])
976 dnl Tru64 has BSD version, but it is thread safe
977 dnl     http://h30097.www3.hp.com/docs/base_doc/DOCUMENTATION/V51B_HTML/MAN/MAN3/1739____.HTM
978 dnl We need #stdio.h to define NULL on FreeBSD (at least)
979 gethostbyaddrrstyle=""
980 AC_MSG_CHECKING([gethostbyaddr_r() syntax])
981 case "$host" in
982 *-freebsd*)
983 dnl With FreeBSD, check if there's a prototype for gethostbyaddr_r.
984 dnl Some versions (FreeBSD 5.1?) have a symbol but no prototype - so we
985 dnl override this test to BSDSTYLE. FreeBSD 6.2 and up have proper GNU
986 dnl style support.
987         AC_CHECK_DECLS([gethostbyaddr_r], [], [
988                 AC_DEFINE(GETHOSTBYADDRRSTYLE, BSDSTYLE,
989                         [style of gethostbyaddr_r functions ])
990                 gethostbyaddrrstyle=BSD
991                 AC_MSG_WARN([FreeBSD overridden to BSD-style])
992         ], [
993 #ifdef HAVE_NETDB_H
994 #include <netdb.h>
995 #endif
996 ])
997         ;;
998 esac
999 if test "x$gethostbyaddrrstyle" = "x"; then
1000         AC_TRY_LINK([
1001 #include <stdio.h>
1002 #include <netdb.h>
1003 ], [ gethostbyaddr_r(NULL, 0, 0, NULL, NULL, 0, NULL, NULL) ], [
1004         AC_DEFINE(GETHOSTBYADDRRSTYLE, GNUSTYLE, [style of gethostbyaddr_r functions ])
1005         gethostbyaddrrstyle=GNU
1006 ])
1007 fi
1008 if test "x$gethostbyaddrrstyle" = "x"; then
1009         AC_TRY_LINK([
1010 #include <stdio.h>
1011 #include <netdb.h>
1012 ], [ gethostbyaddr_r(NULL, 0, 0, NULL, NULL, 0, NULL) ] , [
1013                 AC_DEFINE(GETHOSTBYADDRRSTYLE, SYSVSTYLE, [style of gethostbyaddr_r functions ])
1014                 gethostbyaddrrstyle=SYSV
1015         ])
1016 fi
1017 if test "x$gethostbyaddrrstyle" = "x"; then
1018         AC_TRY_LINK([
1019 #include <stdio.h>
1020 #include <netdb.h>
1021 ], [ gethostbyaddr(NULL, 0, 0)  ], [
1022                 AC_DEFINE(GETHOSTBYADDRRSTYLE, BSDSTYLE, [style of gethostbyaddr_r functions ])
1023                 gethostbyaddrrstyle=BSD
1024         ])
1025 fi
1026
1027 if test "x$gethostbyaddrrstyle" = "x"; then
1028         AC_MSG_RESULT([none!  It must not exist, here.])
1029 else
1030         AC_MSG_RESULT([${gethostbyaddrrstyle}-style])
1031 fi
1032
1033 if test "x$gethostbyaddrrstyle" = "xBSD"; then
1034         AC_MSG_WARN([ ****** BSD-style gethostbyaddr might NOT be thread-safe! ****** ])
1035 fi
1036
1037 dnl Check the style of gethostbyname, in order of preference
1038 dnl GNU (_r seven args)
1039 dnl SYSV (_r five args)
1040 dnl BSD (two args, may not be thread safe)
1041 dnl Tru64 has BSD version, but it _is_ thread safe
1042 dnl     http://h30097.www3.hp.com/docs/base_doc/DOCUMENTATION/V51B_HTML/MAN/MAN3/1946____.HTM
1043 dnl We need #stdio.h to define NULL on FreeBSD (at least)
1044 gethostbynamerstyle=""
1045 AC_MSG_CHECKING([gethostbyname_r() syntax])
1046 AC_TRY_LINK([
1047 #include <stdio.h>
1048 #include <netdb.h>
1049 ], [ gethostbyname_r(NULL, NULL, NULL, 0, NULL, NULL) ], [
1050         AC_DEFINE(GETHOSTBYNAMERSTYLE, GNUSTYLE, [style of gethostbyname_r functions ])
1051         gethostbynamerstyle=GNU
1052 ])
1053 if test "x$gethostbynamerstyle" = "x"; then
1054         AC_TRY_LINK([
1055 #include <stdio.h>
1056 #include <netdb.h>
1057 ], [ gethostbyname_r(NULL, NULL, NULL, 0, NULL) ] , [
1058                 AC_DEFINE(GETHOSTBYNAMERSTYLE, SYSVSTYLE, [style of gethostbyname_r functions ])
1059                 gethostbynamerstyle=SYSV
1060         ])
1061 fi
1062 if test "x$gethostbynamerstyle" = "x"; then
1063         AC_TRY_LINK([
1064 #include <stdio.h>
1065 #include <netdb.h>
1066 ], [ gethostbyname(NULL)  ], [
1067                 AC_DEFINE(GETHOSTBYNAMERSTYLE, BSDSTYLE, [style of gethostbyname_r functions ])
1068                 gethostbynamerstyle=BSD
1069         ])
1070 fi
1071
1072 if test "x$gethostbynamerstyle" = "x"; then
1073         AC_MSG_RESULT([none!  It must not exist, here.])
1074 else
1075         AC_MSG_RESULT([${gethostbynamerstyle}-style])
1076 fi
1077
1078 if test "x$gethostbynamerstyle" = "xBSD"; then
1079         AC_MSG_WARN([ ****** BSD-style gethostbyname might NOT be thread-safe! ****** ])
1080 fi
1081
1082 dnl check for non-posix solaris ctime_r (extra buflen int arg)
1083 AC_DEFINE(POSIXSTYLE, [1], [Posix-Style ctime_r])
1084 AC_DEFINE(SOLARISSTYLE, [2], [Solaris-Style ctime_r])
1085 ctimerstyle=""
1086 AC_MSG_CHECKING([ctime_r() syntax])
1087 AC_TRY_LINK([
1088 #include <time.h>
1089 ], [ ctime_r(NULL, NULL, 0) ], [
1090         AC_DEFINE(CTIMERSTYLE, SOLARISSTYLE, [style of ctime_r function])
1091         ctimerstyle="SOLARIS"
1092 ])
1093 if test "x$ctimerstyle" = "x"; then
1094         AC_TRY_LINK([
1095 #include <time.h>
1096 ], [ ctime_r(NULL, NULL) ], [
1097                 AC_DEFINE(CTIMERSTYLE, POSIXSTYLE, [style of ctime_r function])
1098                 ctimerstyle="POSIX"
1099         ])
1100 fi
1101
1102 if test "x$ctimerstyle" = "x"; then
1103         AC_MSG_RESULT([none!  It must not exist, here.])
1104 else
1105         AC_MSG_RESULT([${ctimerstyle}-style])
1106 fi
1107
1108 AC_SUBST(HOSTINFO, $host)
1109
1110 dnl #############################################################
1111 dnl #
1112 dnl #  8. Checks for system services
1113 dnl #
1114 dnl #############################################################
1115
1116 dnl #
1117 dnl # Figure out where libtool is located,
1118 dnl #
1119 top_builddir=`pwd`
1120 export top_builddir
1121 AC_MSG_RESULT([top_builddir=$top_builddir])
1122 dnl # AC_SUBST(top_builddir)
1123 AC_SUBST(LIBLTDL)
1124 AC_SUBST(INCLTDL)
1125
1126 dnl import libtool stuff
1127
1128 dnl #############################################################
1129 dnl #
1130 dnl #  Configure in any module directories.
1131 dnl #
1132 dnl #############################################################
1133
1134 mysubdirs="$LIBLTDLPATH"
1135 if test "x$EXPERIMENTAL" = "xyes"; then
1136   bar=`ls -1 "${srcdir}"/src/modules/rlm_*/configure | sed 's%/configure%%'`
1137   dnl # get rid of LF's.
1138   mysubdirs=`echo $mysubdirs $bar`
1139 else
1140   dnl #
1141   dnl # Find 'configure' in ONLY the stable modules
1142   dnl #
1143   for bar in `cat "${srcdir}"/src/modules/stable`; do
1144     if test -f "${srcdir}"/src/modules/$bar/configure; then
1145       mysubdirs="$mysubdirs src/modules/$bar"
1146     fi
1147   done
1148 fi
1149
1150 dnl ############################################################
1151 dnl # make modules by list
1152 dnl #############################################################
1153 if test "x$EXPERIMENTAL" = "xyes"; then
1154   for foo in `ls -1 "${srcdir}"/src/modules | grep rlm_`; do
1155     MODULES="$MODULES $foo"
1156   done
1157 else
1158    dnl #
1159    dnl # make ONLY the stable modules
1160    dnl #
1161    for foo in `cat "${srcdir}"/src/modules/stable`; do
1162     MODULES="$MODULES $foo"
1163    done
1164 fi
1165
1166 dnl #
1167 dnl #  Don't change the variable name here.  Autoconf goes bonkers
1168 dnl #  if you do.
1169 dnl #
1170 AC_CONFIG_SUBDIRS($LTDL_SUBDIRS $mysubdirs)
1171 AC_SUBST(MODULES)
1172
1173 dnl #############################################################
1174 dnl #
1175 dnl #  And finally, output the results.
1176 dnl #
1177 dnl #############################################################
1178
1179 AC_CONFIG_COMMANDS([stamp-h], [echo timestamp > src/include/stamp-h])
1180 AC_CONFIG_COMMANDS([build-radpaths-h], [(cd ./src/include && /bin/sh ./build-radpaths-h)])
1181 AC_CONFIG_COMMANDS([main-chmod], [(cd ./src/main   && chmod +x checkrad.pl radlast radtest)])
1182 AC_CONFIG_COMMANDS([scripts-chmod], [(cd ./scripts    && chmod +x rc.radiusd radwatch radiusd.cron.daily radiusd.cron.monthly cryptpasswd)])
1183
1184 dnl #
1185 dnl #  Substitute whatever libraries we found to be necessary
1186 dnl #
1187 AC_SUBST(LIBS)
1188 AC_SUBST(INSTALLSTRIP)
1189
1190 USE_SHARED_LIBS=$enable_shared
1191 AC_SUBST(USE_SHARED_LIBS)
1192 USE_STATIC_LIBS=$enable_static
1193 AC_SUBST(USE_STATIC_LIBS)
1194 AC_SUBST(STATIC_MODULES)
1195 AC_SUBST(RADIUSD_MAJOR_VERSION)
1196 AC_SUBST(RADIUSD_MINOR_VERSION)
1197 AC_SUBST(RADIUSD_VERSION)
1198
1199 AC_OUTPUT(\
1200         ./Make.inc \
1201         ./src/include/build-radpaths-h \
1202         ./src/main/Makefile \
1203         ./src/main/checkrad.pl \
1204         ./src/main/radlast \
1205         ./src/main/radtest \
1206         ./scripts/rc.radiusd \
1207         ./scripts/radwatch \
1208         ./scripts/radiusd.cron.daily \
1209         ./scripts/radiusd.cron.monthly \
1210         ./scripts/cryptpasswd \
1211         ./raddb/dictionary \
1212         ./raddb/radrelay.conf \
1213         ./raddb/radiusd.conf
1214 )