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