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