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