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