51cd1b1e14cc1d5e9444243200485a62dbff5b48
[freeradius.git] / configure.in
1 dnl #############################################################
2 dnl #
3 dnl #  For information about autoconf, see:
4 dnl #
5 dnl #  http://www.primate.wisc.edu/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_RANLIB
38
39 PACKAGE=freeradius
40
41 dnl Find GNU Make.
42 AC_CHECK_PROG(GMAKE, gmake, yes, no)
43 if test $GMAKE = no; then
44   AC_PATH_PROG(MAKE, make, /usr/local/bin/make)
45 else
46   AC_PATH_PROG(MAKE, gmake, /usr/local/gnu/bin/make)
47 fi
48 makever=`$ac_cv_path_MAKE --version 2>&1 | grep "GNU Make"`
49 if test -z "$makever"; then
50   AC_MSG_ERROR(GNU Make is not installed.  Please download and install it
51                 from ftp://prep.ai.mit.edu/pub/gnu/make/ before continuing.)
52 fi
53
54 dnl ensure that we're looking for dlopen
55 AC_LIBTOOL_DLOPEN
56
57 dnl Figure out how to build shared libraries
58 AC_PROG_LIBTOOL
59
60 dnl extra argument: --with-logdir
61 logdir='${localstatedir}/log'
62 AC_MSG_CHECKING(logdir)
63 AC_ARG_WITH(logdir,
64 [  --with-logdir=DIR       Directory for logfiles [LOCALSTATEDIR/log] ],
65 [ case "$withval" in
66     no)
67         AC_MSG_ERROR(Need logdir)
68         ;;
69     yes)
70         ;;
71     *)
72         logdir="$withval"
73         ;;
74   esac ]
75 )
76 AC_SUBST(logdir)
77 AC_MSG_RESULT($logdir)
78
79 dnl extra argument: --with-radacctdir
80 radacctdir='${logdir}/radacct'
81 AC_MSG_CHECKING(radacctdir)
82 AC_ARG_WITH(radacctdir,
83 [  --with-radacctdir=PATH  Directory for detail files [LOGDIR/radacct] ],
84 [ case "$withval" in
85     no)
86         AC_MSG_ERROR(Need radacctdir)
87         ;;
88     yes)
89         ;;
90     *)
91         radacctdir="$withval"
92         ;;
93   esac ]
94 )
95 AC_SUBST(radacctdir)
96 AC_MSG_RESULT($radacctdir)
97
98 dnl extra argument: --with-raddbdir
99 raddbdir='${sysconfdir}/raddb'
100 AC_MSG_CHECKING(raddbdir)
101 AC_ARG_WITH(raddbdir,
102 [  --with-raddbdir=DIR     Directory for config files [SYSCONFDIR/raddb] ],
103 [ case "$withval" in
104     no)
105         AC_MSG_ERROR(Need raddbdir)
106         ;;
107     yes)
108         ;;
109     *)
110         raddbdir="$withval"
111         ;;
112   esac ]
113 )
114 AC_SUBST(raddbdir)
115 AC_MSG_RESULT($raddbdir)
116
117 dnl extra argument: --with-dbm
118 DBMLIB=
119 BUILDDBM=
120 AC_ARG_WITH(dbm,
121 [  --with-dbm              Compile in DBM support],
122 [ case "$withval" in
123     no)
124         ;;
125     yes)
126         AC_DEFINE(WITH_DBM)
127         DBMLIB=-ldbm
128         BUILDDBM=builddbm
129   esac ]
130 )
131
132 dnl extra argument: --with-ndbm
133 AC_ARG_WITH(ndbm,
134 [  --with-ndbm             Compile in NDBM support],
135 [ case "$withval" in
136     no)
137         ;;
138     yes)
139         AC_DEFINE(WITH_NDBM)
140         DBMLIB=-ldb
141         BUILDDBM=builddbm
142   esac ]
143 )
144
145 AC_SUBST(DBMLIB)
146 AC_SUBST(BUILDDBM)
147
148 dnl extra argument: --with-ascend-hack
149 AC_ARG_WITH(ascend-hack,
150 [  --with-ascend-hack      Include Ascend hacks],
151 [ case "$withval" in
152     no)
153         ;;
154     yes)
155         AC_DEFINE(WITH_ASCEND_HACK)
156         dnl if they haven't said to use it, do so.
157         if test "${with_ascend_cpl+set}" != "set"; then
158                 with_ascend_cpl=23
159         fi
160     esac ]
161 )
162
163 dnl extra argument: --with-ascend-cpl=N
164 AC_ARG_WITH(ascend-cpl,
165 [  --with-ascend-cpl=N     Set Ascend Channels Per Line to N [23] ],
166 [ case "$withval" in
167     *)
168         AC_DEFINE_UNQUOTED(ASCEND_CHANNELS_PER_LINE, $withval)
169   esac ]
170 )
171
172 dnl extra argument: --with-ntdomain-hack
173 AC_ARG_WITH(ntdomain-hack,
174 [  --with-ntdomain-hack    Include NT Domain hack],
175 [ case "$withval" in
176     no)
177         ;;
178     yes)
179         AC_DEFINE(WITH_NTDOMAIN_HACK)
180   esac ]
181 )
182
183 dnl extra argument: --with-spcj-hack
184 AC_ARG_WITH(spcj-hack,
185 [  --with-spcj-hack        Include Specialix Jetstream hacks],
186 [ case "$withval" in
187     no)
188         ;;
189     yes)
190         AC_DEFINE(WITH_SPECIALIX_JETSTREAM_HACK)
191   esac ]
192 )
193
194 dnl extra argument: --with-dict-nocase
195 AC_ARG_WITH(dict-nocase,
196 [  --with-dict-nocase      Make dictionary case-independant],
197 [ case "$withval" in
198     no)
199         ;;
200     yes)
201         AC_DEFINE(WITH_DICT_NOCASE)
202   esac ]
203 )
204
205 dnl extra argument: --with-attrib-nmc
206 ATTRIB_NMC=
207 AC_ARG_WITH(attrib-nmc,
208 [  --with-attrib-nmc       Include USR-style vendor specific attributes (default=yes)],
209 [ ATTRIB_NMC=$withval
210  case "$withval" in
211     no)
212         ;;
213     yes)
214         AC_DEFINE(ATTRIB_NMC)
215   esac ]
216 )
217 dnl if they haven't said to use it, do so.
218 if test "$ATTRIB_NMC" = "";then
219   AC_DEFINE(ATTRIB_NMC)
220 fi
221
222 dnl extra argument: --with-ascend-binary
223 ASCEND_BINARY=
224 AC_ARG_WITH(ascend-binary,
225 [  --with-ascend-binary    Include support for Ascend binary filter attributes (default=yes)],
226 [ ASCEND_BINARY=$withval
227  case "$withval" in
228     no)
229         ;;
230     yes)
231         AC_DEFINE(ASCEND_BINARY)
232   esac ]
233 )
234 dnl if they haven't said to use it, do so.
235 if test "X$ASCEND_BINARY" = "X";then
236   AC_DEFINE(ASCEND_BINARY)
237 fi
238
239 dnl extra argument: --with-threads
240 WITH_THREADS=yes
241 AC_ARG_WITH(threads,
242 [  --with-threads          Use threads, if available.  (default=yes) ],
243 [ case "$withval" in
244     *)
245         WITH_THREADS=$withval
246   esac ]
247 )
248
249 dnl extra argument: --with-thread-pool
250 WITH_THREAD_POOL=no
251 AC_ARG_WITH(thread-pool,
252 [  --with-thread-pool      Use a pool of threads for high-load systems.  (default=no) ],
253 [ case "$withval" in
254     *)
255         WITH_THREAD_POOL=$withval
256   esac ]
257 )
258
259 AC_ARG_ENABLE(ltdl-install,
260 [  --disable-ltdl-install  do not install libltdl])
261 if test x"${enable_ltdl_install+set}" != xset; then
262   enable_ltdl_install=yes
263   ac_configure_args="$ac_configure_args --enable-ltdl-install"
264 fi
265 AC_CONFIG_SUBDIRS(src/libltdl)
266
267 dnl See what include-style is used by the make program.
268 dnl AC_MSG_CHECKING(include style for make)
269 dnl echo "include /dev/null" > testmake.$$
270 dnl echo "all:" >> testmake.$$
271 dnl make -f testmake.$$ >/dev/null 2>&1
272 dnl if test $? = 0
273 dnl then
274 dnl     INCLUDE=include
275 dnl     IQUOTE=
276 dnl else
277 dnl     INCLUDE=.include
278 dnl     IQUOTE='"'
279 dnl fi
280 dnl rm -f testmake.$$
281 dnl AC_MSG_RESULT(" $INCLUDE")
282 dnl AC_SUBST(INCLUDE)
283 dnl AC_SUBST(IQUOTE)
284
285 dnl #############################################################
286 dnl #
287 dnl #  1. Checks for programs
288 dnl #
289 dnl #############################################################
290
291 AC_PATH_PROG(PERL, perl, /usr/local/bin/perl)
292 if test ! -x $ac_cv_path_PERL; then
293   AC_MSG_ERROR(perl not found - fatal)
294 fi
295 AC_PATH_PROG(SNMPGET, snmpget, /usr/local/bin/snmpget)
296 AC_PATH_PROG(SNMPWALK, snmpwalk, /usr/local/bin/snmpwalk)
297 AC_PATH_PROG(RUSERS, rusers, /usr/bin/rusers)
298
299 dnl FIXME This is truly gross.
300 missing_dir=`cd $ac_aux_dir && pwd`
301 AM_MISSING_PROG(ACLOCAL, aclocal, $missing_dir)
302 AM_MISSING_PROG(AUTOCONF, autoconf, $missing_dir)
303 AM_MISSING_PROG(AUTOHEADER, autoheader, $missing_dir)
304
305 dnl #
306 dnl # check for AIX, to allow us to use some BSD functions
307 dnl # must be before macros that call the compiler.
308 dnl #
309 AC_AIX
310
311 dnl #############################################################
312 dnl #
313 dnl #  2. Checks for libraries
314 dnl #
315 dnl #############################################################
316
317 dnl If using pthreads, check for -lpthread (posix) or -lc_r (*BSD)
318 PTHREADLIB=
319 if test "$WITH_THREADS" = "yes"; then 
320   AC_CHECK_HEADERS(pthread.h)
321   AC_CHECK_LIB(pthread, pthread_create,
322     PTHREADLIB="-lpthread"
323   )
324   if test "X$PTHREADLIB" = "X"; then
325     AC_CHECK_LIB(c_r, pthread_create,
326       PTHREADLIB="-lc_r"
327     )
328   fi
329   LIBS="$LIBS $PTHREADLIB"
330 fi
331
332 dnl #
333 dnl #  Checks to ensure that the thread pool code can build.
334 dnl #
335 if test "$WITH_THREAD_POOL" = "yes"; then
336   dnl #
337   dnl # If using thread pools, check that threading is enabled
338   dnl #
339   if test "$WITH_THREADS" != "yes"; then
340     AC_MSG_ERROR(You must have threads enabled for thread pools to work.)
341   fi
342
343   dnl #
344   dnl # If using thread pools, check that we have thread libraries
345   dnl #
346   if test "X$PTHREADLIB" = "X"; then
347     AC_MSG_ERROR(You must have threading libraries for thread pools to work.)
348   fi
349
350 dnl #
351 dnl #  Check for sem_init all by itself
352 dnl #
353   AC_CHECK_FUNC(sem_init)
354   if test "X$ac_cv_func_sem_init" = "Xno"; then
355
356 dnl #
357 dnl #  If not found, sem_init is in -lposix4 on Solaris
358 dnl #
359     AC_CHECK_LIB(posix4, sem_init)
360
361     if test "X$ac_cv_lib_posix4_sem_init" = "X"; then
362       AC_MSG_WARN(You do not have posix semaphores.  Disabling thread pools)
363       WITH_THREAD_POOL=no
364     fi
365   fi
366
367 dnl #
368 dnl #  Finally, after all of the checks above, we see if
369 dnl #  we can REALLY use the thread pools.
370 dnl #
371   if test "$WITH_THREAD_POOL" = "yes"; then
372     AC_DEFINE(WITH_THREAD_POOL,1)
373   fi
374 fi
375
376 dnl Check if we need -lsocket
377 AC_CHECK_LIB(socket, getsockname)
378
379 dnl Check for -lresolv
380 dnl This library may be needed later.
381 AC_CHECK_LIB(resolv, inet_aton)
382
383 dnl Check if we need -lnsl. Usually if we want to
384 dnl link against -lsocket we need to include -lnsl as well.
385 AC_CHECK_LIB(nsl, inet_ntoa)
386
387 dnl #############################################################
388 dnl #
389 dnl #  3. Checks for header files
390 dnl #
391 dnl #############################################################
392
393 AC_HEADER_DIRENT
394 AC_HEADER_STDC
395 AC_HEADER_TIME
396 AC_HEADER_SYS_WAIT
397
398 AC_CHECK_HEADERS( \
399         unistd.h \
400         crypt.h \
401         errno.h \
402         resource.h \
403         getopt.h \
404         malloc.h \
405         utmp.h \
406         utmpx.h \
407         sys/select.h \
408         dlfcn.h \
409         regex.h \
410         syslog.h \
411         inttypes.h \
412         stdint.h \
413         arpa/inet.h \
414         sys/time.h
415 )
416
417 dnl #############################################################
418 dnl #
419 dnl #  4. Checks for typedefs
420 dnl #
421 dnl #############################################################
422
423 dnl #
424 dnl # Ensure that these are defined
425 dnl #
426 AC_TYPE_OFF_T 
427 AC_TYPE_PID_T
428 AC_TYPE_SIZE_T
429 AC_TYPE_UID_T
430
431 dnl Check for socklen_t
432 AC_CACHE_CHECK(for socklen_t,
433                fr_cv_socklen_t,
434     [ socklen_t=no
435       AC_TRY_COMPILE([#include <sys/types.h>
436         #include <sys/socket.h>],
437         [socklen_t foo],
438         AC_DEFINE(HAVE_SOCKLEN_T) fr_cv_socklen_t=yes,
439       )
440      ]
441 )
442
443 dnl Check for uint8_t
444 AC_CACHE_CHECK(for uint8_t,
445                fr_cv_uint8_t,
446      [ fr_cv_uint8_t=no
447        AC_TRY_COMPILE([
448 #ifdef HAVE_INTTYPES_H
449 #include <inttypes.h>
450 #endif
451 #ifdef HAVE_STDINT_H
452 #include <stdint.h>
453 #endif
454 ],
455          [uint8_t foo],
456          fr_cv_uint8_t=yes
457        )
458      ]
459 )
460
461 if test "$fr_cv_uint8_t" != "yes"; then
462          AC_DEFINE(uint8_t, unsigned char)
463 fi
464
465 dnl Check for uint32_t
466 AC_CACHE_CHECK(for uint32_t,
467                fr_cv_uint32_t,
468      [ fr_cv_uint32_t=no
469        AC_TRY_COMPILE([
470 #ifdef HAVE_INTTYPES_H
471 #include <inttypes.h>
472 #endif
473 #ifdef HAVE_STDINT_H
474 #include <stdint.h>
475 #endif
476 ],
477          [uint32_t foo],
478          fr_cv_uint32_t=yes
479        )
480      ]
481 )
482
483 if test "$fr_cv_uint32_t" != "yes"; then
484         AC_DEFINE(uint32_t, unsigned int)
485         UINT32_T_AS_INT=yes
486 fi
487
488 dnl #
489 dnl #  If we don't have uint32_t, then verify that sizeof(unsigned int)==4
490 dnl #  If the integers are NOT 4 octets long, then the previous definition
491 dnl #  won't work, and we won't produce correct RADIUS packets.
492 dnl #
493 if test "x$UINT32_T_AS_INT" != "x"; then
494   AC_CHECK_SIZEOF(unsigned int, [4])
495 fi
496
497 dnl #############################################################
498 dnl #
499 dnl #  5. Checks for structures and functions
500 dnl #
501 dnl #############################################################
502 AC_CHECK_FUNCS( \
503         getopt_long \
504         lockf \
505         strsignal \
506         sigaction \
507         sigprocmask \
508         snprintf \
509         vsnprintf \
510         setsid \
511         strncasecmp \
512         strcasecmp \
513         inet_aton \
514         gethostname \
515         setlinebuf \
516         getusershell
517 )
518 RADIUSD_NEED_DECLARATIONS( \
519         crypt \
520         strncasecmp \
521         strcasecmp \
522         inet_aton \
523         gethostname \
524         setlinebuf \
525         getusershell \
526         endusershell
527 )
528
529 AC_TYPE_SIGNAL
530
531 dnl #############################################################
532 dnl #
533 dnl #  6. Checks for compiler characteristics
534 dnl #
535 dnl #############################################################
536
537 dnl #
538 dnl # Ensure that these are defined
539 dnl #
540 AC_C_CONST 
541
542 dnl #
543 dnl # See if this is OS/2
544 dnl #
545 AC_MSG_CHECKING(type of OS)
546 OS=`uname -s`
547 AC_MSG_RESULT($OS)
548 if test "$OS" = "OS/2"; then
549         LIBPREFIX=
550 else
551         LIBPREFIX=lib
552 fi
553 AC_SUBST(LIBPREFIX)
554
555 dnl #
556 dnl # Set Default CFLAGS
557 dnl #
558 if test "$GCC" = "yes"; then
559     CFLAGS="$CFLAGS -Wall -D_GNU_SOURCE"
560 fi
561
562 dnl #############################################################
563 dnl #
564 dnl #  7. Checks for library functions
565 dnl #
566 dnl #############################################################
567
568 dnl Check for libcrypt
569 dnl We use crypt(3) which may be in libc, or in libcrypt (eg FreeBSD)
570 AC_CHECK_LIB(crypt, crypt,
571   CRYPTLIB="-lcrypt"
572 )
573 AC_SUBST(CRYPTLIB)
574 if test "$CRYPTLIB" != ""; then
575   AC_DEFINE(HAVE_CRYPT)
576 else
577   AC_CHECK_FUNC(crypt, AC_DEFINE(HAVE_CRYPT))
578 fi
579
580 dnl ***********************
581 dnl  This next bit is stolen from glib, and modified to work for FreeRADIUS.
582 dnl ***********************
583 MODULE_LIBS=
584 MODULE_CFLAGS=
585 MODULE_LDFLAGS=
586 MODULE_HAVE_DLERROR=0
587
588 dnl *** dlopen() and dlsym() in system libraries
589 if test -z "$DYNAMIC_MODULES"; then
590         AC_CHECK_FUNC(dlopen,
591                 AC_CHECK_FUNC(dlsym,
592                         [ DYNAMIC_MODULES=DYNAMIC_MODULES_DL HAVE_DLOPEN=1 ]
593                 ,)
594         ,)
595 fi
596
597 dnl *** dlopen() and dlsym() in libdl
598 if test -z "$DYNAMIC_MODULES"; then
599         AC_CHECK_LIB(dl, dlopen,
600                 AC_CHECK_LIB(dl, dlsym,
601                         MODULE_LIBS=-ldl
602                         [ DYNAMIC_MODULES=DYNAMIC_MODULES_DL HAVE_DLOPEN=1 ]
603                 ,)
604         ,)
605 fi
606
607 dnl *** shl_load() in libdld (HP-UX)
608 if test -z "$DYNAMIC_MODULES"; then
609         AC_MSG_CHECKING(how to export all symbols)
610         SAVED_LDFLAGS=$LDFLAGS
611
612         LDFLAGS="$LDFLAGS -Wl,-E"
613         AC_TRY_LINK(,[ return 0; ],
614                 [ MODULE_LDFLAGS="-Wl,-E" ],[
615                 LDFLAGS="$SAVED_LDFLAGS -bexpall"
616                 AC_TRY_LINK(,[ return 0; ],
617                         MODULE_LDFLAGS="-bexpall",
618                         MODULE_LDFLAGS=""
619                 )
620         ])
621
622         LDFLAGS=$SAVED_LDFLAGS
623         AC_MSG_RESULT($MODULE_LDFLAGS)
624
625         AC_CHECK_LIB(dld, shl_load,
626                 MODULE_LIBS=-ldld
627                 DYNAMIC_MODULES=DYNAMIC_MODULES_DLD
628         ,)
629 fi
630
631 dnl *** additional checks for DYNAMIC_MODULES_DL
632 if test "$DYNAMIC_MODULES" = "DYNAMIC_MODULES_DL"; then
633
634 dnl *** check whether we need preceeding underscores
635         AC_MSG_CHECKING(for preceeding underscore in symbols)
636         AC_CACHE_VAL(rlm_cv_uscore,[
637                 AC_TRY_RUN([
638                 #include <dlfcn.h>
639                 int rlm_underscore_test (void) { return 42; }
640                 int main() {
641                   void *f1 = (void*)0, *f2 = (void*)0, *handle;
642                   handle = dlopen ((void*)0, 0);
643                   if (handle) {
644                     f1 = dlsym (handle, "rlm_underscore_test");
645                     f2 = dlsym (handle, "_rlm_underscore_test");
646                   } return (!f2 || f1);
647                 }],
648                         rlm_cv_uscore=yes,
649                         rlm_cv_uscore=no,
650                         rlm_cv_uscore=no
651                 )
652                 rm -f plugin.c plugin.o plugin.lo
653         ])
654         AC_MSG_RESULT($rlm_cv_uscore)
655         if test "x$rlm_cv_uscore" = "xyes"; then
656                 AC_DEFINE(MODULE_NEED_USCORE)
657         fi
658
659         LDFLAGS="$LDFLAGS_orig"
660 dnl *** check for having dlerror()
661         AC_CHECK_FUNC(dlerror,
662                 MODULE_HAVE_DLERROR=1,
663                 MODULE_HAVE_DLERROR=0)
664 fi
665 dnl *** done, have e got an implementation?
666 if test -z "$DYNAMIC_MODULES"; then
667         DYNAMIC_MODULES=0
668 fi
669
670 AC_SUBST(DYNAMIC_MODULES)
671 AC_DEFINE(HAVE_DLOPEN)
672 AC_SUBST(MODULE_LIBS)
673 AC_SUBST(MODULE_CFLAGS)
674 AC_SUBST(MODULE_LDFLAGS)
675 AC_SUBST(MODULE_HAVE_DLERROR)
676
677 dnl #############################################################
678 dnl #
679 dnl #  8. Checks for system services
680 dnl #
681 dnl #############################################################
682
683 dnl #
684 dnl # Figure out where libtool is located,
685 dnl #
686 LIBTOOL="`pwd`/libtool"
687 AC_SUBST(LIBTOOL)
688
689 dnl #############################################################
690 dnl #
691 dnl #  And finally, output the results.
692 dnl #
693 dnl #############################################################
694
695 dnl #
696 dnl #  Substitute whatever libraries we found to be necessary
697 dnl #
698 AC_SUBST(LIBS)
699
700 AC_OUTPUT(\
701         ./Make.inc \
702         ./src/include/build-radpaths-h \
703         ./src/main/checkrad.pl \
704         ./src/main/radlast \
705         ./src/main/radtest \
706         ./scripts/rc.radiusd \
707         ./scripts/radwatch \
708         ./scripts/check-radiusd-config
709 )
710
711 AC_OUTPUT_COMMANDS([echo timestamp > src/include/stamp-h])
712 AC_OUTPUT_COMMANDS([(cd ./src/include && /bin/sh ./build-radpaths-h)])
713 AC_OUTPUT_COMMANDS([(cd ./src/main   && chmod +x checkrad.pl radlast radtest)])
714 AC_OUTPUT_COMMANDS([(cd ./scripts    && chmod +x rc.radiusd radwatch check-radiusd-config)])