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_INSTALL
39 AC_PROG_RANLIB
40
41 PACKAGE=freeradius
42
43 dnl Find GNU Make.
44 AC_CHECK_PROG(GMAKE, gmake, yes, no)
45 if test $GMAKE = no; then
46   AC_PATH_PROG(MAKE, make, /usr/local/bin/make)
47 else
48   AC_PATH_PROG(MAKE, gmake, /usr/local/gnu/bin/make)
49 fi
50 makever=`$ac_cv_path_MAKE --version 2>&1 | grep "GNU Make"`
51 if test -z "$makever"; then
52   AC_MSG_ERROR(GNU Make is not installed.  Please download and install it
53                 from ftp://prep.ai.mit.edu/pub/gnu/make/ before continuing.)
54 fi
55
56 dnl libltdl is installable
57 AC_LIBLTDL_INSTALLABLE
58
59 dnl ensure that we're looking for dlopen
60 AC_LIBTOOL_DLOPEN
61
62 dnl Figure out how to build shared libraries
63 AC_PROG_LIBTOOL
64
65 dnl extra argument: --with-logdir
66 logdir='${localstatedir}/log'
67 AC_MSG_CHECKING(logdir)
68 AC_ARG_WITH(logdir,
69 [  --with-logdir=DIR       Directory for logfiles [LOCALSTATEDIR/log] ],
70 [ case "$withval" in
71     no)
72         AC_MSG_ERROR(Need logdir)
73         ;;
74     yes)
75         ;;
76     *)
77         logdir="$withval"
78         ;;
79   esac ]
80 )
81 AC_SUBST(logdir)
82 AC_MSG_RESULT($logdir)
83
84 dnl extra argument: --with-radacctdir
85 radacctdir='${logdir}/radacct'
86 AC_MSG_CHECKING(radacctdir)
87 AC_ARG_WITH(radacctdir,
88 [  --with-radacctdir=PATH  Directory for detail files [LOGDIR/radacct] ],
89 [ case "$withval" in
90     no)
91         AC_MSG_ERROR(Need radacctdir)
92         ;;
93     yes)
94         ;;
95     *)
96         radacctdir="$withval"
97         ;;
98   esac ]
99 )
100 AC_SUBST(radacctdir)
101 AC_MSG_RESULT($radacctdir)
102
103 dnl extra argument: --with-raddbdir
104 raddbdir='${sysconfdir}/raddb'
105 AC_MSG_CHECKING(raddbdir)
106 AC_ARG_WITH(raddbdir,
107 [  --with-raddbdir=DIR     Directory for config files [SYSCONFDIR/raddb] ],
108 [ case "$withval" in
109     no)
110         AC_MSG_ERROR(Need raddbdir)
111         ;;
112     yes)
113         ;;
114     *)
115         raddbdir="$withval"
116         ;;
117   esac ]
118 )
119 AC_SUBST(raddbdir)
120 AC_MSG_RESULT($raddbdir)
121
122 dnl extra argument: --with-dict-nocase
123 WITH_DICT_NOCASE=yes
124 AC_ARG_WITH(dict-nocase,
125 [  --with-dict-nocase      Make dictionary case-independant (default=yes)],
126 [  case "$withval" in
127     yes)
128         ;;
129     *)
130         WITH_DICT_NOCASE=""
131   esac ]
132 )
133 if test "X$WITH_DICT_NOCASE" = "Xyes"; then
134   AC_DEFINE(WITH_DICT_NOCASE)
135 fi
136
137 dnl extra argument: --with-attrib-nmc
138 ATTRIB_NMC=yes
139 AC_ARG_WITH(attrib-nmc,
140 [  --with-attrib-nmc       Include USR-style vendor specific attributes (default=yes)],
141 [ case "$withval" in
142     yes)
143         ;;
144     *)
145         ATTRIB_NMC=""
146   esac ]
147 )
148 if test "X$ATTRIB_NMC" = "Xyes"; then
149   AC_DEFINE(ATTRIB_NMC)
150 fi
151
152 dnl extra argument: --with-ascend-binary
153 ASCEND_BINARY=yes
154 AC_ARG_WITH(ascend-binary,
155 [  --with-ascend-binary    Include support for Ascend binary filter attributes (default=yes)],
156 [ case "$withval" in
157     yes)
158         ;;
159     *)
160         ASCEND_BINARY=""
161   esac ]
162 )
163 if test "X$ASCEND_BINARY" = "Xyes"; then
164   AC_DEFINE(ASCEND_BINARY)
165 fi
166
167 dnl extra argument: --with-threads
168 WITH_THREADS=yes
169 AC_ARG_WITH(threads,
170 [  --with-threads          Use threads, if available.  (default=yes) ],
171 [ case "$withval" in
172     yes)
173         ;;
174     *)
175         WITH_THREADS=""
176   esac ]
177 )
178
179 dnl extra argument: --with-thread-pool
180 WITH_THREAD_POOL=no
181 AC_ARG_WITH(thread-pool,
182 [  --with-thread-pool      Use a pool of threads for high-load systems.  (default=no) ],
183 [ case "$withval" in
184     *)
185         WITH_THREAD_POOL=$withval
186   esac ]
187 )
188
189 dnl extra argument: --with-snmp
190 AC_ARG_WITH(snmp,
191 [  --with-snmp             Compile in SNMP support. (default=no)],
192 [ case "$withval" in
193     no)
194         ;;
195     yes)
196         AC_DEFINE(WITH_SNMP)
197         SNMPLIB="-lsnmp -lcrypto"
198         SNMPINC=-I/usr/include/ucd-snmp
199   esac ]
200 )
201
202 AC_SUBST(SNMPLIB)
203 AC_SUBST(SNMPINC)
204
205
206 AC_ARG_ENABLE(ltdl-install,
207 [  --disable-ltdl-install  do not install libltdl])
208 if test x"${enable_ltdl_install+set}" != xset; then
209   enable_ltdl_install=yes
210   ac_configure_args="$ac_configure_args --enable-ltdl-install"
211 fi
212 AC_CONFIG_SUBDIRS(libltdl)
213
214 dnl See what include-style is used by the make program.
215 dnl AC_MSG_CHECKING(include style for make)
216 dnl echo "include /dev/null" > testmake.$$
217 dnl echo "all:" >> testmake.$$
218 dnl make -f testmake.$$ >/dev/null 2>&1
219 dnl if test $? = 0
220 dnl then
221 dnl     INCLUDE=include
222 dnl     IQUOTE=
223 dnl else
224 dnl     INCLUDE=.include
225 dnl     IQUOTE='"'
226 dnl fi
227 dnl rm -f testmake.$$
228 dnl AC_MSG_RESULT(" $INCLUDE")
229 dnl AC_SUBST(INCLUDE)
230 dnl AC_SUBST(IQUOTE)
231
232 dnl #############################################################
233 dnl #
234 dnl #  1. Checks for programs
235 dnl #
236 dnl #############################################################
237
238 AC_PATH_PROG(PERL, perl, /usr/local/bin/perl)
239 if test ! -x $ac_cv_path_PERL; then
240   AC_MSG_ERROR(perl not found - fatal)
241 fi
242 AC_PATH_PROG(SNMPGET, snmpget, /usr/local/bin/snmpget)
243 AC_PATH_PROG(SNMPWALK, snmpwalk, /usr/local/bin/snmpwalk)
244 AC_PATH_PROG(RUSERS, rusers, /usr/bin/rusers)
245
246 dnl FIXME This is truly gross.
247 missing_dir=`cd $ac_aux_dir && pwd`
248 AM_MISSING_PROG(ACLOCAL, aclocal, $missing_dir)
249 AM_MISSING_PROG(AUTOCONF, autoconf, $missing_dir)
250 AM_MISSING_PROG(AUTOHEADER, autoheader, $missing_dir)
251
252 dnl #
253 dnl # check for AIX, to allow us to use some BSD functions
254 dnl # must be before macros that call the compiler.
255 dnl #
256 AC_AIX
257
258 dnl #############################################################
259 dnl #
260 dnl #  2. Checks for libraries
261 dnl #
262 dnl #############################################################
263
264 dnl If using pthreads, check for -lpthread (posix) or -lc_r (*BSD)
265 PTHREADLIB=
266 if test "$WITH_THREADS" = "yes"; then 
267   if test $ac_cv_prog_suncc = "yes"; then
268     CFLAGS="$CFLAGS -mt"
269   fi
270
271   AC_CHECK_HEADERS(pthread.h)
272
273   if test "X$ac_cv_header_pthread_h" = "X"; then
274     AC_MSG_ERROR("You are trying to use threads without a POSIX <pthread.h>")
275   fi
276
277 dnl # 
278 dnl # pthread stuff is usually in -lpthread
279 dnl # 
280   AC_CHECK_LIB(pthread, pthread_create,
281     PTHREADLIB="-lpthread"
282   )
283
284 dnl # 
285 dnl # Except for *BSD, where it's in -lc_r,
286 dnl # and where we've got to add extra CFLAGS.
287 dnl # 
288   if test "X$PTHREADLIB" = "X"; then
289     SAVED_CFLAGS=$CFLAGS
290     CFLAGS="$CFLAGS -pthread -D_THREAD_SAFE"
291     AC_CHECK_LIB(c_r, pthread_create,
292       PTHREADLIB="-lc_r"
293     )
294   fi
295
296 dnl # 
297 dnl # If we have NO pthread libraries, remove any knowledge of threads.
298 dnl # 
299   if test "x$PTHREADLIB" = "x"; then
300     CFLAGS=$SAVED_CFLAGS
301     ac_cv_header_pthread_h="no"
302   else
303     LIBS="$LIBS $PTHREADLIB"
304     CFLAGS="$CFLAGS -D_REENTRANT"
305   fi
306 fi
307
308 dnl #
309 dnl #  Checks to ensure that the thread pool code can build.
310 dnl #
311 if test "$WITH_THREAD_POOL" = "yes"; then
312   dnl #
313   dnl # If using thread pools, check that threading is enabled
314   dnl #
315   if test "$WITH_THREADS" != "yes"; then
316     AC_MSG_ERROR(You must have threads enabled for thread pools to work.)
317   fi
318
319   dnl #
320   dnl # If using thread pools, check that we have thread libraries
321   dnl #
322   if test "X$PTHREADLIB" = "X"; then
323     AC_MSG_ERROR(You must have threading libraries for thread pools to work.)
324   fi
325
326 dnl #
327 dnl #  Check for sem_init all by itself
328 dnl #
329   AC_CHECK_FUNC(sem_init)
330   if test "X$ac_cv_func_sem_init" = "Xno"; then
331
332 dnl #
333 dnl #  If not found, sem_init is in -lposix4 on Solaris
334 dnl #
335     AC_CHECK_LIB(posix4, sem_init)
336
337     if test "X$ac_cv_lib_posix4_sem_init" = "X"; then
338       AC_MSG_WARN(You do not have posix semaphores.  Disabling thread pools)
339       WITH_THREAD_POOL=no
340     fi
341   fi
342
343 dnl #
344 dnl #  Finally, after all of the checks above, we see if
345 dnl #  we can REALLY use the thread pools.
346 dnl #
347   if test "$WITH_THREAD_POOL" = "yes"; then
348     AC_DEFINE(WITH_THREAD_POOL,1)
349   fi
350 fi
351
352 dnl Check if we need -lsocket
353 AC_CHECK_LIB(socket, getsockname)
354
355 dnl Check for -lresolv
356 dnl This library may be needed later.
357 AC_CHECK_LIB(resolv, inet_aton)
358
359 dnl Check if we need -lnsl. Usually if we want to
360 dnl link against -lsocket we need to include -lnsl as well.
361 AC_CHECK_LIB(nsl, inet_ntoa)
362
363 dnl #############################################################
364 dnl #
365 dnl #  3. Checks for header files
366 dnl #
367 dnl #############################################################
368
369 AC_HEADER_DIRENT
370 AC_HEADER_STDC
371 AC_HEADER_TIME
372 AC_HEADER_SYS_WAIT
373
374 AC_CHECK_HEADERS( \
375         unistd.h \
376         crypt.h \
377         errno.h \
378         resource.h \
379         getopt.h \
380         malloc.h \
381         utmp.h \
382         utmpx.h \
383         sys/select.h \
384         regex.h \
385         syslog.h \
386         inttypes.h \
387         stdint.h \
388         arpa/inet.h \
389         netinet/in.h \
390         sys/types.h \
391         sys/time.h
392 )
393
394 dnl #############################################################
395 dnl #
396 dnl #  4. Checks for typedefs
397 dnl #
398 dnl #############################################################
399
400 dnl #
401 dnl # Ensure that these are defined
402 dnl #
403 AC_TYPE_OFF_T 
404 AC_TYPE_PID_T
405 AC_TYPE_SIZE_T
406 AC_TYPE_UID_T
407
408 dnl Check for socklen_t
409 AC_CACHE_CHECK(for socklen_t,
410                fr_cv_socklen_t,
411     [ fr_cv_socklen_t=no
412       AC_TRY_COMPILE([#include <sys/types.h>
413         #include <sys/socket.h>],
414         [socklen_t foo],
415         fr_cv_socklen_t=yes,
416       )
417      ]
418 )
419
420 if test "$fr_cv_socklen_t" != "yes"; then
421          AC_DEFINE(socklen_t, int)
422 fi
423
424 dnl Check for uint8_t
425 AC_CACHE_CHECK(for uint8_t,
426                fr_cv_uint8_t,
427      [ fr_cv_uint8_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          [uint8_t foo],
437          fr_cv_uint8_t=yes
438        )
439      ]
440 )
441
442 if test "$fr_cv_uint8_t" != "yes"; then
443          AC_DEFINE(uint8_t, unsigned char)
444 fi
445
446 dnl Check for uint32_t
447 AC_CACHE_CHECK(for uint32_t,
448                fr_cv_uint32_t,
449      [ fr_cv_uint32_t=no
450        AC_TRY_COMPILE([
451 #ifdef HAVE_INTTYPES_H
452 #include <inttypes.h>
453 #endif
454 #ifdef HAVE_STDINT_H
455 #include <stdint.h>
456 #endif
457 ],
458          [uint32_t foo],
459          fr_cv_uint32_t=yes
460        )
461      ]
462 )
463
464 if test "$fr_cv_uint32_t" != "yes"; then
465         AC_DEFINE(uint32_t, unsigned int)
466         UINT32_T_AS_INT=yes
467 fi
468
469 dnl #
470 dnl #  If we don't have uint32_t, then verify that sizeof(unsigned int)==4
471 dnl #  If the integers are NOT 4 octets long, then the previous definition
472 dnl #  won't work, and we won't produce correct RADIUS packets.
473 dnl #
474 if test "x$UINT32_T_AS_INT" != "x"; then
475   AC_CHECK_SIZEOF(unsigned int, [4])
476 fi
477
478 dnl #############################################################
479 dnl #
480 dnl #  5. Checks for structures and functions
481 dnl #
482 dnl #############################################################
483 AC_CHECK_FUNCS( \
484         getopt_long \
485         lockf \
486         strsignal \
487         sigaction \
488         sigprocmask \
489         snprintf \
490         vsnprintf \
491         setsid \
492         strncasecmp \
493         strcasecmp \
494         strsep \
495         inet_aton \
496         gethostname \
497         setlinebuf \
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 AC_SUBST(INSTALL)
589 AC_SUBST(INSTALL_PROGRAM)
590 AC_SUBST(INSTALL_DATA)
591 AC_SUBST(INSTALL_SCRIPT)
592
593 AC_OUTPUT(\
594         ./Make.inc \
595         ./src/include/build-radpaths-h \
596         ./src/main/checkrad.pl \
597         ./src/main/radlast \
598         ./src/main/radtest \
599         ./scripts/rc.radiusd \
600         ./scripts/radwatch \
601         ./scripts/check-radiusd-config \
602         ./raddb/radiusd.conf
603 )
604
605 AC_OUTPUT_COMMANDS([echo timestamp > src/include/stamp-h])
606 AC_OUTPUT_COMMANDS([(cd ./src/include && /bin/sh ./build-radpaths-h)])
607 AC_OUTPUT_COMMANDS([(cd ./src/main   && chmod +x checkrad.pl radlast radtest)])
608 AC_OUTPUT_COMMANDS([(cd ./scripts    && chmod +x rc.radiusd radwatch check-radiusd-config)])