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