Record whether the server was built with NDEBUG in features.h
[freeradius.git] / configure.ac
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_PREREQ([2.59])
24 export CFLAGS LIBS LDFLAGS CPPFLAGS
25
26 AC_INIT([freeradius],[$]Id[$],[http://bugs.freeradius.org],,[http://www.freeradius.org])
27 AC_CONFIG_SRCDIR([src/main/radiusd.c])
28 AC_CONFIG_HEADER([src/include/autoconf.h])
29 m4_include([m4/ax_cc.m4])
30
31 dnl #############################################################
32 dnl #
33 dnl #  Custom hackery to discover version at configure time
34 dnl #
35 dnl #############################################################
36
37 RADIUSD_MAJOR_VERSION=`cat VERSION | sed 's/\..*//'`
38 RADIUSD_MINOR_VERSION=`cat VERSION | sed 's/^[[^\.]]*\.//' | sed 's/\..*$//'`
39 RADIUSD_INCRM_VERSION=`cat VERSION | sed 's/^.*\..*\.//' | sed 's/[[\.-]].*$//'`
40
41 RADIUSD_VERSION=`echo | awk -v major="$RADIUSD_MAJOR_VERSION" \
42 -v minor="$RADIUSD_MINOR_VERSION" \
43 -v incrm="$RADIUSD_INCRM_VERSION" \
44 '{ printf "%02i%02i%02i", major, minor, incrm }'`
45
46 dnl #
47 dnl #  Still useful for custom builds
48 dnl #
49 RADIUSD_VERSION_STRING=`cat VERSION`
50
51 dnl #
52 dnl #  Add definitions to Make.inc as it's used by various build targets
53 dnl #
54 AC_SUBST([RADIUSD_VERSION_STRING])
55
56 dnl #
57 dnl #  Add definitions to autoconf.h, so that the headers that we install
58 dnl #  contain the version number of the server.
59 dnl #
60 AC_DEFINE_UNQUOTED([RADIUSD_VERSION], [${RADIUSD_VERSION}], [Version integer in format <ma><ma><mi><mi><in><in>])
61 AC_DEFINE_UNQUOTED([RADIUSD_VERSION_STRING], ["${RADIUSD_VERSION_STRING}"], [Raw version string from VERSION file])
62
63 dnl #############################################################
64 dnl #
65 dnl #  Override some of the default autoconf variables such as
66 dnl #  CFLAGS if were building in developer mode
67 dnl #
68 dnl #############################################################
69
70 dnl #
71 dnl #  Enable developer features like debugging symbols.
72 dnl #  These checks must be done before expanding the AC_PROG_CC
73 dnl #  and AC_PROG_CXX macros.
74 dnl #
75 AC_ARG_ENABLE(developer,
76 [  --enable-developer      enables features of interest to developers.],
77 [ case "$enableval" in
78   no)
79     developer=no
80     ;;
81   *)
82     developer=yes
83   esac ]
84 )
85
86 dnl #
87 dnl #  Turn on the developer flag when taken from a git checkout (not a release)
88 dnl #
89 if test -d $srcdir/.git; then
90   if test "x$developer" != "xno"; then
91     AC_MSG_NOTICE([found .git directory, enabling developer build implicitly, disable with --disable-developer])
92     developer="yes"
93   fi
94 fi
95
96 dnl #
97 dnl #  Autoconf sets -O2 and -g by default, but this is a PITA for debugging
98 dnl #  so we remove the defaults if were building in developer mode, and set
99 dnl #  -g3 so nice things like macro values are included. Other arguments are
100 dnl #  added later when we know what compiler were using.
101 dnl #
102 if test "x$developer" = "xyes"; then
103   : ${CFLAGS=-g3}
104 fi
105
106 dnl #############################################################
107 dnl #
108 dnl #  0. Checks for compiler, libtool, and command line options.
109 dnl #
110 dnl #############################################################
111
112 dnl #
113 dnl #  Get system information
114 dnl #
115 AC_CANONICAL_SYSTEM
116
117 dnl #
118 dnl #  Check for GNU cc
119 dnl #
120 AC_PROG_CC
121 AC_PROG_CXX
122
123 dnl #
124 dnl #  check for AIX, to allow us to use some BSD functions
125 dnl #  must be before macros that call the compiler.
126 dnl #
127 AC_AIX
128
129 AC_PROG_GCC_TRADITIONAL
130 AC_PROG_CC_SUNPRO
131 AC_PROG_RANLIB
132
133 dnl #
134 dnl #  Definitive check for whether the compiler is clang
135 dnl #
136 AX_CC_IS_CLANG
137
138 dnl #
139 dnl #  Set Default CFLAGS for GCC compatible compilers
140 dnl #
141 if test "x$GCC" = "xyes"; then
142   CFLAGS="$CFLAGS -Wall -D_GNU_SOURCE"
143 fi
144
145 dnl #
146 dnl #  -Qunused-arguments means the compiler won't complain about unsupported arguments
147 dnl #
148 AX_CC_QUNUSED_ARGUMENTS_FLAG
149 if test "x$ax_cv_cc_qunused_arguments_flag" = "xyes"; then
150   CFLAGS="$CFLAGS -Qunused-arguments"
151   LDFLAGS="$LDFLAGS -Qunused-arguments"
152 fi
153
154 dnl #
155 dnl #  Compile in large (2G+) file support.
156 dnl #
157 AC_SYS_LARGEFILE
158
159 dnl #
160 dnl #  check for system bytesex
161 dnl #  AC_DEFINES WORDS_BIGENDIAN
162 dnl #
163 AC_C_BIGENDIAN
164
165 dnl #
166 dnl #  Find GNU Make.
167 dnl #
168 AC_CHECK_PROG(GMAKE, gmake, yes, no)
169 if test $GMAKE = no; then
170   AC_PATH_PROG(MAKE, make, /usr/local/bin/make)
171 else
172   AC_PATH_PROG(MAKE, gmake, /usr/local/gnu/bin/make)
173 fi
174 makever=`$ac_cv_path_MAKE --version 2>&1 | grep "GNU Make"`
175 if test -z "$makever"; then
176   AC_MSG_ERROR([GNU Make is not installed.  Please download and install it from ftp://prep.ai.mit.edu/pub/gnu/make/ before continuing.])
177 fi
178
179 dnl #
180 dnl #  autoconf explicitly sets MAKEFLAGS and MFLAGS to '' even though we
181 dnl #  didn't tell it to, so we have to use FR_MAKEFLAGS.
182 dnl #
183 dnl #  determine the number of cores available and set the number of build
184 dnl #  processes appropriately.
185 dnl #
186 AX_SYSTEM_CORES
187
188 dnl #  Temporarily disabled because test and installation targets do not
189 dnl #  have dependencies set up correctly for multiple build processes.
190 dnl if test "x$ax_cv_system_cores" != "x"; then
191 dnl  : ${FR_MAKEFLAGS=-j$ax_cv_system_cores}
192 dnl fi
193 AC_SUBST(FR_MAKEFLAGS)
194
195 dnl #
196 dnl #  See if we have Git.
197 dnl #
198 AC_CHECK_PROG(GIT, git, yes, no)
199
200 dnl Put this in later, when all distributed modules use autoconf.
201 dnl AC_ARG_WITH(disablemodulefoo,
202 dnl [  --without-rlm_foo         Disables module compilation.  Module list:]
203 dnl esyscmd([find src/modules -type d -name rlm_\* -print |\
204 dnl   sed -e 's%src/modules/.*/% (sub)- %; s%.*/%- %' |\
205 dnl   awk '{print "                            "$0}']))
206
207 AC_ARG_ENABLE(strict-dependencies,
208 [  --enable-strict-dependencies  fail configure on lack of module dependancy.])
209
210 AC_ARG_ENABLE(werror,
211 [  --enable-werror         causes the build to fail if any warnings are generated.],
212 [ case "$enableval" in
213     no)
214       werror=no
215     ;;
216     *)
217       werror=yes
218   esac ]
219 )
220
221 dnl #
222 dnl #  extra argument: --with-docdir
223 dnl #
224 docdir='${datadir}/doc/freeradius'
225 AC_MSG_CHECKING([docdir])
226 AC_ARG_WITH(docdir,
227 [  --with-docdir=DIR       directory for documentation [DATADIR/doc/freeradius] ],
228 [ case "$withval" in
229   no)
230     docdir=no
231     ;;
232   yes)
233     ;;
234   [[\\/$]]* | ?:[[\\/]]* )
235     docdir="$withval"
236     ;;
237   *)
238     AC_MSG_ERROR([expected an absolute directory name for --with-docdir: $withval])
239     ;;
240   esac ]
241 )
242 AC_SUBST(docdir)
243 AC_MSG_RESULT($docdir)
244 if test "x$docdir" = xno; then
245   AC_MSG_WARN([Documentation files will NOT be installed.])
246 fi
247
248 dnl #
249 dnl #  extra argument: --with-logdir
250 dnl #
251 logdir='${localstatedir}/log/radius'
252 AC_MSG_CHECKING(logdir)
253 AC_ARG_WITH(logdir,
254 [  --with-logdir=DIR       directory for logfiles [LOCALSTATEDIR/log/radius] ],
255 [ case "$withval" in
256   no)
257     AC_MSG_ERROR([Need logdir])
258     ;;
259   yes)
260     ;;
261   [[\\/$]]* | ?:[[\\/]]* )
262     logdir="$withval"
263     ;;
264   *)
265     AC_MSG_ERROR([expected an absolute directory name for --with-logdir: $withval])
266     ;;
267   esac ]
268 )
269 AC_SUBST(logdir)
270 AC_MSG_RESULT($logdir)
271
272 dnl #
273 dnl #  extra argument: --with-radacctdir
274 dnl #
275 radacctdir='${logdir}/radacct'
276 AC_MSG_CHECKING(radacctdir)
277 AC_ARG_WITH(radacctdir,
278 [  --with-radacctdir=DIR   directory for detail files [LOGDIR/radacct] ],
279 [ case "$withval" in
280   no)
281     AC_MSG_ERROR([Need radacctdir])
282     ;;
283   yes)
284     ;;
285   [[\\/$]]* | ?:[[\\/]]* )
286     radacctdir="$withval"
287     ;;
288   *)
289     AC_MSG_ERROR([expected an absolute directory name for --with-radacctdir: $withval])
290     ;;
291   esac ]
292 )
293 AC_SUBST(radacctdir)
294 AC_MSG_RESULT($radacctdir)
295
296 dnl #
297 dnl #  extra argument: --with-raddbdir
298 dnl #
299 raddbdir='${sysconfdir}/raddb'
300 AC_MSG_CHECKING(raddbdir)
301 AC_ARG_WITH(raddbdir,
302 [  --with-raddbdir=DIR     directory for config files [SYSCONFDIR/raddb] ],
303 [ case "$withval" in
304   no)
305     AC_MSG_ERROR([Need raddbdir])
306     ;;
307   yes)
308     ;;
309   [[\\/$]]* | ?:[[\\/]]* )
310     raddbdir="$withval"
311     ;;
312   *)
313     AC_MSG_ERROR([expected an absolute directory name for --with-raddbdir: $withval])
314     ;;
315   esac ]
316 )
317 AC_SUBST(raddbdir)
318 AC_MSG_RESULT($raddbdir)
319
320 modconfdir="$raddbdir/mods-config"
321 AC_SUBST(modconfdir)
322
323 dnl #
324 dnl #  extra argument: --with-ascend-binary
325 dnl #
326 WITH_ASCEND_BINARY=yes
327 AC_ARG_WITH(ascend-binary,
328 [  --with-ascend-binary    include support for Ascend binary filter attributes (default=yes)],
329 [ case "$withval" in
330   yes)
331     ;;
332   *)
333     WITH_ASCEND_BINARY=no
334   esac ]
335 )
336 if test "x$WITH_ASCEND_BINARY" = "xyes"; then
337   AC_DEFINE(WITH_ASCEND_BINARY, [1], [include support for Ascend binary filter attributes])
338 fi
339
340 dnl #
341 dnl #  extra argument: --with-threads
342 dnl #
343 WITH_THREADS=yes
344 AC_ARG_WITH(threads,
345 [  --with-threads          Use threads, if available.  (default=yes) ],
346 [ case "$withval" in
347   yes)
348     ;;
349   *)
350     WITH_THREADS=no
351   esac ]
352 )
353
354 dnl #
355 dnl #  extra argument: --with-tcp
356 dnl #
357 WITH_TCP=yes
358 AC_ARG_WITH(tcp,
359 [  --with-tcp              Compile in TCP support. (default=yes)],
360 [ case "$withval" in
361   yes)
362     ;;
363   *)
364     WITH_TCP=no
365   esac ]
366 )
367 if test "x$WITH_TCP" = "xyes"; then
368   AC_DEFINE(WITH_TCP, [1], [define if you want TCP support (For RADSec et al)])
369 fi
370
371 dnl #
372 dnl #  extra argument: --with-vmps
373 dnl #
374 WITH_VMPS=yes
375 AC_ARG_WITH(vmps,
376 [  --with-vmps             Compile in VMPS support. (default=yes)],
377 [ case "$withval" in
378   yes)
379     ;;
380   *)
381     WITH_VMPS=no
382   esac ]
383 )
384 if test "x$WITH_VMPS" = "xyes"; then
385   AC_DEFINE(WITH_VMPS, [1], [define if you want VMPS support])
386 fi
387
388 dnl #
389 dnl #  extra argument: --with-dhcp
390 dnl #
391 WITH_DHCP=yes
392 AC_ARG_WITH(dhcp,
393 [  --with-dhcp             Compile in DHCP support. (default=yes)],
394 [ case "$withval" in
395   yes)
396     ;;
397   *)
398     WITH_DHCP=no
399   esac ]
400 )
401 if test "x$WITH_DHCP" = "xyes"; then
402   AC_DEFINE(WITH_DHCP, [1], [define if you want DHCP support])
403 fi
404
405 dnl #
406 dnl #  Allow the user to specify a list of modules to be linked
407 dnl #  statically to the server.
408 dnl #
409 STATIC_MODULES=
410 AC_ARG_WITH(static_modules,
411 [  --with-static-modules=QUOTED-MODULE-LIST],[
412   for i in $withval; do
413     STATIC_MODULES="$STATIC_MODULES -dlpreopen ../modules/rlm_$i/rlm_$i.la"
414   done
415 ])
416
417 USE_SHARED_LIBS=yes
418 AC_ARG_WITH(static,
419 [  --with-shared-libs             Build dynamic libraries and link against them. (default=yes)],
420 [ case "$withval" in
421   no)
422     USE_SHARED_LIBS=no
423     ;;
424   *)
425   esac
426 ])
427
428 MODULES=
429 AC_ARG_WITH(modules,
430 [  --with-modules=QUOTED-MODULE-LIST],[
431  for i in $withval; do
432    MODULES="$MODULES $i"
433  done
434 ])
435
436 dnl #
437 dnl #  extra argument: --with-experimental-modules
438 dnl #
439 EXPERIMENTAL=
440 AC_ARG_WITH(experimental-modules,
441 [  --with-experimental-modules      Use experimental and unstable modules. (default=no, unless --enable-developer=yes) ],
442 [ case "$withval" in
443   yes)
444     EXPERIMENTAL=yes
445     ;;
446   no)
447     EXPERIMENTAL=no
448     ;;
449   *)
450   esac ]
451 )
452
453 dnl #
454 dnl #  extra argument: --with-openssl
455 dnl #
456 WITH_OPENSSL=yes
457 AC_ARG_WITH(openssl,
458 [  --with-openssl                   Use OpenSSL. (default=yes)],
459 [ case "$withval" in
460   no)
461     WITH_OPENSSL=no
462     ;;
463   *)
464     WITH_OPENSSL=yes
465     ;;
466   esac ]
467 )
468
469 dnl #
470 dnl #  extra argument: --with-openssl-includes=dir
471 dnl #
472 OPENSSL_INCLUDE_DIR=
473 AC_ARG_WITH(openssl-includes,
474 [  --with-openssl-includes=DIR      Directory to look for OpenSSL include files],
475 [ case "$withval" in
476   *) OPENSSL_INCLUDE_DIR="$withval"
477     ;;
478   esac ]
479 )
480
481 dnl #
482 dnl #  extra argument: --with-openssl-libraries=dir
483 dnl #
484 OPENSSL_LIB_DIR=
485 AC_ARG_WITH(openssl-libraries,
486 [  --with-openssl-libraries=DIR     Directory to look for OpenSSL library files],
487 [ case "$withval" in
488   *) OPENSSL_LIB_DIR="$withval"
489     ;;
490   esac ]
491 )
492
493 dnl #
494 dnl #  These next two arguments don't actually do anything.  They're
495 dnl #  place holders so that the top-level configure script can tell
496 dnl #  the user how to configure lower-level modules
497 dnl #
498
499 dnl #
500 dnl #  extra argument: --with-rlm-FOO-lib-dir
501 dnl #
502 AC_ARG_WITH(rlm-FOO-lib-dir,
503 [  --with-rlm-FOO-lib-dir=DIR       Directory to look for library files used by module FOO],
504 [ case "$withval" in
505   *)
506     ;;
507   esac ]
508 )
509
510 dnl #
511 dnl #  extra argument: --with-rlm-FOO-include-dir
512 dnl #
513 AC_ARG_WITH(rlm-FOO-include-dir,
514 [  --with-rlm-FOO-include-dir=DIR   Directory to look for include files used by module FOO],
515 [ case "$withval" in
516   *)
517     ;;
518   esac ]
519 )
520
521 dnl #
522 dnl #  extra argument: --with-udpfromto
523 dnl #
524 WITH_UDPFROMTO=no
525 AC_ARG_WITH(udpfromto,
526 [  --with-udpfromto        Compile in UDPFROMTO support. (default=no)],
527 [ case "$withval" in
528   yes)
529     WITH_UDPFROMTO=yes
530     ;;
531   *)
532     WITH_UDPFROMTO=no
533   esac ]
534 )
535
536 if test "x$WITH_UDPFROMTO" = "xyes"; then
537   AC_DEFINE(WITH_UDPFROMTO, [], [define if you want udpfromto])
538 fi
539
540 dnl #############################################################
541 dnl #
542 dnl #  1. Checks for programs
543 dnl #
544 dnl #############################################################
545
546 CHECKRAD=checkrad
547 AC_PATH_PROG(PERL, perl, /usr/local/bin/perl)
548 if test "x$ac_cv_path_PERL" = "x"; then
549   AC_MSG_WARN([perl not found - Simultaneous-Use and checkrad may not work])
550 fi
551 AC_PATH_PROG(SNMPGET, snmpget)
552 if test "x$ac_cv_path_SNMPGET" = "x"; then
553   AC_MSG_WARN([snmpget not found - Simultaneous-Use and checkrad may not work])
554 fi
555
556 AC_PATH_PROG(SNMPWALK, snmpwalk)
557 if test "x$ac_cv_path_SNMPWALK" = "x"; then
558   AC_MSG_WARN([snmpwalk not found - Simultaneous-Use and checkrad may not work])
559 fi
560
561 AC_PATH_PROG(RUSERS, rusers, /usr/bin/rusers)
562
563 dnl #
564 dnl #  FIXME This is truly gross.
565 dnl #
566 missing_dir=`cd $ac_aux_dir && pwd`
567 AM_MISSING_PROG(ACLOCAL, aclocal, $missing_dir)
568 AM_MISSING_PROG(AUTOCONF, autoconf, $missing_dir)
569 AM_MISSING_PROG(AUTOHEADER, autoheader, $missing_dir)
570
571 AC_PATH_PROG(LOCATE,locate)
572 AC_PATH_PROG(DIRNAME,dirname)
573 AC_PATH_PROG(GREP,grep)
574
575 dnl #############################################################
576 dnl #
577 dnl #  2. Checks for libraries
578 dnl #
579 dnl #############################################################
580
581 dnl #
582 dnl #  If using pthreads, check for -lpthread (posix) or -lc_r (*BSD)
583 dnl #
584 old_CFLAGS=$CFLAGS
585 if test "x$WITH_THREADS" = "xyes"; then
586   if test $ac_cv_prog_suncc = "yes"; then
587     CFLAGS="$CFLAGS -mt"
588   fi
589
590   AC_CHECK_HEADERS(pthread.h, [], [ WITH_THREADS="no" ])
591
592   dnl #
593   dnl #  pthread stuff is usually in -lpthread
594   dnl #  or in -lc_r, on *BSD
595   dnl #
596   dnl #  On Some systems, we need extra pre-processor flags, to get them to
597   dnl #  to do the threading properly.
598   dnl #
599   AC_CHECK_LIB(pthread, pthread_create,
600     [
601       CFLAGS="$CFLAGS -D_REENTRANT -D_POSIX_PTHREAD_SEMANTICS"
602       LIBS="-lpthread $LIBS"
603     ],
604     [
605       AC_CHECK_LIB(c_r, pthread_create,
606         [ CFLAGS="$CFLAGS -pthread -D_THREAD_SAFE" ],
607         [ WITH_THREADS="no" ]
608       )
609     ]
610   )
611 fi
612
613 dnl #
614 dnl #  If we have NO pthread libraries, remove any knowledge of threads.
615 dnl #
616 if test "x$WITH_THREADS" != "xyes"; then
617   CFLAGS=$old_CFLAGS
618   ac_cv_header_pthread_h="no"
619   WITH_THREADS=no
620 else
621   dnl #
622   dnl #  We need sem_init() and friends, as they're the friendliest
623   dnl #  semaphore functions for threading.
624   dnl #
625   dnl #  HP/UX requires linking with librt, too, to get the sem_* symbols.
626   dnl #  Some systems have them in -lsem
627   dnl #  Solaris has them in -lposix4
628   dnl #  NetBSD has them in -lsemaphore
629   dnl #
630
631   AC_SEARCH_LIBS(sem_init, pthread sem posix4 rt semaphore,
632     [],
633     [AC_MSG_ERROR([[-lsem not found.  You may want to download it from ftp://ftp.to.gd-es.com/pub/BSDI/libsem.tar.bz2 or ftp://ftp.freeradius.org/pub/radius/contrib/libsem.tar.gz]])]
634   )
635 fi
636
637 if test "x$WITH_THREADS" = "xyes"; then
638   AC_DEFINE(WITH_THREADS, [1], [define if you want thread support])
639 fi
640
641 dnl #
642 dnl #  Check if we need -lsocket
643 dnl #
644 AC_CHECK_LIB(dl, dlopen)
645
646 dnl #
647 dnl #  Check if we need -lsocket
648 dnl #
649 AC_CHECK_LIB(socket, getsockname)
650
651 dnl #
652 dnl #  Check for -lresolv
653 dnl #  This library may be needed later.
654 dnl #
655 AC_CHECK_LIB(resolv, inet_aton)
656
657 dnl #
658 dnl #  Check if we need -lnsl. Usually if we want to
659 dnl #  link against -lsocket we need to include -lnsl as well.
660 dnl #
661 AC_CHECK_LIB(nsl, inet_ntoa)
662 AC_CHECK_LIB(ws2_32, htonl)
663
664 dnl #
665 dnl #  Check the pcap library for the RADIUS sniffer.
666 dnl #
667 PCAP_LIBS=
668 AC_CHECK_LIB(pcap, pcap_open_live,
669   [
670     PCAP_LIBS="-lpcap"
671     AC_DEFINE(HAVE_LIBPCAP, 1,
672       [Define to 1 if you have the `pcap' library (-lpcap).]
673     )
674   ],
675   [
676     AC_MSG_WARN([pcap library not found, silently disabling the RADIUS sniffer.])
677   ]
678 )
679
680 VL_LIB_READLINE
681
682 dnl #############################################################
683 dnl #
684 dnl #  3. Checks for header files
685 dnl #
686 dnl #############################################################
687
688 dnl #
689 dnl #  Interix requires us to set -D_ALL_SOURCE, otherwise
690 dnl #  getopt will be #included, but won't link.  <sigh>
691 dnl #
692 dnl #
693 case "$host" in
694   *-interix*)
695     CFLAGS="$CFLAGS -D_ALL_SOURCE"
696     ;;
697   *-darwin*)
698     CFLAGS="$CFLAGS -DDARWIN"
699     LIBS="-framework DirectoryService $LIBS"
700     ;;
701 esac
702
703 AC_HEADER_DIRENT
704 AC_HEADER_STDC
705 AC_HEADER_TIME
706 AC_HEADER_SYS_WAIT
707
708 AC_CHECK_HEADERS( \
709   dlfcn.h \
710   unistd.h \
711   crypt.h \
712   errno.h \
713   resource.h \
714   sys/resource.h \
715   getopt.h \
716   malloc.h \
717   utmp.h \
718   utmpx.h \
719   signal.h \
720   sys/select.h \
721   syslog.h \
722   inttypes.h \
723   stdint.h \
724   stdio.h \
725   netdb.h \
726   semaphore.h \
727   arpa/inet.h \
728   netinet/in.h \
729   sys/types.h \
730   sys/socket.h \
731   winsock.h \
732   utime.h \
733   sys/time.h \
734   sys/wait.h \
735   sys/security.h \
736   fcntl.h \
737   sys/fcntl.h \
738   sys/prctl.h \
739   sys/un.h \
740   glob.h \
741   prot.h \
742   pwd.h \
743   grp.h \
744   stddef.h \
745   fnmatch.h \
746   sia.h \
747   siad.h
748 )
749
750 dnl #
751 dnl #  FreeBSD requires sys/socket.h before net/if.h
752 dnl #
753 AC_CHECK_HEADERS(net/if.h, [], [],
754 [#ifdef HAVE_SYS_SOCKET_H
755 #  include <sys/socket.h>
756 #  endif
757 ])
758
759 dnl #
760 dnl #  other checks which require headers
761 dnl #
762 if test "x$ac_cv_header_sys_security_h" = "xyes" && test "x$ac_cv_header_prot_h" = "xyes"
763 then
764   AC_DEFINE(OSFC2, [], [define if you have OSFC2 authentication])
765 fi
766
767 if test "x$ac_cv_header_sia_h" = "xyes" && test "x$ac_cv_header_siad_h" = "xyes"
768 then
769   AC_DEFINE(OSFSIA, [], [define if you have OSFSIA authentication])
770 fi
771
772 dnl #
773 dnl #  Were we told to use OpenSSL, if we were and we find an error, call AC_MSG_FAILURE and exit
774 dnl #
775 if test "x$WITH_OPENSSL" = xyes; then
776   old_LIBS=$LIBS
777   old_LDFLAGS="$LDFLAGS"
778
779   OPENSSL_INCLUDE="-DNO_OPENSSL"
780   OPENSSL_LIBS=
781   if test "x$OPENSSL_LIB_DIR" != "x"; then
782     LDFLAGS="$LDFLAGS -L$OPENSSL_LIB_DIR"
783   fi
784
785   dnl #
786   dnl #  Check we can link to libssl
787   dnl #
788   AC_CHECK_LIB(crypto, DH_new,
789     [
790       LIBS="-lcrypto $LIBS"
791       AC_DEFINE(HAVE_LIBCRYPTO, 1, [Define to 1 if you have the `crypto' library (-lcrypto).])
792       AC_CHECK_LIB(ssl, SSL_new,
793         [
794           AC_DEFINE(HAVE_LIBSSL, 1, [Define to 1 if you have the `ssl' library (-lssl).])
795           if test "x$OPENSSL_LIB_DIR" != "x"; then
796             OPENSSL_LIBS="-L$OPENSSL_LIB_DIR"
797           fi
798           OPENSSL_LIBS="$OPENSSL_LIBS -lcrypto -lssl -lcrypto"
799         ],
800         [
801           AC_MSG_FAILURE([failed linking to libssl])
802         ]
803       )
804     ],
805     []
806   )
807
808   dnl #
809   dnl #  Check we can find required headers
810   dnl #
811   old_CPPFLAGS=$CPPFLAGS
812   if test "x$OPENSSL_INCLUDE_DIR" != "x"; then
813     CPPFLAGS="$CPPFLAGS -I$OPENSSL_INCLUDE_DIR"
814   fi
815
816   dnl #
817   dnl #  Stupid RedHat shit
818   dnl #
819   CPPFLAGS="$CPPFLAGS -DOPENSSL_NO_KRB5"
820   AC_CHECK_HEADERS( \
821     openssl/ssl.h \
822     openssl/crypto.h \
823     openssl/err.h \
824     openssl/evp.h \
825     openssl/md5.h \
826     openssl/md4.h \
827     openssl/sha.h \
828     openssl/ocsp.h \
829     openssl/engine.h,
830     [],
831     [
832       AC_MSG_FAILURE([failed locating OpenSSL headers])
833     ]
834   )
835
836   AC_MSG_CHECKING([for OpenSSL version >= 0.9.7])
837   AC_EGREP_CPP(yes,
838     [#include <openssl/crypto.h>
839      #if (OPENSSL_VERSION_NUMBER >= 0x00907000L)
840      yes
841      #endif
842     ],
843     [
844       AC_MSG_RESULT(yes)
845     ],
846     [
847       AC_MSG_RESULT(no)
848       AC_MSG_FAILURE([OpenSSL version too old])
849     ]
850   )
851
852   if test "x$OPENSSL_INCLUDE_DIR" != "x"; then
853     OPENSSL_INCLUDE="-I$OPENSSL_INCLUDE_DIR -DOPENSSL_NO_KRB5"
854   else
855     OPENSSL_INCLUDE="-DOPENSSL_NO_KRB5"
856   fi
857
858   dnl #
859   dnl #  Now check that the header versions match the library
860   dnl #
861   AC_MSG_CHECKING([OpenSSL library and header version consistency])
862   AC_RUN_IFELSE(
863     [AC_LANG_PROGRAM(
864       [[
865         #include <stdio.h>
866         #include <openssl/opensslv.h>
867         #include <openssl/crypto.h>
868       ]],
869       [[
870         if (SSLeay() == OPENSSL_VERSION_NUMBER) {
871           return 0;
872         } else {
873           printf("library: %lx header: %lx... ", (unsigned long) SSLeay(), (unsigned long) OPENSSL_VERSION_NUMBER);
874           return 1;
875         }
876       ]]
877     )],
878     [
879       AC_MSG_RESULT(yes)
880     ],
881     [
882       AC_MSG_RESULT(no)
883       AC_MSG_FAILURE([OpenSSL library version does not match header version])
884     ]
885   )
886
887   CPPFLAGS=$old_CPPFLAGS
888   LIBS=$old_LIBS
889   LDFLAGS="$old_LDFLAGS"
890 fi
891
892 AC_SUBST(OPENSSL_INCLUDE)
893 AC_SUBST(OPENSSL_LIBS)
894 export OPENSSL_LIBS
895
896 dnl #
897 dnl #  Check the pcap includes for the RADIUS sniffer.
898 dnl #
899 if test "x$PCAP_LIBS" = x; then
900   AC_MSG_NOTICE([skipping test for pcap.h.])
901 else
902   AC_CHECK_HEADER(pcap.h,
903     [
904       AC_DEFINE(HAVE_PCAP_H, 1, [Define to 1 if you have the <pcap.h> header file.])
905
906       AC_CHECK_LIB(pcap, pcap_fopen_offline,
907         [
908           AC_DEFINE(HAVE_PCAP_FOPEN_OFFLINE, 1, [Define to 1 if you have the function pcap_fopen_offline.])
909         ]
910       )
911
912       AC_CHECK_LIB(pcap, pcap_dump_fopen,
913         [
914           AC_DEFINE(HAVE_PCAP_DUMP_FOPEN, 1, [Define to 1 if you have the function pcap_dump_fopen.])
915         ]
916       )
917     ],
918     [
919       PCAP_LIBS=
920       AC_MSG_WARN([pcap.h not found, silently disabling the RADIUS sniffer.])
921     ]
922   )
923 fi
924 AC_SUBST(PCAP_LIBS)
925
926 dnl #############################################################
927 dnl #
928 dnl #  4. Checks for typedefs
929 dnl #
930 dnl #############################################################
931
932 dnl #
933 dnl #  Ensure that these are defined
934 dnl #
935 AC_TYPE_OFF_T
936 AC_TYPE_PID_T
937 AC_TYPE_SIZE_T
938 AC_TYPE_UID_T
939
940 dnl #
941 dnl #  Check for socklen_t
942 dnl #
943 FR_CHECK_TYPE_INCLUDE(
944   [
945     #ifdef HAVE_SYS_TYPES_H
946     #  include <sys/types.h>
947     #endif
948
949     #ifdef HAVE_SYS_SOCKET_H
950     #  include <sys/socket.h>
951     #endif
952   ],
953   socklen_t, int, [socklen_t is generally 'int' on systems which don't use it]
954 )
955
956 dnl #
957 dnl #  Check for uint8_t
958 dnl #
959 FR_CHECK_TYPE_INCLUDE(
960   [
961     #ifdef HAVE_INTTYPES_H
962     #  include <inttypes.h>
963     #endif
964
965     #ifdef HAVE_STDINT_H
966     #  include <stdint.h>
967     #endif
968   ],
969   uint8_t, unsigned char, [uint8_t should be the canonical 'octet' for network traffic]
970 )
971
972 dnl #
973 dnl #  Check for uint16_t
974 dnl #
975 FR_CHECK_TYPE_INCLUDE(
976   [
977     #ifdef HAVE_INTTYPES_H
978     #  include <inttypes.h>
979     #endif
980
981     #ifdef HAVE_STDINT_H
982     #  include <stdint.h>
983     #endif
984   ],
985   uint16_t, unsigned short, [uint16_t should be the canonical '2 octets' for network traffic]
986 )
987
988 dnl #
989 dnl #  Check for uint32_t
990 dnl #
991 FR_CHECK_TYPE_INCLUDE(
992   [
993     #ifdef HAVE_INTTYPES_H
994     #  include <inttypes.h>
995     #endif
996
997     #ifdef HAVE_STDINT_H
998     #  include <stdint.h>
999     #endif
1000   ],
1001   uint32_t, unsigned int, [uint32_t should be the canonical 'network integer']
1002 )
1003
1004 AC_CHECK_TYPE(struct in6_addr, AC_DEFINE(HAVE_STRUCT_IN6_ADDR, 1, [IPv6 address structure]), [],
1005   [
1006     #ifdef HAVE_NETINET_IN_H
1007     #  include <netinet/in.h>
1008     #endif
1009   ]
1010 )
1011
1012 AC_CHECK_TYPE(struct sockaddr_storage, AC_DEFINE(HAVE_STRUCT_SOCKADDR_STORAGE, 1, [Generic socket addresses]), [],
1013   [
1014     #ifdef HAVE_NETINET_IN_H
1015     #  include <netinet/in.h>
1016     #endif
1017
1018     #ifdef HAVE_SYS_SOCKET_H
1019     #  include <sys/socket.h>
1020     #endif
1021 ])
1022
1023 AC_CHECK_TYPE(struct sockaddr_in6, AC_DEFINE(HAVE_STRUCT_SOCKADDR_IN6, 1, [IPv6 socket addresses]), [],
1024   [
1025     #ifdef HAVE_NETINET_IN_H
1026     #  include <netinet/in.h>
1027     #endif
1028 ])
1029
1030 AC_CHECK_TYPE(struct addrinfo, AC_DEFINE(HAVE_STRUCT_ADDRINFO, 1, [Generic DNS lookups]), [],
1031   [
1032     #ifdef HAVE_SYS_TYPES_H
1033     #  include <sys/types.h>
1034     #endif
1035
1036     #ifdef HAVE_SYS_SOCKET_H
1037     #  include <sys/socket.h>
1038     #endif
1039
1040     #ifdef HAVE_NETDB_H
1041     #  include <netdb.h>
1042     #endif
1043   ]
1044 )
1045
1046 dnl #############################################################
1047 dnl #
1048 dnl #  5. Checks for structures and functions
1049 dnl #
1050 dnl #############################################################
1051 AC_CHECK_FUNCS( \
1052   getopt_long \
1053   fcntl \
1054   strsignal \
1055   sigaction \
1056   sigprocmask \
1057   pthread_sigmask \
1058   snprintf \
1059   vsnprintf \
1060   setsid \
1061   strncasecmp \
1062   strcasecmp \
1063   localtime_r \
1064   ctime_r \
1065   gmtime_r \
1066   strsep \
1067   inet_aton \
1068   inet_pton \
1069   inet_ntop \
1070   setlinebuf \
1071   setvbuf \
1072   getusershell \
1073   initgroups \
1074   getaddrinfo \
1075   getnameinfo \
1076   closefrom \
1077   gettimeofday \
1078   getpeereid \
1079   setuid \
1080   setresuid \
1081   getresuid \
1082   strlcat \
1083   strlcpy
1084 )
1085
1086 AC_TYPE_SIGNAL
1087
1088 dnl #
1089 dnl #  Check if we have utmpx.h
1090 dnl #  if so, check if struct utmpx has entry ut_xtime
1091 dnl #  if not, set it to define ut_xtime == ut_tv.tv_sec
1092 dnl #
1093 if test "x$ac_cv_header_utmpx_h" = "xyes"; then
1094  FR_CHECK_STRUCT_HAS_MEMBER([#include <utmpx.h>], [struct utmpx], ut_xtime)
1095  if test "x$ac_cv_type_struct_utmpx_has_ut_xtime" = "x"; then
1096    AC_DEFINE(ut_xtime, ut_tv.tv_sec, [define to something if you don't have ut_xtime in struct utmpx])
1097  fi
1098 fi
1099
1100 dnl #
1101 dnl #  struct ip_pktinfo
1102 dnl #
1103 FR_CHECK_STRUCT_HAS_MEMBER([#include <netinet/in.h>], [struct in_pktinfo], ipi_addr)
1104 if test "x$ac_cv_type_struct_in_pktinfo_has_ipi_addr" = "xyes"; then
1105   AC_DEFINE(HAVE_IP_PKTINFO, [], [define if you have IP_PKTINFO (Linux)])
1106 fi
1107
1108 dnl #
1109 dnl #  struct in6_pktinfo
1110 dnl #
1111 FR_CHECK_STRUCT_HAS_MEMBER([#include <netinet/in.h>], [struct in6_pktinfo], ipi6_addr)
1112 if test "x$ac_cv_type_struct_in6_pktinfo_has_ipi6_addr" = "xyes"; then
1113   AC_DEFINE(HAVE_IN6_PKTINFO, [], [define if you have IN6_PKTINFO (Linux)])
1114 fi
1115
1116 dnl #############################################################
1117 dnl #
1118 dnl #  6. Checks for compiler characteristics
1119 dnl #
1120 dnl #############################################################
1121
1122 dnl #
1123 dnl #  Ensure that these are defined
1124 dnl #
1125 AC_C_CONST
1126
1127 dnl #
1128 dnl #  See if this is OS/2
1129 dnl #
1130 AC_MSG_CHECKING([type of OS])
1131 OS=`uname -s`
1132 AC_MSG_RESULT($OS)
1133 if test "$OS" = "OS/2"; then
1134   LIBPREFIX=
1135 else
1136   LIBPREFIX=lib
1137 fi
1138 AC_SUBST(LIBPREFIX)
1139
1140 if test "x$developer" = "xyes"; then
1141   AC_MSG_NOTICE([Setting additional developer CFLAGS])
1142
1143   dnl #
1144   dnl #  Tell the compiler to parse doxygen documentation and verify it against function and variable declarations
1145   dnl #
1146   AX_CC_WDOCUMENTATION_FLAG
1147   if test "x$ax_cv_cc_wdocumentation_flag" = "xyes"; then
1148     devflags="-Wdocumentation"
1149   fi
1150
1151   if test "x$GCC" = "xyes"; then
1152     devflags="$devflags -Wshadow -Wpointer-arith -Wcast-qual -Wcast-align -Wwrite-strings -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations -Wnested-externs -W -Wredundant-decls -Wundef -Wformat-y2k -Wno-format-extra-args -Wno-format-zero-length -Wno-cast-align -Wformat-nonliteral -Wformat-security -Wformat=2 -DWITH_VERIFY_PTR=1"
1153     INSTALLSTRIP=""
1154   fi
1155
1156   AC_MSG_NOTICE([Developer CFLAGS are "$devflags"])
1157
1158   CFLAGS="$CFLAGS $devflags"
1159   dnl #
1160   dnl #  Enable experimental modules (we want to know if code changes breaks one of them)
1161   dnl #
1162   if test "x$EXPERIMENTAL" != "xno"; then
1163     AC_MSG_NOTICE([is developer build, enabling experimental modules implicitly, disable with --without-experimental-modules])
1164     EXPERIMENTAL=yes
1165   fi
1166 else
1167   devflags=""
1168   CFLAGS="$CFLAGS -DNDEBUG"
1169   INSTALLSTRIP=""
1170 fi
1171
1172 dnl #
1173 dnl #  May of been set outside of this configure script
1174 dnl #
1175 AC_MSG_CHECKING([if building with -DNDEBUG])
1176 if echo "$CFLAGS" | grep '\-DNDEBUG' > /dev/null; then
1177   AC_MSG_RESULT([yes])
1178   AC_DEFINE([WITH_NDEBUG], [1], [define if the server was built with -DNDEBUG])
1179 else
1180   AC_MSG_RESULT([no])
1181 fi
1182
1183 export EXPERIMENTAL
1184
1185 dnl #
1186 dnl #  append the current git hash onto the version string
1187 dnl #
1188 if test -d $srcdir/.git -a "x$GIT" = "xyes"; then
1189   RADIUSD_VERSION_COMMIT=`git log --pretty=format:'%h' -n 1`
1190   AC_DEFINE_UNQUOTED([RADIUSD_VERSION_COMMIT],["${RADIUSD_VERSION_COMMIT}"],[Commit HEAD at time of configuring])
1191 fi
1192
1193 FR_TLS
1194
1195 dnl #############################################################
1196 dnl #
1197 dnl #  7. Checks for library functions
1198 dnl #
1199 dnl #############################################################
1200
1201 dnl Check for talloc
1202 dnl extra argument: --with-talloc-include-dir=DIR
1203 talloc_include_dir=
1204 AC_ARG_WITH(talloc-include-dir,
1205   [AS_HELP_STRING([--with-talloc-include-dir=DIR],
1206   [Directory where the talloc includes may be found])],
1207   [case "$withval" in
1208     no)
1209       AC_MSG_ERROR([Need talloc-include-dir])
1210       ;;
1211     yes)
1212       ;;
1213     *)
1214       talloc_include_dir="$withval"
1215       ;;
1216   esac])
1217
1218 dnl Check for talloc
1219 dnl extra argument: --with-talloc-lib-dir=DIR
1220 talloc_lib_dir=
1221 AC_ARG_WITH(talloc-lib-dir,
1222   [AS_HELP_STRING([--with-talloc-lib-dir=DIR],
1223   [Directory where the talloc libs may be found])],
1224   [case "$withval" in
1225     no)
1226       AC_MSG_ERROR([Need talloc-lib-dir])
1227       ;;
1228     yes)
1229       ;;
1230     *)
1231       talloc_lib_dir="$withval"
1232       ;;
1233   esac])
1234
1235 dnl #
1236 dnl # Check for talloc header files
1237 dnl #
1238 smart_try_dir="$talloc_include_dir"
1239 FR_SMART_CHECK_INCLUDE([talloc.h])
1240 if test "x$ac_cv_header_talloc_h" != "xyes"; then
1241   AC_MSG_WARN([talloc headers not found. Use --with-talloc-include-dir=<path>.])
1242   AC_MSG_ERROR([FreeRADIUS requires libtalloc])
1243 fi
1244
1245 smart_try_dir="$talloc_lib_dir"
1246 FR_SMART_CHECK_LIB(talloc, _talloc)
1247 if test "x$ac_cv_lib_talloc__talloc" != "xyes"; then
1248   AC_MSG_WARN([talloc library not found. Use --with-talloc-lib-dir=<path>.])
1249   AC_MSG_ERROR([FreeRADIUS requires libtalloc])
1250 fi
1251
1252 dnl #
1253 dnl # Check for libcrypt
1254 dnl # We use crypt(3) which may be in libc, or in libcrypt (eg FreeBSD)
1255 dnl #
1256 AC_CHECK_LIB(crypt, crypt,
1257   CRYPTLIB="-lcrypt"
1258 )
1259
1260 if test "$CRYPTLIB" != ""; then
1261   AC_DEFINE(HAVE_CRYPT, [], [Do we have the crypt function])
1262 else
1263   AC_CHECK_FUNC(crypt, AC_DEFINE(HAVE_CRYPT, [], [Do we have the crypt function]))
1264 fi
1265
1266 dnl Check for libcipher
1267 AC_CHECK_LIB(cipher, setkey,
1268    CRYPTLIB="${CRYPTLIB} -lcipher"
1269 )
1270 AC_SUBST(CRYPTLIB)
1271
1272
1273 dnl #
1274 dnl #  Check for regular expression support, if were using PCRE it MUST be included
1275 dnl #  before all others, else we seem to still pickup the posix symbols for regcomp
1276 dnl #  and regexec, which results in crashes as soon as we call any posix regex
1277 dnl #  functions.
1278 dnl #
1279 dnl extra argument: --with-pcre-lib-dir
1280 pcre_lib_dir=
1281 AC_ARG_WITH(rlm-pcre-lib-dir,
1282 [  --with-pcre-lib-dir=DIR       directory for PCRE library files []],
1283 [ case "$withval" in
1284     no)
1285         AC_MSG_ERROR(Need rlm-pcre-lib-dir)
1286         ;;
1287     yes)
1288         ;;
1289     *)
1290         pcre_lib_dir="$withval"
1291         ;;
1292   esac ]
1293 )
1294
1295 dnl extra argument: --with-pcre-include--dir
1296 pcre_include_dir=
1297 AC_ARG_WITH(rlm-pcre-include-dir,
1298 [  --with-pcre-include-dir=DIR   directory for PCRE include files []],
1299 [ case "$withval" in
1300     no)
1301         AC_MSG_ERROR(Need rlm-pcre-include-dir)
1302         ;;
1303     yes)
1304         ;;
1305     *)
1306         pcre_include_dir="$withval"
1307         ;;
1308   esac ]
1309 )
1310
1311 REGEX=no
1312 REGEX_EXTENDED=no
1313 REGEX_PCRE=no
1314
1315 dnl #
1316 dnl #  First look for PCRE
1317 dnl #
1318 smart_try_dir=$pcre_include_dir
1319 FR_SMART_CHECK_INCLUDE(pcreposix.h)
1320 if test "x$ac_cv_header_pcreposix_h" = "xyes"; then
1321   AC_DEFINE(HAVE_REGEX_H, [1], [define if we have any regex])
1322   AC_DEFINE(HAVE_PCREPOSIX_H, [1], [define this if we have the <pcreposix.h> header file])
1323   REGEX=yes
1324   REGEX_EXTENDED=yes
1325   REGEX_PCRE=yes
1326   LIBS="-lpcre -lpcreposix $LIBS"
1327
1328 dnl #
1329 dnl #  Then fallback to POSIX regular expressions
1330 dnl #
1331 else
1332   smart_try_dir=
1333   FR_SMART_CHECK_INCLUDE(regex.h)
1334   if test "x$ac_cv_header_regex_h" = "xyes"; then
1335     AC_DEFINE(HAVE_REGEX_H, [1], [define if we have any regex])
1336     REGEX=yes
1337     AC_EGREP_CPP(yes,
1338       [
1339         #include <regex.h>
1340         #ifdef REG_EXTENDED
1341         yes
1342         #endif
1343        ],
1344     [AC_DEFINE(HAVE_REG_EXTENDED, [1], [define this if we have REG_EXTENDED (from <regex.h>)]) REGEX_EXTENDED=yes]
1345     )
1346 dnl #
1347 dnl # Fixme, this is needed for mingw builds, but not available on some Linux systems
1348 dnl # despite the presence of regex.h
1349 dnl #
1350 dnl # LIBS="$LIBS -lregex"
1351   fi
1352 fi
1353
1354 AC_SUBST(REGEX)
1355 AC_SUBST(REGEX_PCRE)
1356 AC_SUBST(REGEX_EXTENDED)
1357
1358 dnl #
1359 dnl #  Check the style of gethostbyaddr, in order of preference
1360 dnl #  GNU (_r eight args)
1361 dnl #
1362 AC_DEFINE(GNUSTYLE, [1], [GNU-Style get*byaddr_r])
1363
1364 dnl #
1365 dnl #  SYSV (_r six args)
1366 dnl #
1367 AC_DEFINE(SYSVSTYLE, [2], [SYSV-Style get*byaddr_r])
1368
1369 dnl #
1370 dnl #  BSD (three args, may not be thread safe)
1371 dnl #
1372 AC_DEFINE(BSDSTYLE, [3], [BSD-Style get*byaddr_r])
1373
1374 dnl #
1375 dnl #  Tru64 has BSD version, but it is thread safe
1376 dnl #  http://h30097.www3.hp.com/docs/base_doc/DOCUMENTATION/V51B_HTML/MAN/MAN3/1739____.HTM
1377 dnl #  We need #stdio.h to define NULL on FreeBSD (at least)
1378 dnl #
1379 gethostbyaddrrstyle=""
1380 AC_MSG_CHECKING([gethostbyaddr_r() syntax])
1381 case "$host" in
1382   *-freebsd*)
1383     dnl #
1384     dnl #  With FreeBSD, check if there's a prototype for gethostbyaddr_r.
1385     dnl #  Some versions (FreeBSD 5.1?) have a symbol but no prototype - so we
1386     dnl #  override this test to BSDSTYLE. FreeBSD 6.2 and up have proper GNU
1387     dnl #  style support.
1388     dnl #
1389     AC_CHECK_DECLS([gethostbyaddr_r], [],
1390       [
1391         AC_DEFINE(GETHOSTBYADDRRSTYLE, BSDSTYLE,
1392           [style of gethostbyaddr_r functions ])
1393         gethostbyaddrrstyle=BSD
1394         AC_MSG_WARN([FreeBSD overridden to BSD-style])
1395       ],
1396       [
1397         #ifdef HAVE_NETDB_H
1398         #include <netdb.h>
1399         #endif
1400       ])
1401     ;;
1402 esac
1403
1404 if test "x$gethostbyaddrrstyle" = "x"; then
1405   AC_TRY_LINK(
1406     [
1407       #include <stdio.h>
1408       #include <netdb.h>
1409     ],
1410     [ gethostbyaddr_r(NULL, 0, 0, NULL, NULL, 0, NULL, NULL) ],
1411     [
1412       AC_DEFINE(GETHOSTBYADDRRSTYLE, GNUSTYLE, [style of gethostbyaddr_r functions ])
1413       gethostbyaddrrstyle=GNU
1414     ]
1415   )
1416 fi
1417
1418 if test "x$gethostbyaddrrstyle" = "x"; then
1419   AC_TRY_LINK(
1420     [
1421       #include <stdio.h>
1422       #include <netdb.h>
1423     ],
1424     [ gethostbyaddr_r(NULL, 0, 0, NULL, NULL, 0, NULL) ] ,
1425     [
1426       AC_DEFINE(GETHOSTBYADDRRSTYLE, SYSVSTYLE, [style of gethostbyaddr_r functions ])
1427       gethostbyaddrrstyle=SYSV
1428     ]
1429   )
1430 fi
1431
1432
1433 if test "x$gethostbyaddrrstyle" = "x"; then
1434   AC_TRY_LINK(
1435     [
1436       #include <stdio.h>
1437       #include <netdb.h>
1438     ],
1439     [ gethostbyaddr(NULL, 0, 0)  ],
1440     [
1441       AC_DEFINE(GETHOSTBYADDRRSTYLE, BSDSTYLE, [style of gethostbyaddr_r functions ])
1442       gethostbyaddrrstyle=BSD
1443     ]
1444   )
1445 fi
1446
1447 if test "x$gethostbyaddrrstyle" = "x"; then
1448   AC_MSG_RESULT([none!  It must not exist, here.])
1449 else
1450   AC_MSG_RESULT([${gethostbyaddrrstyle}-style])
1451 fi
1452
1453 if test "x$gethostbyaddrrstyle" = "xBSD"; then
1454   AC_MSG_WARN([ ****** BSD-style gethostbyaddr might NOT be thread-safe! ****** ])
1455 fi
1456
1457 dnl #
1458 dnl #  Check the style of gethostbyname, in order of preference
1459 dnl #  GNU (_r seven args)
1460 dnl #  SYSV (_r five args)
1461 dnl #  BSD (two args, may not be thread safe)
1462 dnl #  Tru64 has BSD version, but it _is_ thread safe
1463 dnl #    http://h30097.www3.hp.com/docs/base_doc/DOCUMENTATION/V51B_HTML/MAN/MAN3/1946____.HTM
1464 dnl #  We need #stdio.h to define NULL on FreeBSD (at least)
1465 dnl #
1466 gethostbynamerstyle=""
1467 AC_MSG_CHECKING([gethostbyname_r() syntax])
1468 AC_TRY_LINK(
1469   [
1470     #include <stdio.h>
1471     #include <netdb.h>
1472   ],
1473   [ gethostbyname_r(NULL, NULL, NULL, 0, NULL, NULL) ],
1474   [
1475     AC_DEFINE(GETHOSTBYNAMERSTYLE, GNUSTYLE, [style of gethostbyname_r functions ])
1476     gethostbynamerstyle=GNU
1477   ]
1478 )
1479
1480 if test "x$gethostbynamerstyle" = "x"; then
1481   AC_TRY_LINK(
1482     [
1483       #include <stdio.h>
1484       #include <netdb.h>
1485     ],
1486     [ gethostbyname_r(NULL, NULL, NULL, 0, NULL) ] ,
1487     [
1488       AC_DEFINE(GETHOSTBYNAMERSTYLE, SYSVSTYLE, [style of gethostbyname_r functions ])
1489       gethostbynamerstyle=SYSV
1490     ]
1491   )
1492 fi
1493
1494 if test "x$gethostbynamerstyle" = "x"; then
1495   AC_TRY_LINK(
1496     [
1497       #include <stdio.h>
1498       #include <netdb.h>
1499     ],
1500     [ gethostbyname(NULL) ],
1501     [
1502       AC_DEFINE(GETHOSTBYNAMERSTYLE, BSDSTYLE, [style of gethostbyname_r functions ])
1503       gethostbynamerstyle=BSD
1504     ]
1505   )
1506 fi
1507
1508 if test "x$gethostbynamerstyle" = "x"; then
1509   AC_MSG_RESULT([none!  It must not exist, here.])
1510 else
1511   AC_MSG_RESULT([${gethostbynamerstyle}-style])
1512 fi
1513
1514 if test "x$gethostbynamerstyle" = "xBSD"; then
1515   AC_MSG_WARN([ ****** BSD-style gethostbyname might NOT be thread-safe! ****** ])
1516 fi
1517
1518 dnl #
1519 dnl #  Check for non-posix solaris ctime_r (extra buflen int arg)
1520 dnl #
1521 AC_DEFINE(POSIXSTYLE, [1], [Posix-Style ctime_r])
1522 AC_DEFINE(SOLARISSTYLE, [2], [Solaris-Style ctime_r])
1523 ctimerstyle=""
1524 AC_MSG_CHECKING([ctime_r() syntax])
1525 AC_TRY_LINK(
1526   [
1527     #include <time.h>
1528   ],
1529   [ ctime_r(NULL, NULL, 0) ],
1530   [
1531     AC_DEFINE(CTIMERSTYLE, SOLARISSTYLE, [style of ctime_r function])
1532     ctimerstyle="SOLARIS"
1533   ]
1534 )
1535
1536 if test "x$ctimerstyle" = "x"; then
1537   AC_TRY_LINK(
1538     [
1539       #include <time.h>
1540     ],
1541     [ ctime_r(NULL, NULL) ],
1542     [
1543       AC_DEFINE(CTIMERSTYLE, POSIXSTYLE, [style of ctime_r function])
1544       ctimerstyle="POSIX"
1545     ]
1546   )
1547 fi
1548
1549 if test "x$ctimerstyle" = "x"; then
1550     AC_MSG_RESULT([none!  It must not exist, here.])
1551 else
1552     AC_MSG_RESULT([${ctimerstyle}-style])
1553 fi
1554
1555 AC_SUBST(HOSTINFO, $host)
1556
1557 dnl #############################################################
1558 dnl #
1559 dnl #  8. Checks for system services
1560 dnl #
1561 dnl #############################################################
1562
1563 dnl #
1564 dnl #  Figure out where libtool is located,
1565 dnl #
1566 top_builddir=`pwd`
1567 export top_builddir
1568 AC_MSG_RESULT([top_builddir=$top_builddir])
1569 dnl #  AC_SUBST(top_builddir)
1570
1571 dnl #
1572 dnl #  import libtool stuff
1573 dnl #
1574 dnl #############################################################
1575 dnl #
1576 dnl #  Configure in any module directories.
1577 dnl #
1578 dnl #############################################################
1579
1580 dnl ############################################################
1581 dnl #  Remove any conflicting definitions if autoconf.h
1582 dnl #  is being included by a module.
1583 dnl #############################################################
1584 AH_BOTTOM([#include <freeradius-devel/automask.h>])
1585
1586 dnl ############################################################
1587 dnl #  make modules by list
1588 dnl #############################################################
1589 if test "x$EXPERIMENTAL" = "xyes"; then
1590   for foo in `ls -1 "${srcdir}"/src/modules | grep rlm_`; do
1591     MODULES="$MODULES $foo"
1592   done
1593 else
1594    dnl #
1595    dnl #  make ONLY the stable modules
1596    dnl #
1597    for foo in `cat "${srcdir}"/src/modules/stable`; do
1598       MODULES="$MODULES $foo"
1599    done
1600 fi
1601
1602 dnl ############################################################
1603 dnl #  Add autoconf subdirs, based on the module list we
1604 dnl #  previously created.
1605 dnl #############################################################
1606 mysubdirs=""
1607 for bar in $MODULES; do
1608   if test -f "${srcdir}"/src/modules/$bar/configure; then
1609     mysubdirs="$mysubdirs src/modules/$bar"
1610   fi
1611 done
1612
1613 dnl #
1614 dnl #  Don't change the variable name here.  Autoconf goes bonkers
1615 dnl #  if you do.
1616 dnl #
1617 AC_CONFIG_SUBDIRS($mysubdirs)
1618 AC_SUBST(MODULES)
1619
1620 dnl #############################################################
1621 dnl #
1622 dnl #  Add -Werror last, so it doesn't interfere with autoconf's
1623 dnl #  test programs.
1624 dnl #
1625 dnl #############################################################
1626 if test "x$werror" == "xyes"; then
1627   CFLAGS="-Werror $CFLAGS"
1628 fi
1629
1630 dnl #############################################################
1631 dnl #
1632 dnl #  And finally, output the results.
1633 dnl #
1634 dnl #############################################################
1635 AC_CONFIG_COMMANDS([stamp-h], [echo timestamp > src/include/stamp-h])
1636 AC_CONFIG_COMMANDS([build-radpaths-h], [(cd ./src/include && /bin/sh ./build-radpaths-h)])
1637 AC_CONFIG_COMMANDS([main-chmod], [(cd ./src/main && chmod +x checkrad radlast radtest)])
1638 AC_CONFIG_COMMANDS([scripts-chmod], [(cd ./scripts && chmod +x rc.radiusd radiusd.cron.daily radiusd.cron.monthly cryptpasswd)])
1639
1640 dnl #
1641 dnl #  Substitute whatever libraries we found to be necessary
1642 dnl #
1643 AC_SUBST(LIBS)
1644 AC_SUBST(INSTALLSTRIP)
1645
1646 AC_SUBST(USE_SHARED_LIBS)
1647 USE_STATIC_LIBS="yes"
1648 AC_SUBST(USE_STATIC_LIBS)
1649 AC_SUBST(STATIC_MODULES)
1650
1651 AC_OUTPUT(\
1652   ./Make.inc \
1653   ./src/include/build-radpaths-h \
1654   ./src/main/radsniff.mk \
1655   ./src/main/checkrad \
1656   ./src/main/radlast \
1657   ./src/main/radtest \
1658   ./scripts/rc.radiusd \
1659   ./scripts/radiusd.cron.daily \
1660   ./scripts/radiusd.cron.monthly \
1661   ./scripts/cryptpasswd \
1662   ./raddb/dictionary \
1663   ./raddb/radrelay.conf \
1664   ./raddb/radiusd.conf
1665 )