5d0398a6d96e00faf54c34a80bd8d7628bcb3b03
[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 See what include-style is used by the make program.
214 dnl AC_MSG_CHECKING(include style for make)
215 dnl echo "include /dev/null" > testmake.$$
216 dnl echo "all:" >> testmake.$$
217 dnl make -f testmake.$$ >/dev/null 2>&1
218 dnl if test $? = 0
219 dnl then
220 dnl     INCLUDE=include
221 dnl     IQUOTE=
222 dnl else
223 dnl     INCLUDE=.include
224 dnl     IQUOTE='"'
225 dnl fi
226 dnl rm -f testmake.$$
227 dnl AC_MSG_RESULT(" $INCLUDE")
228 dnl AC_SUBST(INCLUDE)
229 dnl AC_SUBST(IQUOTE)
230
231 dnl #############################################################
232 dnl #
233 dnl #  1. Checks for programs
234 dnl #
235 dnl #############################################################
236
237 AC_PATH_PROG(PERL, perl, /usr/local/bin/perl)
238 if test ! -x $ac_cv_path_PERL; then
239   AC_MSG_ERROR(perl not found - fatal)
240 fi
241 AC_PATH_PROG(SNMPGET, snmpget, /usr/local/bin/snmpget)
242 AC_PATH_PROG(SNMPWALK, snmpwalk, /usr/local/bin/snmpwalk)
243 AC_PATH_PROG(RUSERS, rusers, /usr/bin/rusers)
244
245 dnl FIXME This is truly gross.
246 missing_dir=`cd $ac_aux_dir && pwd`
247 AM_MISSING_PROG(ACLOCAL, aclocal, $missing_dir)
248 AM_MISSING_PROG(AUTOCONF, autoconf, $missing_dir)
249 AM_MISSING_PROG(AUTOHEADER, autoheader, $missing_dir)
250
251 dnl #
252 dnl # check for AIX, to allow us to use some BSD functions
253 dnl # must be before macros that call the compiler.
254 dnl #
255 AC_AIX
256
257 dnl #############################################################
258 dnl #
259 dnl #  2. Checks for libraries
260 dnl #
261 dnl #############################################################
262
263 dnl If using pthreads, check for -lpthread (posix) or -lc_r (*BSD)
264 PTHREADLIB=
265 if test "$WITH_THREADS" = "yes"; then 
266   if test $ac_cv_prog_suncc = "yes"; then
267     CFLAGS="$CFLAGS -mt"
268   fi
269
270   AC_CHECK_HEADERS(pthread.h)
271
272   if test "X$ac_cv_header_pthread_h" = "X"; then
273     AC_MSG_ERROR("You are trying to use threads without a POSIX <pthread.h>")
274   fi
275
276 dnl # 
277 dnl # pthread stuff is usually in -lpthread
278 dnl # 
279   AC_CHECK_LIB(pthread, pthread_create,
280     PTHREADLIB="-lpthread"
281   )
282
283 dnl # 
284 dnl # Except for *BSD, where it's in -lc_r,
285 dnl # and where we've got to add extra CFLAGS.
286 dnl # 
287   if test "X$PTHREADLIB" = "X"; then
288     SAVED_CFLAGS=$CFLAGS
289     CFLAGS="$CFLAGS -pthread -D_THREAD_SAFE"
290     AC_CHECK_LIB(c_r, pthread_create,
291       PTHREADLIB="-lc_r"
292     )
293   fi
294
295 dnl # 
296 dnl # If we have NO pthread libraries, remove any knowledge of threads.
297 dnl # 
298   if test "x$PTHREADLIB" = "x"; then
299     CFLAGS=$SAVED_CFLAGS
300     ac_cv_header_pthread_h="no"
301   else
302     LIBS="$LIBS $PTHREADLIB"
303     CFLAGS="$CFLAGS -D_REENTRANT"
304   fi
305 fi
306
307 dnl #
308 dnl #  Checks to ensure that the thread pool code can build.
309 dnl #
310 if test "$WITH_THREAD_POOL" = "yes"; then
311   dnl #
312   dnl # If using thread pools, check that threading is enabled
313   dnl #
314   if test "$WITH_THREADS" != "yes"; then
315     AC_MSG_ERROR(You must have threads enabled for thread pools to work.)
316   fi
317
318   dnl #
319   dnl # If using thread pools, check that we have thread libraries
320   dnl #
321   if test "X$PTHREADLIB" = "X"; then
322     AC_MSG_ERROR(You must have threading libraries for thread pools to work.)
323   fi
324
325 dnl #
326 dnl #  Check for sem_init all by itself
327 dnl #
328   AC_CHECK_FUNC(sem_init)
329   if test "X$ac_cv_func_sem_init" = "Xno"; then
330
331 dnl #
332 dnl #  If not found, sem_init is in -lposix4 on Solaris
333 dnl #
334     AC_CHECK_LIB(posix4, sem_init)
335
336     if test "X$ac_cv_lib_posix4_sem_init" = "X"; then
337       AC_MSG_WARN(You do not have posix semaphores.  Disabling thread pools)
338       WITH_THREAD_POOL=no
339     fi
340   fi
341
342 dnl #
343 dnl #  Finally, after all of the checks above, we see if
344 dnl #  we can REALLY use the thread pools.
345 dnl #
346   if test "$WITH_THREAD_POOL" = "yes"; then
347     AC_DEFINE(WITH_THREAD_POOL,1)
348   fi
349 fi
350
351 dnl Check if we need -lsocket
352 AC_CHECK_LIB(socket, getsockname)
353
354 dnl Check for -lresolv
355 dnl This library may be needed later.
356 AC_CHECK_LIB(resolv, inet_aton)
357
358 dnl Check if we need -lnsl. Usually if we want to
359 dnl link against -lsocket we need to include -lnsl as well.
360 AC_CHECK_LIB(nsl, inet_ntoa)
361
362 dnl #############################################################
363 dnl #
364 dnl #  3. Checks for header files
365 dnl #
366 dnl #############################################################
367
368 AC_HEADER_DIRENT
369 AC_HEADER_STDC
370 AC_HEADER_TIME
371 AC_HEADER_SYS_WAIT
372
373 AC_CHECK_HEADERS( \
374         unistd.h \
375         crypt.h \
376         errno.h \
377         resource.h \
378         getopt.h \
379         malloc.h \
380         utmp.h \
381         utmpx.h \
382         sys/select.h \
383         regex.h \
384         syslog.h \
385         inttypes.h \
386         stdint.h \
387         arpa/inet.h \
388         netinet/in.h \
389         sys/types.h \
390         sys/time.h
391 )
392
393 dnl #############################################################
394 dnl #
395 dnl #  4. Checks for typedefs
396 dnl #
397 dnl #############################################################
398
399 dnl #
400 dnl # Ensure that these are defined
401 dnl #
402 AC_TYPE_OFF_T 
403 AC_TYPE_PID_T
404 AC_TYPE_SIZE_T
405 AC_TYPE_UID_T
406
407 dnl Check for socklen_t
408 AC_CACHE_CHECK(for socklen_t,
409                fr_cv_socklen_t,
410     [ fr_cv_socklen_t=no
411       AC_TRY_COMPILE([#include <sys/types.h>
412         #include <sys/socket.h>],
413         [socklen_t foo],
414         fr_cv_socklen_t=yes,
415       )
416      ]
417 )
418
419 if test "$fr_cv_socklen_t" != "yes"; then
420          AC_DEFINE(socklen_t, int)
421 fi
422
423 dnl Check for uint8_t
424 AC_CACHE_CHECK(for uint8_t,
425                fr_cv_uint8_t,
426      [ fr_cv_uint8_t=no
427        AC_TRY_COMPILE([
428 #ifdef HAVE_INTTYPES_H
429 #include <inttypes.h>
430 #endif
431 #ifdef HAVE_STDINT_H
432 #include <stdint.h>
433 #endif
434 ],
435          [uint8_t foo],
436          fr_cv_uint8_t=yes
437        )
438      ]
439 )
440
441 if test "$fr_cv_uint8_t" != "yes"; then
442          AC_DEFINE(uint8_t, unsigned char)
443 fi
444
445 dnl Check for uint32_t
446 AC_CACHE_CHECK(for uint32_t,
447                fr_cv_uint32_t,
448      [ fr_cv_uint32_t=no
449        AC_TRY_COMPILE([
450 #ifdef HAVE_INTTYPES_H
451 #include <inttypes.h>
452 #endif
453 #ifdef HAVE_STDINT_H
454 #include <stdint.h>
455 #endif
456 ],
457          [uint32_t foo],
458          fr_cv_uint32_t=yes
459        )
460      ]
461 )
462
463 if test "$fr_cv_uint32_t" != "yes"; then
464         AC_DEFINE(uint32_t, unsigned int)
465         UINT32_T_AS_INT=yes
466 fi
467
468 dnl #
469 dnl #  If we don't have uint32_t, then verify that sizeof(unsigned int)==4
470 dnl #  If the integers are NOT 4 octets long, then the previous definition
471 dnl #  won't work, and we won't produce correct RADIUS packets.
472 dnl #
473 if test "x$UINT32_T_AS_INT" != "x"; then
474   AC_CHECK_SIZEOF(unsigned int, [4])
475 fi
476
477 dnl #############################################################
478 dnl #
479 dnl #  5. Checks for structures and functions
480 dnl #
481 dnl #############################################################
482 AC_CHECK_FUNCS( \
483         getopt_long \
484         lockf \
485         strsignal \
486         sigaction \
487         sigprocmask \
488         snprintf \
489         vsnprintf \
490         setsid \
491         strncasecmp \
492         strcasecmp \
493         strsep \
494         inet_aton \
495         gethostname \
496         setlinebuf \
497         setvbuf \
498         getusershell
499 )
500 RADIUSD_NEED_DECLARATIONS( \
501         crypt \
502         strncasecmp \
503         strcasecmp \
504         inet_aton \
505         gethostname \
506         setlinebuf \
507         getusershell \
508         endusershell
509 )
510
511 AC_TYPE_SIGNAL
512
513 dnl #############################################################
514 dnl #
515 dnl #  6. Checks for compiler characteristics
516 dnl #
517 dnl #############################################################
518
519 dnl #
520 dnl # Ensure that these are defined
521 dnl #
522 AC_C_CONST 
523
524 dnl #
525 dnl # See if this is OS/2
526 dnl #
527 AC_MSG_CHECKING(type of OS)
528 OS=`uname -s`
529 AC_MSG_RESULT($OS)
530 if test "$OS" = "OS/2"; then
531         LIBPREFIX=
532 else
533         LIBPREFIX=lib
534 fi
535 AC_SUBST(LIBPREFIX)
536
537 dnl #
538 dnl # Set Default CFLAGS
539 dnl #
540 if test "$GCC" = "yes"; then
541     CFLAGS="$CFLAGS -Wall -D_GNU_SOURCE"
542 fi
543
544 dnl #############################################################
545 dnl #
546 dnl #  7. Checks for library functions
547 dnl #
548 dnl #############################################################
549
550 dnl Check for libcrypt
551 dnl We use crypt(3) which may be in libc, or in libcrypt (eg FreeBSD)
552 AC_CHECK_LIB(crypt, crypt,
553   CRYPTLIB="-lcrypt"
554 )
555 AC_SUBST(CRYPTLIB)
556 if test "$CRYPTLIB" != ""; then
557   AC_DEFINE(HAVE_CRYPT)
558 else
559   AC_CHECK_FUNC(crypt, AC_DEFINE(HAVE_CRYPT))
560 fi
561
562 dnl #############################################################
563 dnl #
564 dnl #  8. Checks for system services
565 dnl #
566 dnl #############################################################
567
568 dnl #
569 dnl # Figure out where libtool is located,
570 dnl #
571 LIBTOOL="`pwd`/libtool"
572 AC_SUBST(LIBTOOL)
573 AC_SUBST(LIBLTDL)
574 AC_SUBST(INCLTDL)
575 top_builddir=`pwd`
576 AC_SUBST(top_builddir)
577
578 dnl #############################################################
579 dnl #
580 dnl #  And finally, output the results.
581 dnl #
582 dnl #############################################################
583
584 dnl #
585 dnl #  Substitute whatever libraries we found to be necessary
586 dnl #
587 AC_SUBST(LIBS)
588
589 AC_OUTPUT(\
590         ./Make.inc \
591         ./src/include/build-radpaths-h \
592         ./src/main/checkrad.pl \
593         ./src/main/radlast \
594         ./src/main/radtest \
595         ./scripts/rc.radiusd \
596         ./scripts/radwatch \
597         ./scripts/check-radiusd-config \
598         ./raddb/radiusd.conf
599 )
600
601 AC_OUTPUT_COMMANDS([echo timestamp > src/include/stamp-h])
602 AC_OUTPUT_COMMANDS([(cd ./src/include && /bin/sh ./build-radpaths-h)])
603 AC_OUTPUT_COMMANDS([(cd ./src/main   && chmod +x checkrad.pl radlast radtest)])
604 AC_OUTPUT_COMMANDS([(cd ./scripts    && chmod +x rc.radiusd radwatch check-radiusd-config)])