Fix check for shared library using libtool info, instead of assuming extension
[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
27 dnl # The version of the software, first beta, is 0.1
28 RADIUSD_VERSION=0.1
29
30 dnl #############################################################
31 dnl #
32 dnl #  0. Checks for compiler, libtool, and command line options.
33 dnl #
34 dnl #############################################################
35
36 dnl Check for GNU cc
37 AC_PROG_CC
38 AC_PROG_GCC_TRADITIONAL
39 AC_PROG_CC_SUNPRO
40 AC_PROG_RANLIB
41
42 PACKAGE=freeradius
43
44 dnl Find GNU Make.
45 AC_CHECK_PROG(GMAKE, gmake, yes, no)
46 if test $GMAKE = no; then
47   AC_PATH_PROG(MAKE, make, /usr/local/bin/make)
48 else
49   AC_PATH_PROG(MAKE, gmake, /usr/local/gnu/bin/make)
50 fi
51 makever=`$ac_cv_path_MAKE --version 2>&1 | grep "GNU Make"`
52 if test -z "$makever"; then
53   AC_MSG_ERROR(GNU Make is not installed.  Please download and install it
54                 from ftp://prep.ai.mit.edu/pub/gnu/make/ before continuing.)
55 fi
56
57 dnl libltdl is installable
58 AC_LIBLTDL_INSTALLABLE
59
60 dnl ensure that we're looking for dlopen
61 AC_LIBTOOL_DLOPEN
62
63 dnl Figure out how to build shared libraries
64 AC_PROG_LIBTOOL
65
66 dnl Put this in later, when all distributed modules use autoconf.
67 dnl AC_ARG_WITH(disablemodulefoo,
68 dnl [  --without-rlm_foo       Disables module compilation.  Module list:]
69 dnl esyscmd([find src/modules -type d -name rlm_\* -print |\
70 dnl     sed -e 's%src/modules/.*/% (sub)- %; s%.*/%- %' |\
71 dnl     awk '{print "                            "$0}']))
72
73 AC_ARG_ENABLE(strict-dependencies,
74 [  --enable-strict-dependencies  Fail configure on lack of module dependancy.])
75
76 AC_ARG_WITH(fooincludedir,
77 [  --with-FOO-include-dir=DIR   Dir for includes for FOO, module dependancy.])
78
79 AC_ARG_WITH(foolibdir,
80 [  --with-FOO-lib-dir=DIR  Dir for libraries for FOO, module dependancy.])
81
82 dnl extra argument: --with-logdir
83 logdir='${localstatedir}/log/radius'
84 AC_MSG_CHECKING(logdir)
85 AC_ARG_WITH(logdir,
86 [  --with-logdir=DIR       Directory for logfiles [LOCALSTATEDIR/log/radius] ],
87 [ case "$withval" in
88     no)
89         AC_MSG_ERROR(Need logdir)
90         ;;
91     yes)
92         ;;
93     *)
94         logdir="$withval"
95         ;;
96   esac ]
97 )
98 AC_SUBST(logdir)
99 AC_MSG_RESULT($logdir)
100
101 dnl extra argument: --with-radacctdir
102 radacctdir='${logdir}/radacct'
103 AC_MSG_CHECKING(radacctdir)
104 AC_ARG_WITH(radacctdir,
105 [  --with-radacctdir=PATH  Directory for detail files [LOGDIR/radacct] ],
106 [ case "$withval" in
107     no)
108         AC_MSG_ERROR(Need radacctdir)
109         ;;
110     yes)
111         ;;
112     *)
113         radacctdir="$withval"
114         ;;
115   esac ]
116 )
117 AC_SUBST(radacctdir)
118 AC_MSG_RESULT($radacctdir)
119
120 dnl extra argument: --with-raddbdir
121 raddbdir='${sysconfdir}/raddb'
122 AC_MSG_CHECKING(raddbdir)
123 AC_ARG_WITH(raddbdir,
124 [  --with-raddbdir=DIR     Directory for config files [SYSCONFDIR/raddb] ],
125 [ case "$withval" in
126     no)
127         AC_MSG_ERROR(Need raddbdir)
128         ;;
129     yes)
130         ;;
131     *)
132         raddbdir="$withval"
133         ;;
134   esac ]
135 )
136 AC_SUBST(raddbdir)
137 AC_MSG_RESULT($raddbdir)
138
139 dnl extra argument: --with-dict-nocase
140 WITH_DICT_NOCASE=yes
141 AC_ARG_WITH(dict-nocase,
142 [  --with-dict-nocase      Make dictionary case-independant (default=yes)],
143 [  case "$withval" in
144     yes)
145         ;;
146     *)
147         WITH_DICT_NOCASE=""
148   esac ]
149 )
150 if test "X$WITH_DICT_NOCASE" = "Xyes"; then
151   AC_DEFINE(WITH_DICT_NOCASE)
152 fi
153
154 dnl extra argument: --with-ascend-binary
155 ASCEND_BINARY=yes
156 AC_ARG_WITH(ascend-binary,
157 [  --with-ascend-binary    Include support for Ascend binary filter attributes (default=yes)],
158 [ case "$withval" in
159     yes)
160         ;;
161     *)
162         ASCEND_BINARY=""
163   esac ]
164 )
165 if test "X$ASCEND_BINARY" = "Xyes"; then
166   AC_DEFINE(ASCEND_BINARY)
167 fi
168
169 dnl extra argument: --with-threads
170 WITH_THREADS=yes
171 AC_ARG_WITH(threads,
172 [  --with-threads          Use threads, if available.  (default=yes) ],
173 [ case "$withval" in
174     yes)
175         ;;
176     *)
177         WITH_THREADS=""
178   esac ]
179 )
180
181 dnl extra argument: --with-thread-pool
182 WITH_THREAD_POOL=no
183 AC_ARG_WITH(thread-pool,
184 [  --with-thread-pool      Use a pool of threads for high-load systems.  (default=no) ],
185 [ case "$withval" in
186     yes)
187         WITH_THREAD_POOL=yes
188         ;;
189     *)
190         ;;
191   esac ]
192 )
193
194 dnl extra argument: --with-snmp
195 WITH_SNMP=yes
196 AC_ARG_WITH(snmp,
197 [  --with-snmp             Compile in SNMP support. (default=yes)],
198 [ case "$withval" in
199     yes)
200         ;;
201     *)
202         WITH_SNMP=no
203   esac ]
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 #
215 dnl #  Allow the user to specify a list of modules to be linked
216 dnl #  statically to the server.
217 dnl #
218 STATIC_MODULES=
219 AC_ARG_WITH(static_modules,
220 [  --with-static-modules=QUOTED-MODULE-LIST],[
221   for i in $withval; do
222     STATIC_MODULES="$STATIC_MODULES -dlpreopen ../modules/rlm_$i/rlm_$i.la"
223   done
224 ])
225
226 dnl #
227 dnl #  Enable developer C compiler warnings
228 dnl #
229 AC_ARG_ENABLE(developer,
230 [  --enable-developer      Turns on flags of interest to developers.],
231 [ case "$withval" in
232     *)
233         developer=no
234         ;;
235     yes)
236         developer=yes
237   esac ]
238 )
239
240 if test "x$developer" != "xno" -a -d $srcdir/CVS; then
241   dnl turn on the developer flag when taken from a CVS checkout (not a release)
242   developer="yes"
243 fi
244
245 dnl See what include-style is used by the make program.
246 dnl AC_MSG_CHECKING(include style for make)
247 dnl echo "include /dev/null" > testmake.$$
248 dnl echo "all:" >> testmake.$$
249 dnl make -f testmake.$$ >/dev/null 2>&1
250 dnl if test $? = 0
251 dnl then
252 dnl     INCLUDE=include
253 dnl     IQUOTE=
254 dnl else
255 dnl     INCLUDE=.include
256 dnl     IQUOTE='"'
257 dnl fi
258 dnl rm -f testmake.$$
259 dnl AC_MSG_RESULT(" $INCLUDE")
260 dnl AC_SUBST(INCLUDE)
261 dnl AC_SUBST(IQUOTE)
262
263 dnl #############################################################
264 dnl #
265 dnl #  1. Checks for programs
266 dnl #
267 dnl #############################################################
268
269 AC_PATH_PROG(PERL, perl, /usr/local/bin/perl)
270 if test ! -x $ac_cv_path_PERL; then
271   AC_MSG_ERROR(perl not found - fatal)
272 fi
273 AC_PATH_PROG(SNMPGET, snmpget, /usr/local/bin/snmpget)
274 AC_PATH_PROG(SNMPWALK, snmpwalk, /usr/local/bin/snmpwalk)
275 AC_PATH_PROG(RUSERS, rusers, /usr/bin/rusers)
276
277 dnl FIXME This is truly gross.
278 missing_dir=`cd $ac_aux_dir && pwd`
279 AM_MISSING_PROG(ACLOCAL, aclocal, $missing_dir)
280 AM_MISSING_PROG(AUTOCONF, autoconf, $missing_dir)
281 AM_MISSING_PROG(AUTOHEADER, autoheader, $missing_dir)
282
283 AC_PATH_PROG(LOCATE,locate)
284 AC_PATH_PROG(DIRNAME,dirname)
285 AC_PATH_PROG(GREP,grep)
286
287 dnl #
288 dnl # check for AIX, to allow us to use some BSD functions
289 dnl # must be before macros that call the compiler.
290 dnl #
291 AC_AIX
292
293 dnl #############################################################
294 dnl #
295 dnl #  2. Checks for libraries
296 dnl #
297 dnl #############################################################
298
299 dnl If using pthreads, check for -lpthread (posix) or -lc_r (*BSD)
300 PTHREADLIB=
301 if test "$WITH_THREADS" = "yes"; then 
302   if test $ac_cv_prog_suncc = "yes"; then
303     CFLAGS="$CFLAGS -mt"
304   fi
305
306   AC_CHECK_HEADERS(pthread.h)
307
308   if test "X$ac_cv_header_pthread_h" = "X"; then
309     AC_MSG_ERROR("You are trying to use threads without a POSIX <pthread.h>")
310   fi
311
312 dnl # 
313 dnl # pthread stuff is usually in -lpthread
314 dnl # 
315   AC_CHECK_LIB(pthread, pthread_join,
316     PTHREADLIB="-lpthread"
317   )
318
319 dnl # HP/UX requires linking with librt, too, to get the sem_* symbols.  :\
320
321   AC_SEARCH_LIBS(sem_init, pthread rt,
322         [ 
323         dnl    Er, this usage of $ac_cv_search_sem_init may be unfounded 
324         dnl    chumminess with the autoconf internals.  -chad
325         PTHREADLIB="$PTHREADLIB $ac_cv_search_sem_init"
326         ],
327         [],
328         "-lpthread"
329   )
330
331 dnl # 
332 dnl # Except for *BSD, where it's in -lc_r,
333 dnl # and where we've got to add extra CFLAGS.
334 dnl # 
335   if test "X$PTHREADLIB" = "X"; then
336     SAVED_CFLAGS=$CFLAGS
337     CFLAGS="$CFLAGS -pthread -D_THREAD_SAFE"
338     AC_CHECK_LIB(c_r, pthread_create,
339       PTHREADLIB="-lc_r"
340     )
341   fi
342
343 dnl # 
344 dnl # If we have NO pthread libraries, remove any knowledge of threads.
345 dnl # 
346   if test "x$PTHREADLIB" = "x"; then
347     CFLAGS=$SAVED_CFLAGS
348     ac_cv_header_pthread_h="no"
349   else
350     LIBS="$LIBS $PTHREADLIB"
351     CFLAGS="$CFLAGS -D_REENTRANT"
352   fi
353 fi
354
355 dnl Check if we need -lsocket
356 AC_CHECK_LIB(socket, getsockname)
357
358 dnl Check for -lresolv
359 dnl This library may be needed later.
360 AC_CHECK_LIB(resolv, inet_aton)
361
362 dnl Check if we need -lnsl. Usually if we want to
363 dnl link against -lsocket we need to include -lnsl as well.
364 AC_CHECK_LIB(nsl, inet_ntoa)
365
366 dnl #############################################################
367 dnl #
368 dnl #  3. Checks for header files
369 dnl #
370 dnl #############################################################
371
372 AC_HEADER_DIRENT
373 AC_HEADER_STDC
374 AC_HEADER_TIME
375 AC_HEADER_SYS_WAIT
376
377 AC_CHECK_HEADERS( \
378         unistd.h \
379         crypt.h \
380         errno.h \
381         resource.h \
382         getopt.h \
383         malloc.h \
384         utmp.h \
385         utmpx.h \
386         signal.h \
387         sys/select.h \
388         syslog.h \
389         inttypes.h \
390         stdint.h \
391         stdio.h \
392         netdb.h \
393         semaphore.h \
394         arpa/inet.h \
395         netinet/in.h \
396         sys/types.h \
397         sys/socket.h \
398         sys/time.h
399 )
400
401 REGEX=no
402 AC_CHECK_HEADER(regex.h, AC_DEFINE(HAVE_REGEX_H))
403 if test "x$ac_cv_header_regex_h" = "xyes"; then
404   REGEX_EXTENDED=no
405   REGEX=yes
406   AC_EGREP_CPP(yes,
407     [#include <regex.h>
408      #ifdef REG_EXTENDED
409        yes
410      #endif
411      ], [AC_DEFINE(HAVE_REG_EXTENDED) REGEX_EXTENDED=yes])
412 fi
413 AC_SUBST(REGEX)
414 AC_SUBST(REGEX_EXTENDED)
415
416
417 dnl #############################################################
418 dnl #
419 dnl #  4. Checks for typedefs
420 dnl #
421 dnl #############################################################
422
423 dnl #
424 dnl # Ensure that these are defined
425 dnl #
426 AC_TYPE_OFF_T 
427 AC_TYPE_PID_T
428 AC_TYPE_SIZE_T
429 AC_TYPE_UID_T
430
431 dnl check for socklen_t
432 AC_CHECK_TYPE_INCLUDE([
433 #ifdef HAVE_SYS_TYPES_H
434 #include <sys/types.h>
435 #endif
436 #ifdef HAVE_SYS_SOCKET_H
437 #include <sys/socket.h>
438 #endif
439 ],socklen_t, int)
440
441 dnl check for uint8_t
442 AC_CHECK_TYPE_INCLUDE([
443 #ifdef HAVE_INTTYPES_H
444 #include <inttypes.h>
445 #endif
446 #ifdef HAVE_STDINT_H
447 #include <stdint.h>
448 #endif
449 ],uint8_t, unsigned char)
450
451 dnl check for uint32_t
452 AC_CHECK_TYPE_INCLUDE([
453 #ifdef HAVE_INTTYPES_H
454 #include <inttypes.h>
455 #endif
456 #ifdef HAVE_STDINT_H
457 #include <stdint.h>
458 #endif
459 ],uint32_t, unsigned int)
460
461 dnl #############################################################
462 dnl #
463 dnl #  5. Checks for structures and functions
464 dnl #
465 dnl #############################################################
466 AC_CHECK_FUNCS( \
467         getopt_long \
468         lockf \
469         strsignal \
470         sigaction \
471         sigprocmask \
472         snprintf \
473         vsnprintf \
474         setsid \
475         strncasecmp \
476         strcasecmp \
477         strsep \
478         inet_aton \
479         gethostname \
480         setlinebuf \
481         setvbuf \
482         sem_init \
483         getusershell
484 )
485 RADIUSD_NEED_DECLARATIONS( \
486         crypt \
487         strncasecmp \
488         strcasecmp \
489         inet_aton \
490         gethostname \
491         setlinebuf \
492         getusershell \
493         endusershell
494 )
495
496 AC_TYPE_SIGNAL
497
498 dnl #############################################################
499 dnl #
500 dnl #  6. Checks for compiler characteristics
501 dnl #
502 dnl #############################################################
503
504 dnl #
505 dnl # Ensure that these are defined
506 dnl #
507 AC_C_CONST 
508
509 dnl #
510 dnl # See if this is OS/2
511 dnl #
512 AC_MSG_CHECKING(type of OS)
513 OS=`uname -s`
514 AC_MSG_RESULT($OS)
515 if test "$OS" = "OS/2"; then
516         LIBPREFIX=
517 else
518         LIBPREFIX=lib
519 fi
520 AC_SUBST(LIBPREFIX)
521
522 dnl #
523 dnl # Set Default CFLAGS
524 dnl #
525 if test "x$GCC" = "xyes"; then
526     CFLAGS="$CFLAGS -Wall -D_GNU_SOURCE"
527 fi
528
529 AC_MSG_CHECKING(for developer gcc flags)
530 if test "x$developer" = "xyes" -a "x$GCC" = "xyes"; then
531   devflags="-Wshadow -Wpointer-arith -Wcast-qual -Wcast-align -Wwrite-strings -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations -Wnested-externs"
532   CFLAGS="$CFLAGS $devflags"
533   INSTALLSTRIP=""
534   AC_MSG_RESULT(yes.  Using $devflags)
535 else
536   devflags="none"
537   CFLAGS="$CFLAGS -DNDEBUG"
538   INSTALLSTRIP="-s"
539   AC_MSG_RESULT(no.)
540 fi
541
542 dnl #############################################################
543 dnl #
544 dnl #  7. Checks for library functions
545 dnl #
546 dnl #############################################################
547
548 dnl Check for libcrypt
549 dnl We use crypt(3) which may be in libc, or in libcrypt (eg FreeBSD)
550 AC_CHECK_LIB(crypt, crypt,
551   CRYPTLIB="-lcrypt"
552 )
553 AC_SUBST(CRYPTLIB)
554 if test "$CRYPTLIB" != ""; then
555   AC_DEFINE(HAVE_CRYPT)
556 else
557   AC_CHECK_FUNC(crypt, AC_DEFINE(HAVE_CRYPT))
558 fi
559
560 if test "x$WITH_SNMP" = "xyes"; then
561   SNMP_CHECKS
562 fi
563
564 dnl #
565 dnl #  Check for sem_init all by itself
566 dnl #
567 if test "X$ac_cv_func_sem_init" = "Xno"; then
568
569 dnl #
570 dnl #  If not found, sem_init is in -lposix4 on Solaris
571 dnl #
572  AC_CHECK_LIB(posix4, sem_init)
573
574   if test "X$ac_cv_lib_posix4_sem_init" = "X"; then
575     if test "$WITH_THREAD_POOL" = "yes"; then
576       AC_MSG_WARN(You do not have posix semaphores.  Disabling thread pools)
577     fi
578     WITH_THREAD_POOL=no
579   fi
580 fi
581
582 POSTGRESQL_CHECKS
583 ODBC_CHECKS
584
585 dnl #############################################################
586 dnl #
587 dnl #  8. Checks for system services
588 dnl #
589 dnl #############################################################
590
591 dnl #
592 dnl # Figure out where libtool is located,
593 dnl #
594 LIBTOOL="`pwd`/libtool"
595 AC_SUBST(LIBTOOL)
596 AC_SUBST(LIBLTDL)
597 AC_SUBST(INCLTDL)
598 top_builddir=`pwd`
599 AC_SUBST(top_builddir)
600
601 dnl import libtool stuff
602
603 dnl #
604 dnl #  Checks to ensure that the thread pool code can build.
605 dnl #
606 if test "$WITH_THREAD_POOL" = "yes"; then
607   dnl #
608   dnl # If using thread pools, check that threading is enabled
609   dnl #
610   if test "$WITH_THREADS" != "yes"; then
611     AC_MSG_ERROR(You must have threads enabled for thread pools to work.)
612   fi
613
614   dnl #
615   dnl # If using thread pools, check that we have thread libraries
616   dnl #
617   if test "X$PTHREADLIB" = "X"; then
618     AC_MSG_ERROR(You must have threading libraries for thread pools to work.)
619   fi
620
621 dnl #
622 dnl #  Finally, after all of the checks above, we see if
623 dnl #  we can REALLY use the thread pools.
624 dnl #
625   if test "$WITH_THREAD_POOL" = "yes"; then
626     AC_DEFINE(WITH_THREAD_POOL,1)
627   fi
628 fi
629
630 dnl #############################################################
631 dnl #
632 dnl #  Configure in any module directories.
633 dnl #
634 dnl #############################################################
635
636 mysubdirs=
637 for foo in `find src/modules -name configure -print`; do
638   bar=`echo $foo | sed 's%/configure$%%g'`
639   mysubdirs="$mysubdirs $bar"
640 done
641
642 dnl #
643 dnl #  Don't change the variable name here.  Autoconf goes bonkers
644 dnl #  if you do.
645 dnl #
646 AC_CONFIG_SUBDIRS($mysubdirs)
647
648 dnl #############################################################
649 dnl #
650 dnl #  And finally, output the results.
651 dnl #
652 dnl #############################################################
653
654 dnl #
655 dnl #  Substitute whatever libraries we found to be necessary
656 dnl #
657 AC_SUBST(LIBS)
658 AC_SUBST(INSTALLSTRIP)
659
660 USE_SHARED_LIBS=$enable_shared
661 AC_SUBST(USE_SHARED_LIBS)
662 USE_STATIC_LIBS=$enable_static
663 AC_SUBST(USE_STATIC_LIBS)
664 AC_SUBST(STATIC_MODULES)
665 AC_SUBST(RADIUSD_VERSION)
666 export CFLAGS LIBS
667
668 AC_OUTPUT(\
669         ./Make.inc \
670         ./src/include/build-radpaths-h \
671         ./src/main/checkrad.pl \
672         ./src/main/radlast \
673         ./src/main/radtest \
674         ./scripts/rc.radiusd \
675         ./scripts/radwatch \
676         ./scripts/check-radiusd-config \
677         ./scripts/radiusd.cron.daily \
678         ./scripts/radiusd.cron.monthly \
679         ./raddb/radiusd.conf
680 )
681
682 AC_OUTPUT_COMMANDS([echo timestamp > src/include/stamp-h])
683 AC_OUTPUT_COMMANDS([(cd ./src/include && /bin/sh ./build-radpaths-h)])
684 AC_OUTPUT_COMMANDS([(cd ./src/main   && chmod +x checkrad.pl radlast radtest)])
685 AC_OUTPUT_COMMANDS([(cd ./scripts    && chmod +x rc.radiusd radwatch check-radiusd-config radiusd.cron.daily radiusd.cron.monthly)])
686 AC_OUTPUT_COMMANDS([
687 cat >> src/include/autoconf.h <<EOF
688
689 #define HOSTINFO        "$host"
690 #define RADIUSD_VERSION "$RADIUSD_VERSION"
691 EOF
692 ],host=$host)