Jeff Carneal <jeff@apex.net>
[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-dbm
122 DBMLIB=
123 BUILDDBM=
124 AC_ARG_WITH(dbm,
125 [  --with-dbm              Compile in DBM support],
126 [ case "$withval" in
127     no)
128         ;;
129     yes)
130         AC_DEFINE(WITH_DBM)
131         DBMLIB=-ldbm
132         BUILDDBM=builddbm
133   esac ]
134 )
135
136 dnl extra argument: --with-ndbm
137 AC_ARG_WITH(ndbm,
138 [  --with-ndbm             Compile in NDBM support],
139 [ case "$withval" in
140     no)
141         ;;
142     yes)
143         AC_DEFINE(WITH_NDBM)
144         DBMLIB=-ldb
145         BUILDDBM=builddbm
146   esac ]
147 )
148
149 AC_SUBST(DBMLIB)
150 AC_SUBST(BUILDDBM)
151
152 dnl extra argument: --with-ascend-hack
153 AC_ARG_WITH(ascend-hack,
154 [  --with-ascend-hack      Include Ascend hacks],
155 [ case "$withval" in
156     no)
157         ;;
158     yes)
159         AC_DEFINE(WITH_ASCEND_HACK)
160         dnl if they haven't said to use it, do so.
161         if test "${with_ascend_cpl+set}" != "set"; then
162                 with_ascend_cpl=23
163         fi
164     esac ]
165 )
166
167 dnl extra argument: --with-ascend-cpl=N
168 AC_ARG_WITH(ascend-cpl,
169 [  --with-ascend-cpl=N     Set Ascend Channels Per Line to N [23] ],
170 [ case "$withval" in
171     *)
172         AC_DEFINE_UNQUOTED(ASCEND_CHANNELS_PER_LINE, $withval)
173   esac ]
174 )
175
176 dnl extra argument: --with-ntdomain-hack
177 AC_ARG_WITH(ntdomain-hack,
178 [  --with-ntdomain-hack    Include NT Domain hack],
179 [ case "$withval" in
180     no)
181         ;;
182     yes)
183         AC_DEFINE(WITH_NTDOMAIN_HACK)
184   esac ]
185 )
186
187 dnl extra argument: --with-spcj-hack
188 AC_ARG_WITH(spcj-hack,
189 [  --with-spcj-hack        Include Specialix Jetstream hacks],
190 [ case "$withval" in
191     no)
192         ;;
193     yes)
194         AC_DEFINE(WITH_SPECIALIX_JETSTREAM_HACK)
195   esac ]
196 )
197
198 dnl extra argument: --with-dict-nocase
199 WITH_DICT_NOCASE=yes
200 AC_ARG_WITH(dict-nocase,
201 [  --with-dict-nocase      Make dictionary case-independant (default=yes)],
202 [  case "$withval" in
203     yes)
204         ;;
205     *)
206         WITH_DICT_NOCASE=""
207   esac ]
208 )
209 if test "X$WITH_DICT_NOCASE" = "Xyes"; then
210   AC_DEFINE(WITH_DICT_NOCASE)
211 fi
212
213 dnl extra argument: --with-attrib-nmc
214 ATTRIB_NMC=yes
215 AC_ARG_WITH(attrib-nmc,
216 [  --with-attrib-nmc       Include USR-style vendor specific attributes (default=yes)],
217 [ case "$withval" in
218     yes)
219         ;;
220     *)
221         ATTRIB_NMC=""
222   esac ]
223 )
224 if test "X$ATTRIB_NMC" = "Xyes"; then
225   AC_DEFINE(ATTRIB_NMC)
226 fi
227
228 dnl extra argument: --with-ascend-binary
229 ASCEND_BINARY=yes
230 AC_ARG_WITH(ascend-binary,
231 [  --with-ascend-binary    Include support for Ascend binary filter attributes (default=yes)],
232 [ case "$withval" in
233     yes)
234         ;;
235     *)
236         ASCEND_BINARY=""
237   esac ]
238 )
239 if test "X$ASCEND_BINARY" = "Xyes"; then
240   AC_DEFINE(ASCEND_BINARY)
241 fi
242
243 dnl extra argument: --with-threads
244 WITH_THREADS=yes
245 AC_ARG_WITH(threads,
246 [  --with-threads          Use threads, if available.  (default=yes) ],
247 [ case "$withval" in
248     yes)
249         ;;
250     *)
251         WITH_THREADS=""
252   esac ]
253 )
254
255 dnl extra argument: --with-thread-pool
256 WITH_THREAD_POOL=no
257 AC_ARG_WITH(thread-pool,
258 [  --with-thread-pool      Use a pool of threads for high-load systems.  (default=no) ],
259 [ case "$withval" in
260     *)
261         WITH_THREAD_POOL=$withval
262   esac ]
263 )
264
265 dnl extra argument: --with-snmp
266 AC_ARG_WITH(snmp,
267 [  --with-snmp             Compile in SNMP support. (default=no)],
268 [ case "$withval" in
269     no)
270         ;;
271     yes)
272         AC_DEFINE(WITH_SNMP)
273         SNMPLIB="-lsnmp -lcrypto"
274         SNMPINC=-I/usr/include/ucd-snmp
275   esac ]
276 )
277
278 dnl extra argument: --with-usercollide
279 AC_ARG_WITH(usercollide,
280 [  --with-usercollide       Compile in user collision code. (default=no)],
281 [ case "$withval" in
282     no)
283         ;;
284     yes)
285         AC_DEFINE(WITH_USERCOLLIDE)
286   esac ]
287 )
288
289
290 AC_SUBST(SNMPLIB)
291 AC_SUBST(SNMPINC)
292
293
294 AC_ARG_ENABLE(ltdl-install,
295 [  --disable-ltdl-install  do not install libltdl])
296 if test x"${enable_ltdl_install+set}" != xset; then
297   enable_ltdl_install=yes
298   ac_configure_args="$ac_configure_args --enable-ltdl-install"
299 fi
300 AC_CONFIG_SUBDIRS(libltdl)
301
302 dnl See what include-style is used by the make program.
303 dnl AC_MSG_CHECKING(include style for make)
304 dnl echo "include /dev/null" > testmake.$$
305 dnl echo "all:" >> testmake.$$
306 dnl make -f testmake.$$ >/dev/null 2>&1
307 dnl if test $? = 0
308 dnl then
309 dnl     INCLUDE=include
310 dnl     IQUOTE=
311 dnl else
312 dnl     INCLUDE=.include
313 dnl     IQUOTE='"'
314 dnl fi
315 dnl rm -f testmake.$$
316 dnl AC_MSG_RESULT(" $INCLUDE")
317 dnl AC_SUBST(INCLUDE)
318 dnl AC_SUBST(IQUOTE)
319
320 dnl #############################################################
321 dnl #
322 dnl #  1. Checks for programs
323 dnl #
324 dnl #############################################################
325
326 AC_PATH_PROG(PERL, perl, /usr/local/bin/perl)
327 if test ! -x $ac_cv_path_PERL; then
328   AC_MSG_ERROR(perl not found - fatal)
329 fi
330 AC_PATH_PROG(SNMPGET, snmpget, /usr/local/bin/snmpget)
331 AC_PATH_PROG(SNMPWALK, snmpwalk, /usr/local/bin/snmpwalk)
332 AC_PATH_PROG(RUSERS, rusers, /usr/bin/rusers)
333
334 dnl FIXME This is truly gross.
335 missing_dir=`cd $ac_aux_dir && pwd`
336 AM_MISSING_PROG(ACLOCAL, aclocal, $missing_dir)
337 AM_MISSING_PROG(AUTOCONF, autoconf, $missing_dir)
338 AM_MISSING_PROG(AUTOHEADER, autoheader, $missing_dir)
339
340 dnl #
341 dnl # check for AIX, to allow us to use some BSD functions
342 dnl # must be before macros that call the compiler.
343 dnl #
344 AC_AIX
345
346 dnl #############################################################
347 dnl #
348 dnl #  2. Checks for libraries
349 dnl #
350 dnl #############################################################
351
352 dnl If using pthreads, check for -lpthread (posix) or -lc_r (*BSD)
353 PTHREADLIB=
354 if test "$WITH_THREADS" = "yes"; then 
355   if test $ac_cv_prog_suncc = "yes"; then
356     CFLAGS="$CFLAGS -mt"
357   fi
358
359   AC_CHECK_HEADERS(pthread.h)
360
361   if test "X$ac_cv_header_pthread_h" = "X"; then
362     AC_MSG_ERROR("You are trying to use threads without a POSIX <pthread.h>")
363   fi
364
365 dnl # 
366 dnl # pthread stuff is usually in -lpthread
367 dnl # 
368   AC_CHECK_LIB(pthread, pthread_create,
369     PTHREADLIB="-lpthread"
370   )
371
372 dnl # 
373 dnl # Except for *BSD, where it's in -lc_r,
374 dnl # and where we've got to add extra CFLAGS.
375 dnl # 
376   if test "X$PTHREADLIB" = "X"; then
377     SAVED_CFLAGS=$CFLAGS
378     CFLAGS="$CFLAGS -pthread -D_THREAD_SAFE"
379     AC_CHECK_LIB(c_r, pthread_create,
380       PTHREADLIB="-lc_r"
381     )
382   fi
383   LIBS="$LIBS $PTHREADLIB"
384   CFLAGS="$CFLAGS -D_REENTRANT"
385 fi
386
387 dnl #
388 dnl #  Checks to ensure that the thread pool code can build.
389 dnl #
390 if test "$WITH_THREAD_POOL" = "yes"; then
391   dnl #
392   dnl # If using thread pools, check that threading is enabled
393   dnl #
394   if test "$WITH_THREADS" != "yes"; then
395     AC_MSG_ERROR(You must have threads enabled for thread pools to work.)
396   fi
397
398   dnl #
399   dnl # If using thread pools, check that we have thread libraries
400   dnl #
401   if test "X$PTHREADLIB" = "X"; then
402     AC_MSG_ERROR(You must have threading libraries for thread pools to work.)
403   fi
404
405 dnl #
406 dnl #  Check for sem_init all by itself
407 dnl #
408   AC_CHECK_FUNC(sem_init)
409   if test "X$ac_cv_func_sem_init" = "Xno"; then
410
411 dnl #
412 dnl #  If not found, sem_init is in -lposix4 on Solaris
413 dnl #
414     AC_CHECK_LIB(posix4, sem_init)
415
416     if test "X$ac_cv_lib_posix4_sem_init" = "X"; then
417       AC_MSG_WARN(You do not have posix semaphores.  Disabling thread pools)
418       WITH_THREAD_POOL=no
419     fi
420   fi
421
422 dnl #
423 dnl #  Finally, after all of the checks above, we see if
424 dnl #  we can REALLY use the thread pools.
425 dnl #
426   if test "$WITH_THREAD_POOL" = "yes"; then
427     AC_DEFINE(WITH_THREAD_POOL,1)
428   fi
429 fi
430
431 dnl Check if we need -lsocket
432 AC_CHECK_LIB(socket, getsockname)
433
434 dnl Check for -lresolv
435 dnl This library may be needed later.
436 AC_CHECK_LIB(resolv, inet_aton)
437
438 dnl Check if we need -lnsl. Usually if we want to
439 dnl link against -lsocket we need to include -lnsl as well.
440 AC_CHECK_LIB(nsl, inet_ntoa)
441
442 dnl #############################################################
443 dnl #
444 dnl #  3. Checks for header files
445 dnl #
446 dnl #############################################################
447
448 AC_HEADER_DIRENT
449 AC_HEADER_STDC
450 AC_HEADER_TIME
451 AC_HEADER_SYS_WAIT
452
453 AC_CHECK_HEADERS( \
454         unistd.h \
455         crypt.h \
456         errno.h \
457         resource.h \
458         getopt.h \
459         malloc.h \
460         utmp.h \
461         utmpx.h \
462         sys/select.h \
463         regex.h \
464         syslog.h \
465         inttypes.h \
466         stdint.h \
467         arpa/inet.h \
468         netinet/in.h \
469         sys/types.h \
470         sys/time.h
471 )
472
473 dnl #############################################################
474 dnl #
475 dnl #  4. Checks for typedefs
476 dnl #
477 dnl #############################################################
478
479 dnl #
480 dnl # Ensure that these are defined
481 dnl #
482 AC_TYPE_OFF_T 
483 AC_TYPE_PID_T
484 AC_TYPE_SIZE_T
485 AC_TYPE_UID_T
486
487 dnl Check for socklen_t
488 AC_CACHE_CHECK(for socklen_t,
489                fr_cv_socklen_t,
490     [ fr_cv_socklen_t=no
491       AC_TRY_COMPILE([#include <sys/types.h>
492         #include <sys/socket.h>],
493         [socklen_t foo],
494         fr_cv_socklen_t=yes,
495       )
496      ]
497 )
498
499 if test "$fr_cv_socklen_t" != "yes"; then
500          AC_DEFINE(socklen_t, int)
501 fi
502
503 dnl Check for uint8_t
504 AC_CACHE_CHECK(for uint8_t,
505                fr_cv_uint8_t,
506      [ fr_cv_uint8_t=no
507        AC_TRY_COMPILE([
508 #ifdef HAVE_INTTYPES_H
509 #include <inttypes.h>
510 #endif
511 #ifdef HAVE_STDINT_H
512 #include <stdint.h>
513 #endif
514 ],
515          [uint8_t foo],
516          fr_cv_uint8_t=yes
517        )
518      ]
519 )
520
521 if test "$fr_cv_uint8_t" != "yes"; then
522          AC_DEFINE(uint8_t, unsigned char)
523 fi
524
525 dnl Check for uint32_t
526 AC_CACHE_CHECK(for uint32_t,
527                fr_cv_uint32_t,
528      [ fr_cv_uint32_t=no
529        AC_TRY_COMPILE([
530 #ifdef HAVE_INTTYPES_H
531 #include <inttypes.h>
532 #endif
533 #ifdef HAVE_STDINT_H
534 #include <stdint.h>
535 #endif
536 ],
537          [uint32_t foo],
538          fr_cv_uint32_t=yes
539        )
540      ]
541 )
542
543 if test "$fr_cv_uint32_t" != "yes"; then
544         AC_DEFINE(uint32_t, unsigned int)
545         UINT32_T_AS_INT=yes
546 fi
547
548 dnl #
549 dnl #  If we don't have uint32_t, then verify that sizeof(unsigned int)==4
550 dnl #  If the integers are NOT 4 octets long, then the previous definition
551 dnl #  won't work, and we won't produce correct RADIUS packets.
552 dnl #
553 if test "x$UINT32_T_AS_INT" != "x"; then
554   AC_CHECK_SIZEOF(unsigned int, [4])
555 fi
556
557 dnl #############################################################
558 dnl #
559 dnl #  5. Checks for structures and functions
560 dnl #
561 dnl #############################################################
562 AC_CHECK_FUNCS( \
563         getopt_long \
564         lockf \
565         strsignal \
566         sigaction \
567         sigprocmask \
568         snprintf \
569         vsnprintf \
570         setsid \
571         strncasecmp \
572         strcasecmp \
573         strsep \
574         inet_aton \
575         gethostname \
576         setlinebuf \
577         getusershell
578 )
579 RADIUSD_NEED_DECLARATIONS( \
580         crypt \
581         strncasecmp \
582         strcasecmp \
583         inet_aton \
584         gethostname \
585         setlinebuf \
586         getusershell \
587         endusershell
588 )
589
590 AC_TYPE_SIGNAL
591
592 dnl #############################################################
593 dnl #
594 dnl #  6. Checks for compiler characteristics
595 dnl #
596 dnl #############################################################
597
598 dnl #
599 dnl # Ensure that these are defined
600 dnl #
601 AC_C_CONST 
602
603 dnl #
604 dnl # See if this is OS/2
605 dnl #
606 AC_MSG_CHECKING(type of OS)
607 OS=`uname -s`
608 AC_MSG_RESULT($OS)
609 if test "$OS" = "OS/2"; then
610         LIBPREFIX=
611 else
612         LIBPREFIX=lib
613 fi
614 AC_SUBST(LIBPREFIX)
615
616 dnl #
617 dnl # Set Default CFLAGS
618 dnl #
619 if test "$GCC" = "yes"; then
620     CFLAGS="$CFLAGS -Wall -D_GNU_SOURCE"
621 fi
622
623 dnl #############################################################
624 dnl #
625 dnl #  7. Checks for library functions
626 dnl #
627 dnl #############################################################
628
629 dnl Check for libcrypt
630 dnl We use crypt(3) which may be in libc, or in libcrypt (eg FreeBSD)
631 AC_CHECK_LIB(crypt, crypt,
632   CRYPTLIB="-lcrypt"
633 )
634 AC_SUBST(CRYPTLIB)
635 if test "$CRYPTLIB" != ""; then
636   AC_DEFINE(HAVE_CRYPT)
637 else
638   AC_CHECK_FUNC(crypt, AC_DEFINE(HAVE_CRYPT))
639 fi
640
641 dnl #############################################################
642 dnl #
643 dnl #  8. Checks for system services
644 dnl #
645 dnl #############################################################
646
647 dnl #
648 dnl # Figure out where libtool is located,
649 dnl #
650 LIBTOOL="`pwd`/libtool"
651 AC_SUBST(LIBTOOL)
652 AC_SUBST(LIBLTDL)
653 AC_SUBST(INCLTDL)
654 top_builddir=`pwd`
655 AC_SUBST(top_builddir)
656
657 dnl #############################################################
658 dnl #
659 dnl #  And finally, output the results.
660 dnl #
661 dnl #############################################################
662
663 dnl #
664 dnl #  Substitute whatever libraries we found to be necessary
665 dnl #
666 AC_SUBST(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         ./raddb/radiusd.conf
678 )
679
680 AC_OUTPUT_COMMANDS([echo timestamp > src/include/stamp-h])
681 AC_OUTPUT_COMMANDS([(cd ./src/include && /bin/sh ./build-radpaths-h)])
682 AC_OUTPUT_COMMANDS([(cd ./src/main   && chmod +x checkrad.pl radlast radtest)])
683 AC_OUTPUT_COMMANDS([(cd ./scripts    && chmod +x rc.radiusd radwatch check-radiusd-config)])