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