5ed99f1d5c1235b66936da47389096c82db12259
[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 dnl See what include-style is used by the make program.
260 dnl AC_MSG_CHECKING(include style for make)
261 dnl echo "include /dev/null" > testmake.$$
262 dnl echo "all:" >> testmake.$$
263 dnl make -f testmake.$$ >/dev/null 2>&1
264 dnl if test $? = 0
265 dnl then
266 dnl     INCLUDE=include
267 dnl     IQUOTE=
268 dnl else
269 dnl     INCLUDE=.include
270 dnl     IQUOTE='"'
271 dnl fi
272 dnl rm -f testmake.$$
273 dnl AC_MSG_RESULT(" $INCLUDE")
274 dnl AC_SUBST(INCLUDE)
275 dnl AC_SUBST(IQUOTE)
276
277 dnl #############################################################
278 dnl #
279 dnl #  1. Checks for programs
280 dnl #
281 dnl #############################################################
282
283 AC_PATH_PROG(PERL, perl, /usr/local/bin/perl)
284 if test ! -x $ac_cv_path_PERL; then
285   AC_MSG_ERROR(perl not found - fatal)
286 fi
287 AC_PATH_PROG(SNMPGET, snmpget, /usr/local/bin/snmpget)
288 AC_PATH_PROG(SNMPWALK, snmpwalk, /usr/local/bin/snmpwalk)
289 AC_PATH_PROG(RUSERS, rusers, /usr/bin/rusers)
290
291 dnl #
292 dnl # check for AIX, to allow us to use some BSD functions
293 dnl # must be before macros that call the compiler.
294 dnl #
295 AC_AIX
296
297 dnl #############################################################
298 dnl #
299 dnl #  2. Checks for libraries
300 dnl #
301 dnl #############################################################
302
303 dnl If using pthreads, check for -lpthread (posix) or -lc_r (*BSD)
304 PTHREADLIB=
305 if test "$WITH_THREADS" = "yes"; then 
306   AC_CHECK_HEADERS(pthread.h)
307   AC_CHECK_LIB(pthread, pthread_create,
308     PTHREADLIB="-lpthread"
309   )
310   if test "X$PTHREADLIB" = "X"; then
311     AC_CHECK_LIB(c_r, pthread_create,
312       PTHREADLIB="-lc_r"
313     )
314   fi
315   AC_SUBST(PTHREADLIB)
316 fi
317
318 if test "$WITH_THREAD_POOL" = "yes"; then
319   dnl If using thread pools, check that threading is enabled
320   if test "$WITH_THREADS" != "yes"; then
321     AC_MSG_ERROR(You must have threads enabled for thread pools to work.)
322   fi
323
324   dnl If using thread pools, check that we have thread libraries
325   if test "X$PTHREADLIB" = "X"; then
326     AC_MSG_ERROR(You must have threading libraries for thread pools to work.)
327   fi
328
329   AC_DEFINE(WITH_THREAD_POOL,1)
330 fi
331
332 dnl Check for -lsocket
333 AC_CHECK_LIB(socket, getsockname,
334   SOCKETLIB="-lsocket"
335 )
336 AC_SUBST(SOCKETLIB)
337
338 dnl Check for -lresolv
339 dnl This library may be needed later.
340 AC_CHECK_LIB(resolv, inet_aton)
341
342 dnl Check for -lnsl. We don't need yp_all, but usually if we want to
343 dnl link against -lsocket we need to include -lnsl as well.
344 AC_CHECK_LIB(nsl, yp_all,
345   NSLLIB="-lnsl",
346 )
347 AC_SUBST(NSLLIB)
348
349 dnl #############################################################
350 dnl #
351 dnl #  3. Checks for header files
352 dnl #
353 dnl #############################################################
354
355 AC_HEADER_DIRENT
356 AC_HEADER_STDC
357
358 AC_CHECK_HEADERS( \
359         unistd.h \
360         crypt.h \
361         errno.h \
362         resource.h \
363         getopt.h \
364         malloc.h \
365         utmp.h \
366         utmpx.h \
367         sys/select.h \
368         dlfcn.h \
369         regex.h \
370         syslog.h \
371         inttypes.h \
372         stdint.h \
373         arpa/inet.h
374 )
375
376 dnl #############################################################
377 dnl #
378 dnl #  4. Checks for typedefs
379 dnl #
380 dnl #############################################################
381
382 dnl #
383 dnl # Ensure that these are defined
384 dnl #
385 AC_TYPE_OFF_T 
386 AC_TYPE_PID_T
387 AC_TYPE_SIZE_T
388 AC_TYPE_UID_T
389
390 dnl Check for socklen_t
391 AC_CACHE_CHECK(for socklen_t,
392                fr_cv_socklen_t,
393     [ socklen_t=no
394       AC_TRY_COMPILE([#include <sys/types.h>
395         #include <sys/socket.h>],
396         [socklen_t foo],
397         AC_DEFINE(HAVE_SOCKLEN_T) fr_cv_socklen_t=yes,
398       )
399      ]
400 )
401
402 dnl Check for uint8_t
403 AC_CACHE_CHECK(for uint8_t,
404                fr_cv_uint8_t,
405      [ fr_cv_uint8_t=no
406        AC_TRY_COMPILE([
407 #ifdef HAVE_INTTYPES_H
408 #include <inttypes.h>
409 #endif
410 #ifdef HAVE_STDINT_H
411 #include <stdint.h>
412 #endif
413 ],
414          [uint8_t foo],
415          fr_cv_uint8_t=yes
416        )
417      ]
418 )
419
420 if test "$fr_cv_uint8_t" != "yes"; then
421          AC_DEFINE(uint8_t, unsigned char)
422 fi
423
424 dnl Check for uint32_t
425 AC_CACHE_CHECK(for uint32_t,
426                fr_cv_uint32_t,
427      [ fr_cv_uint32_t=no
428        AC_TRY_COMPILE([
429 #ifdef HAVE_INTTYPES_H
430 #include <inttypes.h>
431 #endif
432 #ifdef HAVE_STDINT_H
433 #include <stdint.h>
434 #endif
435 ],
436          [uint32_t foo],
437          fr_cv_uint32_t=yes
438        )
439      ]
440 )
441
442 if test "$fr_cv_uint32_t" != "yes"; then
443         AC_DEFINE(uint32_t, unsigned int)
444         UINT32_T_AS_INT=yes
445 fi
446
447 dnl #
448 dnl #  If we don't have uint32_t, then verify that sizeof(unsigned int)==4
449 dnl #  If the integers are NOT 4 octets long, then the previous definition
450 dnl #  won't work, and we won't produce correct RADIUS packets.
451 dnl #
452 if test "x$UINT32_T_AS_INT" != "x"; then
453   AC_CHECK_SIZEOF(unsigned int, [4])
454 fi
455
456 dnl #############################################################
457 dnl #
458 dnl #  5. Checks for structures and functions
459 dnl #
460 dnl #############################################################
461 AC_CHECK_FUNCS( \
462         getopt_long \
463         lockf \
464         strsignal \
465         sigaction \
466         snprintf \
467         vsnprintf \
468         setsid \
469         strncasecmp \
470         strcasecmp \
471         inet_aton \
472         gethostname \
473         setlinebuf \
474         getusershell
475 )
476 RADIUSD_NEED_DECLARATIONS( \
477         crypt \
478         strncasecmp \
479         strcasecmp \
480         inet_aton \
481         gethostname \
482         setlinebuf \
483         getusershell \
484         endusershell
485 )
486
487 AC_TYPE_SIGNAL
488
489 dnl #############################################################
490 dnl #
491 dnl #  6. Checks for compiler characteristics
492 dnl #
493 dnl #############################################################
494
495 dnl #
496 dnl # Ensure that these are defined
497 dnl #
498 AC_C_CONST 
499
500 dnl #
501 dnl # See if this is OS/2
502 dnl #
503 AC_MSG_CHECKING(type of OS)
504 OS=`uname -s`
505 AC_MSG_RESULT($OS)
506 if test "$OS" = "OS/2"; then
507         LIBPREFIX=
508 else
509         LIBPREFIX=lib
510 fi
511 AC_SUBST(LIBPREFIX)
512
513 dnl #
514 dnl # Set Default CFLAGS
515 dnl #
516 if test "$GCC" = "yes"; then
517     CFLAGS="$CFLAGS -Wall -D_GNU_SOURCE"
518 fi
519
520 dnl #############################################################
521 dnl #
522 dnl #  7. Checks for library functions
523 dnl #
524 dnl #############################################################
525
526 dnl Check for libcrypt
527 dnl We use crypt(3) which may be in libc, or in libcrypt (eg FreeBSD)
528 AC_CHECK_LIB(crypt, crypt,
529   CRYPTLIB="-lcrypt"
530 )
531 AC_SUBST(CRYPTLIB)
532 if test "$CRYPTLIB" != ""; then
533   AC_DEFINE(HAVE_CRYPT)
534 else
535   AC_CHECK_FUNC(crypt, AC_DEFINE(HAVE_CRYPT))
536 fi
537
538 dnl ***********************
539 dnl  This next bit is stolen from glib, and modified to work for FreeRADIUS.
540 dnl ***********************
541 MODULE_LIBS=
542 MODULE_CFLAGS=
543 MODULE_LDFLAGS=
544 MODULE_HAVE_DLERROR=0
545
546 dnl *** dlopen() and dlsym() in system libraries
547 if test -z "$DYNAMIC_MODULES"; then
548         AC_CHECK_FUNC(dlopen,
549                 AC_CHECK_FUNC(dlsym,
550                         [ DYNAMIC_MODULES=DYNAMIC_MODULES_DL HAVE_DLOPEN=1 ]
551                 ,)
552         ,)
553 fi
554
555 dnl *** dlopen() and dlsym() in libdl
556 if test -z "$DYNAMIC_MODULES"; then
557         AC_CHECK_LIB(dl, dlopen,
558                 AC_CHECK_LIB(dl, dlsym,
559                         MODULE_LIBS=-ldl
560                         [ DYNAMIC_MODULES=DYNAMIC_MODULES_DL HAVE_DLOPEN=1 ]
561                 ,)
562         ,)
563 fi
564
565 dnl *** shl_load() in libdld (HP-UX)
566 if test -z "$DYNAMIC_MODULES"; then
567         AC_MSG_CHECKING(how to export all symbols)
568         SAVED_LDFLAGS=$LDFLAGS
569
570         LDFLAGS="$LDFLAGS -Wl,-E"
571         AC_TRY_LINK(,[ return 0; ],
572                 [ MODULE_LDFLAGS="-Wl,-E" ],[
573                 LDFLAGS="$SAVED_LDFLAGS -bexpall"
574                 AC_TRY_LINK(,[ return 0; ],
575                         MODULE_LDFLAGS="-bexpall",
576                         MODULE_LDFLAGS=""
577                 )
578         ])
579
580         LDFLAGS=$SAVED_LDFLAGS
581         AC_MSG_RESULT($MODULE_LDFLAGS)
582
583         AC_CHECK_LIB(dld, shl_load,
584                 MODULE_LIBS=-ldld
585                 DYNAMIC_MODULES=DYNAMIC_MODULES_DLD
586         ,)
587 fi
588
589 dnl *** additional checks for DYNAMIC_MODULES_DL
590 if test "$DYNAMIC_MODULES" = "DYNAMIC_MODULES_DL"; then
591
592 dnl *** check whether we need preceeding underscores
593         AC_MSG_CHECKING(for preceeding underscore in symbols)
594         AC_CACHE_VAL(rlm_cv_uscore,[
595                 AC_TRY_RUN([
596                 #include <dlfcn.h>
597                 int rlm_underscore_test (void) { return 42; }
598                 int main() {
599                   void *f1 = (void*)0, *f2 = (void*)0, *handle;
600                   handle = dlopen ((void*)0, 0);
601                   if (handle) {
602                     f1 = dlsym (handle, "rlm_underscore_test");
603                     f2 = dlsym (handle, "_rlm_underscore_test");
604                   } return (!f2 || f1);
605                 }],
606                         rlm_cv_uscore=yes,
607                         rlm_cv_uscore=no,
608                         rlm_cv_uscore=no
609                 )
610                 rm -f plugin.c plugin.o plugin.lo
611         ])
612         AC_MSG_RESULT($rlm_cv_uscore)
613         if test "x$rlm_cv_uscore" = "xyes"; then
614                 AC_DEFINE(MODULE_NEED_USCORE)
615         fi
616
617         LDFLAGS="$LDFLAGS_orig"
618 dnl *** check for having dlerror()
619         AC_CHECK_FUNC(dlerror,
620                 MODULE_HAVE_DLERROR=1,
621                 MODULE_HAVE_DLERROR=0)
622 fi
623 dnl *** done, have e got an implementation?
624 if test -z "$DYNAMIC_MODULES"; then
625         DYNAMIC_MODULES=0
626 fi
627
628 AC_SUBST(DYNAMIC_MODULES)
629 AC_DEFINE(HAVE_DLOPEN)
630 AC_SUBST(MODULE_LIBS)
631 AC_SUBST(MODULE_CFLAGS)
632 AC_SUBST(MODULE_LDFLAGS)
633 AC_SUBST(MODULE_HAVE_DLERROR)
634
635 dnl #############################################################
636 dnl #
637 dnl #  8. Checks for system services
638 dnl #
639 dnl #############################################################
640
641 dnl #
642 dnl # Figure out where libtool is located,
643 dnl #
644 LIBTOOL="`pwd`/libtool"
645 AC_SUBST(LIBTOOL)
646
647 dnl #############################################################
648 dnl #
649 dnl #  And finally, output the results.
650 dnl #
651 dnl #############################################################
652
653 dnl #
654 dnl #  Substitute whatever libraries we found to be necessary
655 dnl #
656 AC_SUBST(LIBS)
657
658 AC_OUTPUT(\
659         ./Make.inc \
660         ./src/include/build-radpaths-h \
661         ./src/main/checkrad.pl \
662         ./src/main/radlast \
663         ./src/main/radtest \
664         ./scripts/rc.radiusd \
665         ./scripts/radwatch \
666 )
667
668 AC_OUTPUT_COMMANDS([echo timestamp > src/include/stamp-h])
669 AC_OUTPUT_COMMANDS([(cd ./src/include && /bin/sh ./build-radpaths-h)])
670 AC_OUTPUT_COMMANDS([(cd ./src/main   && chmod +x checkrad.pl radlast radtest)])