* Add a check that prevents the server from seg faulting if
[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 dnl AC_PREFIX_DEFAULT(/usr/local)
27
28 dnl #############################################################
29 dnl #
30 dnl #  0. Checks for compiler, libtool, and command line options.
31 dnl #
32 dnl #############################################################
33
34 dnl Check for GNU cc
35 AC_PROG_CC
36 AC_PROG_GCC_TRADITIONAL
37 AC_PROG_CC_SUNPRO
38 AC_PROG_RANLIB
39
40 PACKAGE=freeradius
41
42 dnl Find GNU Make.
43 AC_CHECK_PROG(GMAKE, gmake, yes, no)
44 if test $GMAKE = no; then
45   AC_PATH_PROG(MAKE, make, /usr/local/bin/make)
46 else
47   AC_PATH_PROG(MAKE, gmake, /usr/local/gnu/bin/make)
48 fi
49 makever=`$ac_cv_path_MAKE --version 2>&1 | grep "GNU Make"`
50 if test -z "$makever"; then
51   AC_MSG_ERROR(GNU Make is not installed.  Please download and install it
52                 from ftp://prep.ai.mit.edu/pub/gnu/make/ before continuing.)
53 fi
54
55 dnl libltdl is installable
56 AC_LIBLTDL_INSTALLABLE
57
58 dnl ensure that we're looking for dlopen
59 AC_LIBTOOL_DLOPEN
60
61 dnl Figure out how to build shared libraries
62 AC_PROG_LIBTOOL
63
64 dnl extra argument: --with-logdir
65 logdir='${localstatedir}/log'
66 AC_MSG_CHECKING(logdir)
67 AC_ARG_WITH(logdir,
68 [  --with-logdir=DIR       Directory for logfiles [LOCALSTATEDIR/log] ],
69 [ case "$withval" in
70     no)
71         AC_MSG_ERROR(Need logdir)
72         ;;
73     yes)
74         ;;
75     *)
76         logdir="$withval"
77         ;;
78   esac ]
79 )
80 AC_SUBST(logdir)
81 AC_MSG_RESULT($logdir)
82
83 dnl extra argument: --with-radacctdir
84 radacctdir='${logdir}/radacct'
85 AC_MSG_CHECKING(radacctdir)
86 AC_ARG_WITH(radacctdir,
87 [  --with-radacctdir=PATH  Directory for detail files [LOGDIR/radacct] ],
88 [ case "$withval" in
89     no)
90         AC_MSG_ERROR(Need radacctdir)
91         ;;
92     yes)
93         ;;
94     *)
95         radacctdir="$withval"
96         ;;
97   esac ]
98 )
99 AC_SUBST(radacctdir)
100 AC_MSG_RESULT($radacctdir)
101
102 dnl extra argument: --with-raddbdir
103 raddbdir='${sysconfdir}/raddb'
104 AC_MSG_CHECKING(raddbdir)
105 AC_ARG_WITH(raddbdir,
106 [  --with-raddbdir=DIR     Directory for config files [SYSCONFDIR/raddb] ],
107 [ case "$withval" in
108     no)
109         AC_MSG_ERROR(Need raddbdir)
110         ;;
111     yes)
112         ;;
113     *)
114         raddbdir="$withval"
115         ;;
116   esac ]
117 )
118 AC_SUBST(raddbdir)
119 AC_MSG_RESULT($raddbdir)
120
121 dnl extra argument: --with-dict-nocase
122 WITH_DICT_NOCASE=yes
123 AC_ARG_WITH(dict-nocase,
124 [  --with-dict-nocase      Make dictionary case-independant (default=yes)],
125 [  case "$withval" in
126     yes)
127         ;;
128     *)
129         WITH_DICT_NOCASE=""
130   esac ]
131 )
132 if test "X$WITH_DICT_NOCASE" = "Xyes"; then
133   AC_DEFINE(WITH_DICT_NOCASE)
134 fi
135
136 dnl extra argument: --with-ascend-binary
137 ASCEND_BINARY=yes
138 AC_ARG_WITH(ascend-binary,
139 [  --with-ascend-binary    Include support for Ascend binary filter attributes (default=yes)],
140 [ case "$withval" in
141     yes)
142         ;;
143     *)
144         ASCEND_BINARY=""
145   esac ]
146 )
147 if test "X$ASCEND_BINARY" = "Xyes"; then
148   AC_DEFINE(ASCEND_BINARY)
149 fi
150
151 dnl extra argument: --with-threads
152 WITH_THREADS=yes
153 AC_ARG_WITH(threads,
154 [  --with-threads          Use threads, if available.  (default=yes) ],
155 [ case "$withval" in
156     yes)
157         ;;
158     *)
159         WITH_THREADS=""
160   esac ]
161 )
162
163 dnl extra argument: --with-thread-pool
164 WITH_THREAD_POOL=no
165 AC_ARG_WITH(thread-pool,
166 [  --with-thread-pool      Use a pool of threads for high-load systems.  (default=no) ],
167 [ case "$withval" in
168     yes)
169         WITH_THREAD_POOL=yes
170         ;;
171     *)
172         ;;
173   esac ]
174 )
175
176 dnl extra argument: --with-snmp
177 WITH_SNMP=yes
178 AC_ARG_WITH(snmp,
179 [  --with-snmp             Compile in SNMP support. (default=yes)],
180 [ case "$withval" in
181     yes)
182         ;;
183     *)
184         WITH_SNMP=no
185   esac ]
186 )
187
188 AC_ARG_WITH(mysql-include-dir,
189 [  --with-mysql-include-dir=DIR       Directory where the MySQL includes may be found ],
190 [ mysql_include_dir="$withval" ]
191 )
192
193 AC_ARG_WITH(mysql-lib-dir,
194 [  --with-mysql-lib-dir=DIR       Directory where the MySQL libraries may be found ],
195 [ mysql_lib_dir="$withval" ]
196 )
197
198 AC_ARG_WITH(mysql-dir,
199 [  --with-mysql-dir=DIR       Base directory where MySQL is installed ],
200 [ mysql_lib_dir="$withval/lib/mysql"
201   mysql_include_dir="$withval/include"
202 ]
203 )
204
205 AC_ARG_ENABLE(ltdl-install,
206 [  --disable-ltdl-install  do not install libltdl])
207 if test x"${enable_ltdl_install+set}" != xset; then
208   enable_ltdl_install=yes
209   ac_configure_args="$ac_configure_args --enable-ltdl-install"
210 fi
211 AC_CONFIG_SUBDIRS(libltdl)
212
213 dnl #
214 dnl #  Allow the user to specify a list of modules to be linked
215 dnl #  statically to the server.
216 dnl #
217 STATIC_MODULES=
218 AC_ARG_WITH(static_modules,
219 [  --with-static-modules=QUOTED-MODULE-LIST],[
220   for i in $withval; do
221     STATIC_MODULES="$STATIC_MODULES -dlpreopen ../modules/rlm_$i/rlm_$i.la"
222   done
223 ])
224
225 dnl #
226 dnl #  Enable developer C compiler warnings
227 dnl #
228 AC_ARG_ENABLE(developer,
229 [  --enable-developer              Turns on super-duper-extra-compile-warnings
230                                   when using gcc.],
231 [ case "$withval" in
232     *)
233         developer=no
234         ;;
235     yes)
236         developer=yes
237   esac ]
238 )
239
240 if test "x$developer" != "xno" -a -d $srcdir/CVS; then
241   dnl turn on the developer flag when taken from a CVS checkout (not a release)
242   developer="yes"
243 fi
244
245 dnl See what include-style is used by the make program.
246 dnl AC_MSG_CHECKING(include style for make)
247 dnl echo "include /dev/null" > testmake.$$
248 dnl echo "all:" >> testmake.$$
249 dnl make -f testmake.$$ >/dev/null 2>&1
250 dnl if test $? = 0
251 dnl then
252 dnl     INCLUDE=include
253 dnl     IQUOTE=
254 dnl else
255 dnl     INCLUDE=.include
256 dnl     IQUOTE='"'
257 dnl fi
258 dnl rm -f testmake.$$
259 dnl AC_MSG_RESULT(" $INCLUDE")
260 dnl AC_SUBST(INCLUDE)
261 dnl AC_SUBST(IQUOTE)
262
263 dnl #############################################################
264 dnl #
265 dnl #  1. Checks for programs
266 dnl #
267 dnl #############################################################
268
269 AC_PATH_PROG(PERL, perl, /usr/local/bin/perl)
270 if test ! -x $ac_cv_path_PERL; then
271   AC_MSG_ERROR(perl not found - fatal)
272 fi
273 AC_PATH_PROG(SNMPGET, snmpget, /usr/local/bin/snmpget)
274 AC_PATH_PROG(SNMPWALK, snmpwalk, /usr/local/bin/snmpwalk)
275 AC_PATH_PROG(RUSERS, rusers, /usr/bin/rusers)
276
277 dnl FIXME This is truly gross.
278 missing_dir=`cd $ac_aux_dir && pwd`
279 AM_MISSING_PROG(ACLOCAL, aclocal, $missing_dir)
280 AM_MISSING_PROG(AUTOCONF, autoconf, $missing_dir)
281 AM_MISSING_PROG(AUTOHEADER, autoheader, $missing_dir)
282
283 dnl #
284 dnl # check for AIX, to allow us to use some BSD functions
285 dnl # must be before macros that call the compiler.
286 dnl #
287 AC_AIX
288
289 dnl #############################################################
290 dnl #
291 dnl #  2. Checks for libraries
292 dnl #
293 dnl #############################################################
294
295 dnl If using pthreads, check for -lpthread (posix) or -lc_r (*BSD)
296 PTHREADLIB=
297 if test "$WITH_THREADS" = "yes"; then 
298   if test $ac_cv_prog_suncc = "yes"; then
299     CFLAGS="$CFLAGS -mt"
300   fi
301
302   AC_CHECK_HEADERS(pthread.h)
303
304   if test "X$ac_cv_header_pthread_h" = "X"; then
305     AC_MSG_ERROR("You are trying to use threads without a POSIX <pthread.h>")
306   fi
307
308 dnl # 
309 dnl # pthread stuff is usually in -lpthread
310 dnl # 
311   AC_CHECK_LIB(pthread, pthread_create,
312     PTHREADLIB="-lpthread"
313   )
314
315 dnl # 
316 dnl # Except for *BSD, where it's in -lc_r,
317 dnl # and where we've got to add extra CFLAGS.
318 dnl # 
319   if test "X$PTHREADLIB" = "X"; then
320     SAVED_CFLAGS=$CFLAGS
321     CFLAGS="$CFLAGS -pthread -D_THREAD_SAFE"
322     AC_CHECK_LIB(c_r, pthread_create,
323       PTHREADLIB="-lc_r"
324     )
325   fi
326
327 dnl # 
328 dnl # If we have NO pthread libraries, remove any knowledge of threads.
329 dnl # 
330   if test "x$PTHREADLIB" = "x"; then
331     CFLAGS=$SAVED_CFLAGS
332     ac_cv_header_pthread_h="no"
333   else
334     LIBS="$LIBS $PTHREADLIB"
335     CFLAGS="$CFLAGS -D_REENTRANT"
336   fi
337 fi
338
339 dnl #
340 dnl #  Checks to ensure that the thread pool code can build.
341 dnl #
342 if test "$WITH_THREAD_POOL" = "yes"; then
343   dnl #
344   dnl # If using thread pools, check that threading is enabled
345   dnl #
346   if test "$WITH_THREADS" != "yes"; then
347     AC_MSG_ERROR(You must have threads enabled for thread pools to work.)
348   fi
349
350   dnl #
351   dnl # If using thread pools, check that we have thread libraries
352   dnl #
353   if test "X$PTHREADLIB" = "X"; then
354     AC_MSG_ERROR(You must have threading libraries for thread pools to work.)
355   fi
356
357 dnl #
358 dnl #  Check for sem_init all by itself
359 dnl #
360   AC_CHECK_FUNC(sem_init)
361   if test "X$ac_cv_func_sem_init" = "Xno"; then
362
363 dnl #
364 dnl #  If not found, sem_init is in -lposix4 on Solaris
365 dnl #
366     AC_CHECK_LIB(posix4, sem_init)
367
368     if test "X$ac_cv_lib_posix4_sem_init" = "X"; then
369       AC_MSG_WARN(You do not have posix semaphores.  Disabling thread pools)
370       WITH_THREAD_POOL=no
371     fi
372   fi
373
374 dnl #
375 dnl #  Finally, after all of the checks above, we see if
376 dnl #  we can REALLY use the thread pools.
377 dnl #
378   if test "$WITH_THREAD_POOL" = "yes"; then
379     AC_DEFINE(WITH_THREAD_POOL,1)
380   fi
381 fi
382
383 dnl Check if we need -lsocket
384 AC_CHECK_LIB(socket, getsockname)
385
386 dnl Check for -lresolv
387 dnl This library may be needed later.
388 AC_CHECK_LIB(resolv, inet_aton)
389
390 dnl Check if we need -lnsl. Usually if we want to
391 dnl link against -lsocket we need to include -lnsl as well.
392 AC_CHECK_LIB(nsl, inet_ntoa)
393
394 dnl #############################################################
395 dnl #
396 dnl #  3. Checks for header files
397 dnl #
398 dnl #############################################################
399
400 AC_HEADER_DIRENT
401 AC_HEADER_STDC
402 AC_HEADER_TIME
403 AC_HEADER_SYS_WAIT
404
405 AC_CHECK_HEADERS( \
406         unistd.h \
407         crypt.h \
408         errno.h \
409         resource.h \
410         getopt.h \
411         malloc.h \
412         utmp.h \
413         utmpx.h \
414         signal.h \
415         sys/select.h \
416         syslog.h \
417         inttypes.h \
418         stdint.h \
419         stdio.h \
420         netdb.h \
421         arpa/inet.h \
422         netinet/in.h \
423         sys/types.h \
424         sys/socket.h \
425         sys/time.h
426 )
427
428 REGEX=no
429 AC_CHECK_HEADER(regex.h, REGEX=yes)
430
431 REGEX_EXTENDED=no
432 AC_EGREP_CPP(yes,
433   [#include <regex.h>
434    #ifdef REG_EXTENDED
435      yes
436    #endif
437    ], [AC_DEFINE(HAVE_REG_EXTENDED) REGEX_EXTENDED=yes])
438
439 dnl #############################################################
440 dnl #
441 dnl #  4. Checks for typedefs
442 dnl #
443 dnl #############################################################
444
445 dnl #
446 dnl # Ensure that these are defined
447 dnl #
448 AC_TYPE_OFF_T 
449 AC_TYPE_PID_T
450 AC_TYPE_SIZE_T
451 AC_TYPE_UID_T
452
453 dnl check for socklen_t
454 AC_CHECK_TYPE_INCLUDE([
455 #ifdef HAVE_SYS_TYPES_H
456 #include <sys/types.h>
457 #endif
458 #ifdef HAVE_SYS_SOCKET_H
459 #include <sys/socket.h>
460 #endif
461 ],socklen_t, int)
462
463 dnl check for uint8_t
464 AC_CHECK_TYPE_INCLUDE([
465 #ifdef HAVE_INTTYPES_H
466 #include <inttypes.h>
467 #endif
468 #ifdef HAVE_STDINT_H
469 #include <stdint.h>
470 #endif
471 ],uint8_t, unsigned char)
472
473 dnl check for uint32_t
474 AC_CHECK_TYPE_INCLUDE([
475 #ifdef HAVE_INTTYPES_H
476 #include <inttypes.h>
477 #endif
478 #ifdef HAVE_STDINT_H
479 #include <stdint.h>
480 #endif
481 ],uint32_t, unsigned int)
482
483 dnl #############################################################
484 dnl #
485 dnl #  5. Checks for structures and functions
486 dnl #
487 dnl #############################################################
488 AC_CHECK_FUNCS( \
489         getopt_long \
490         lockf \
491         strsignal \
492         sigaction \
493         sigprocmask \
494         snprintf \
495         vsnprintf \
496         setsid \
497         strncasecmp \
498         strcasecmp \
499         strsep \
500         inet_aton \
501         gethostname \
502         setlinebuf \
503         setvbuf \
504         getusershell
505 )
506 RADIUSD_NEED_DECLARATIONS( \
507         crypt \
508         strncasecmp \
509         strcasecmp \
510         inet_aton \
511         gethostname \
512         setlinebuf \
513         getusershell \
514         endusershell
515 )
516
517 AC_TYPE_SIGNAL
518
519 dnl #############################################################
520 dnl #
521 dnl #  6. Checks for compiler characteristics
522 dnl #
523 dnl #############################################################
524
525 dnl #
526 dnl # Ensure that these are defined
527 dnl #
528 AC_C_CONST 
529
530 dnl #
531 dnl # See if this is OS/2
532 dnl #
533 AC_MSG_CHECKING(type of OS)
534 OS=`uname -s`
535 AC_MSG_RESULT($OS)
536 if test "$OS" = "OS/2"; then
537         LIBPREFIX=
538 else
539         LIBPREFIX=lib
540 fi
541 AC_SUBST(LIBPREFIX)
542
543 dnl #
544 dnl # Set Default CFLAGS
545 dnl #
546 if test "x$GCC" = "xyes"; then
547     CFLAGS="$CFLAGS -Wall -D_GNU_SOURCE"
548 fi
549
550 AC_MSG_CHECKING(for developer gcc flags)
551 if test "x$developer" = "xyes" -a "x$GCC" = "xyes"; then
552   devflags="-Wshadow -Wpointer-arith -Wcast-qual -Wcast-align -Wwrite-strings -Waggregate-return -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations -Wnested-externs"
553   CFLAGS="$CFLAGS $devflags"
554 else
555   devflags="none"
556   CFLAGS="$CFLAGS -DNDEBUG"
557 fi
558 AC_MSG_RESULT($devflags)
559
560 dnl #############################################################
561 dnl #
562 dnl #  7. Checks for library functions
563 dnl #
564 dnl #############################################################
565
566 dnl Check for libcrypt
567 dnl We use crypt(3) which may be in libc, or in libcrypt (eg FreeBSD)
568 AC_CHECK_LIB(crypt, crypt,
569   CRYPTLIB="-lcrypt"
570 )
571 AC_SUBST(CRYPTLIB)
572 if test "$CRYPTLIB" != ""; then
573   AC_DEFINE(HAVE_CRYPT)
574 else
575   AC_CHECK_FUNC(crypt, AC_DEFINE(HAVE_CRYPT))
576 fi
577
578 if test "x$WITH_SNMP" = "xyes"; then
579   SNMP_CHECKS
580 fi
581
582 POSTGRESQL_CHECKS
583 MYSQL_CHECKS
584 ORACLE_CHECKS
585 ODBC_CHECKS
586
587 dnl #############################################################
588 dnl #
589 dnl #  8. Checks for system services
590 dnl #
591 dnl #############################################################
592
593 dnl #
594 dnl # Figure out where libtool is located,
595 dnl #
596 LIBTOOL="`pwd`/libtool"
597 AC_SUBST(LIBTOOL)
598 AC_SUBST(LIBLTDL)
599 AC_SUBST(INCLTDL)
600 top_builddir=`pwd`
601 AC_SUBST(top_builddir)
602
603 dnl #############################################################
604 dnl #
605 dnl #  And finally, output the results.
606 dnl #
607 dnl #############################################################
608
609 dnl #
610 dnl #  Substitute whatever libraries we found to be necessary
611 dnl #
612 AC_SUBST(LIBS)
613
614 USE_SHARED_LIBS=$enable_shared
615 AC_SUBST(USE_SHARED_LIBS)
616 USE_STATIC_LIBS=$enable_static
617 AC_SUBST(USE_STATIC_LIBS)
618 AC_SUBST(STATIC_MODULES)
619 AC_SUBST(REGEX)
620 AC_SUBST(REGEX_EXTENDED)
621
622 AC_OUTPUT(\
623         ./Make.inc \
624         ./src/include/build-radpaths-h \
625         ./src/main/checkrad.pl \
626         ./src/main/radlast \
627         ./src/main/radtest \
628         ./scripts/rc.radiusd \
629         ./scripts/radwatch \
630         ./scripts/check-radiusd-config \
631         ./scripts/radiusd.cron.daily \
632         ./scripts/radiusd.cron.monthly \
633         ./raddb/radiusd.conf
634 )
635
636 AC_OUTPUT_COMMANDS([echo timestamp > src/include/stamp-h])
637 AC_OUTPUT_COMMANDS([(cd ./src/include && /bin/sh ./build-radpaths-h)])
638 AC_OUTPUT_COMMANDS([(cd ./src/main   && chmod +x checkrad.pl radlast radtest)])
639 AC_OUTPUT_COMMANDS([(cd ./scripts    && chmod +x rc.radiusd radwatch check-radiusd-config radiusd.cron.daily radiusd.cron.monthly)])
640 AC_OUTPUT_COMMANDS([
641 cat >> src/include/autoconf.h <<EOF
642
643 #define HOSTINFO        "$host"
644 EOF
645 ],host=$host)