Merge branch 'collectd-5.7' into collectd-5.8
[collectd.git] / configure.ac
1 dnl Process this file with autoconf to produce a configure script.
2 AC_PREREQ([2.60])
3 AC_INIT([collectd],[m4_esyscmd(./version-gen.sh)])
4 AC_CONFIG_SRCDIR(src/target_set.c)
5 AC_CONFIG_HEADERS(src/config.h)
6 AC_CONFIG_AUX_DIR([build-aux])
7 AC_CONFIG_MACRO_DIR([m4])
8
9 dnl older automake's default of ARFLAGS=cru is noisy on newer binutils;
10 dnl we don't really need the 'u' even in older toolchains.  Then there is
11 dnl older libtool, which spelled it AR_FLAGS
12 m4_divert_text([DEFAULTS], [: "${ARFLAGS=cr} ${AR_FLAGS=cr}"])
13
14 LT_INIT([dlopen disable-static])
15
16 AM_INIT_AUTOMAKE([subdir-objects tar-pax dist-bzip2 no-dist-gzip foreign])
17 m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
18 AC_LANG(C)
19
20 AC_PREFIX_DEFAULT("/opt/collectd")
21
22 AC_SYS_LARGEFILE
23
24 #
25 # Checks for programs.
26 #
27 AC_PROG_CC_C99([],
28   [AC_MSG_ERROR([No compiler found that supports C99])]
29 )
30
31 AX_COMPILER_VENDOR
32
33 AC_PROG_CXX
34 AC_PROG_CPP
35 AC_PROG_EGREP
36 AC_PROG_INSTALL
37 AC_PROG_LN_S
38 AC_PROG_MAKE_SET
39 AM_PROG_CC_C_O
40
41 AC_PROG_LEX
42 AC_PROG_YACC
43
44 AC_PATH_PROG([VALGRIND], [valgrind])
45
46 # Warn when pkg.m4 is missing
47 m4_pattern_forbid([^_?PKG_[A-Z_]+$],[*** pkg.m4 missing, please install pkg-config])
48
49 PKG_PROG_PKG_CONFIG
50
51 AC_CACHE_CHECK([if Bison is the parser generator],
52   [collectd_cv_prog_bison],
53   [
54     AS_IF([$YACC --version 2>/dev/null | $EGREP -q '^bison '],
55       [collectd_cv_prog_bison=yes],
56       [collectd_cv_prog_bison=no]
57     )
58   ]
59 )
60
61 if test "x$collectd_cv_prog_bison" = "xno" && test ! -f "${srcdir}/src/liboconfig/parser.c"; then
62   AC_MSG_ERROR([bison is missing and you do not have ${srcdir}/src/liboconfig/parser.c. Please install bison])
63 fi
64
65 if test "x$lt_cv_dlopen" = "xno"; then
66   AC_MSG_ERROR([Your system does not support dlopen])
67 fi
68
69 AC_SUBST([DLOPEN_LIBS], [$lt_cv_dlopen_libs])
70
71
72 AC_MSG_CHECKING([for kernel type ($host_os)])
73 case $host_os in
74   *aix*)
75     AC_DEFINE([KERNEL_AIX], [1], [True if program is to be compiled for a AIX kernel])
76     ac_system="AIX"
77     ;;
78   *darwin*)
79     AC_DEFINE([KERNEL_DARWIN], [1], [True if program is to be compiled for a Darwin kernel])
80     ac_system="Darwin"
81     ;;
82   *freebsd*)
83     AC_DEFINE([KERNEL_FREEBSD], [1], [True if program is to be compiled for a FreeBSD kernel])
84     ac_system="FreeBSD"
85     ;;
86   *linux*)
87     AC_DEFINE([KERNEL_LINUX], [1], [True if program is to be compiled for a Linux kernel])
88     ac_system="Linux"
89     ;;
90   *netbsd*)
91     AC_DEFINE([KERNEL_NETBSD], [1], [True if program is to be compiled for a NetBSD kernel])
92     ac_system="NetBSD"
93     ;;
94   *openbsd*)
95     AC_DEFINE([KERNEL_OPENBSD], [1], [True if program is to be compiled for an OpenBSD kernel])
96     ac_system="OpenBSD"
97     ;;
98   *solaris*)
99     AC_DEFINE([KERNEL_SOLARIS], [1], [True if program is to be compiled for a Solaris kernel])
100     ac_system="Solaris"
101     ;;
102   *)
103     ac_system="unknown"
104     ;;
105 esac
106 AC_MSG_RESULT([$ac_system])
107
108 AM_CONDITIONAL([BUILD_AIX], [test "x$ac_system" = "xAIX"])
109 AM_CONDITIONAL([BUILD_DARWIN], [test "x$ac_system" = "xDarwin"])
110 AM_CONDITIONAL([BUILD_FREEBSD], [test "x$ac_system" = "xFreeBSD"])
111 AM_CONDITIONAL([BUILD_LINUX], [test "x$ac_system" = "xLinux"])
112 AM_CONDITIONAL([BUILD_OPENBSD], [test "x$ac_system" = "xOpenBSD"])
113 AM_CONDITIONAL([BUILD_SOLARIS], [test "x$ac_system" = "xSolaris"])
114
115 if test "x$ac_system" = "xSolaris"; then
116   AC_DEFINE([_POSIX_PTHREAD_SEMANTICS], [1], [Define to enforce POSIX thread semantics under Solaris.])
117   AC_DEFINE([_REENTRANT], [1], [Define to enable reentrancy interfaces.])
118
119   AC_MSG_CHECKING([whether compiler builds 64bit binaries])
120   AC_COMPILE_IFELSE(
121     [
122       AC_LANG_PROGRAM(
123         [
124           #ifndef _LP64
125           # error "Compiler not in 64bit mode."
126           #endif
127         ]
128       )
129     ],
130     [AC_MSG_RESULT([yes])],
131     [
132       AC_MSG_RESULT([no])
133       AC_MSG_NOTICE([Solaris detected. Please consider building a 64-bit binary.])
134     ]
135   )
136 fi
137
138 if test "x$ac_system" = "xAIX"; then
139   AC_DEFINE([_THREAD_SAFE_ERRNO], [1], [Define to use the thread-safe version of errno under AIX.])
140 fi
141
142 # Where to install .pc files.
143 pkgconfigdir="${libdir}/pkgconfig"
144 AC_SUBST([pkgconfigdir])
145
146 #
147 # Checks for header files.
148 #
149 AC_HEADER_SYS_WAIT
150 AC_HEADER_DIRENT
151
152 AC_CHECK_HEADERS_ONCE([ \
153   arpa/inet.h \
154   endian.h \
155   fcntl.h \
156   fnmatch.h \
157   fs_info.h \
158   fshelp.h \
159   grp.h \
160   kstat.h \
161   kvm.h \
162   libgen.h \
163   mntent.h \
164   mnttab.h \
165   netdb.h \
166   paths.h \
167   poll.h \
168   pthread_np.h \
169   pwd.h \
170   regex.h \
171   sys/endian.h \
172   sys/fs_types.h \
173   sys/fstyp.h \
174   sys/ioctl.h \
175   sys/isa_defs.h \
176   sys/mntent.h \
177   sys/mnttab.h \
178   sys/param.h \
179   sys/resource.h \
180   sys/select.h \
181   sys/socket.h \
182   sys/statfs.h \
183   sys/statvfs.h \
184   sys/types.h \
185   sys/un.h \
186   sys/vfs.h \
187   sys/vfstab.h \
188   sys/vmmeter.h \
189   syslog.h \
190   wordexp.h
191 ])
192
193 if test "x$ac_system" = "xNetBSD"; then
194   # For entropy plugin on newer NetBSD
195   AC_CHECK_HEADERS([sys/rndio.h], [], [],
196     [[
197       #if HAVE_SYS_TYPES_H
198       # include <sys/types.h>
199       #endif
200       #if HAVE_SYS_IOCTL_H
201       # include <sys/ioctl.h>
202       #endif
203       #if HAVE_SYS_PARAM_H
204       # include <sys/param.h>
205       #endif
206     ]]
207   )
208 fi
209
210 # For ping library
211 AC_CHECK_HEADERS([netinet/in_systm.h], [], [],
212   [[
213     #include <stdint.h>
214     #if HAVE_SYS_TYPES_H
215     # include <sys/types.h>
216     #endif
217   ]]
218 )
219
220 AC_CHECK_HEADERS([netinet/in.h], [], [],
221   [[
222     #include <stdint.h>
223     #if HAVE_SYS_TYPES_H
224     # include <sys/types.h>
225     #endif
226     #if HAVE_NETINET_IN_SYSTM_H
227     # include <netinet/in_systm.h>
228     #endif
229   ]]
230 )
231
232 AC_CHECK_HEADERS([netinet/ip.h], [], [],
233   [[
234     #include <stdint.h>
235     #if HAVE_SYS_TYPES_H
236     # include <sys/types.h>
237     #endif
238     #if HAVE_NETINET_IN_SYSTM_H
239     # include <netinet/in_systm.h>
240     #endif
241     #if HAVE_NETINET_IN_H
242     # include <netinet/in.h>
243     #endif
244   ]]
245 )
246
247 AC_CHECK_HEADERS([netinet/ip_icmp.h], [], [],
248   [[
249     #include <stdint.h>
250     #if HAVE_SYS_TYPES_H
251     # include <sys/types.h>
252     #endif
253     #if HAVE_NETINET_IN_SYSTM_H
254     # include <netinet/in_systm.h>
255     #endif
256     #if HAVE_NETINET_IN_H
257     # include <netinet/in.h>
258     #endif
259     #if HAVE_NETINET_IP_H
260     # include <netinet/ip.h>
261     #endif
262   ]]
263 )
264
265 AC_CHECK_HEADERS([netinet/ip_var.h], [], [],
266   [[
267     #include <stdint.h>
268     #if HAVE_SYS_TYPES_H
269     # include <sys/types.h>
270     #endif
271     #if HAVE_NETINET_IN_SYSTM_H
272     # include <netinet/in_systm.h>
273     #endif
274     #if HAVE_NETINET_IN_H
275     # include <netinet/in.h>
276     #endif
277     #if HAVE_NETINET_IP_H
278     # include <netinet/ip.h>
279     #endif
280   ]]
281 )
282
283 AC_CHECK_HEADERS([netinet/ip6.h], [], [],
284   [[
285     #include <stdint.h>
286     #if HAVE_SYS_TYPES_H
287     # include <sys/types.h>
288     #endif
289     #if HAVE_NETINET_IN_SYSTM_H
290     # include <netinet/in_systm.h>
291     #endif
292     #if HAVE_NETINET_IN_H
293     # include <netinet/in.h>
294     #endif
295   ]]
296 )
297
298 AC_CHECK_HEADERS([netinet/icmp6.h], [], [],
299   [[
300     #include <stdint.h>
301     #if HAVE_SYS_TYPES_H
302     # include <sys/types.h>
303     #endif
304     #if HAVE_NETINET_IN_SYSTM_H
305     # include <netinet/in_systm.h>
306     #endif
307     #if HAVE_NETINET_IN_H
308     # include <netinet/in.h>
309     #endif
310     #if HAVE_NETINET_IP6_H
311     # include <netinet/ip6.h>
312     #endif
313   ]]
314 )
315
316 AC_CHECK_HEADERS([netinet/tcp.h], [], [],
317   [[
318     #include <stdint.h>
319     #if HAVE_SYS_TYPES_H
320     # include <sys/types.h>
321     #endif
322     #if HAVE_NETINET_IN_SYSTM_H
323     # include <netinet/in_systm.h>
324     #endif
325     #if HAVE_NETINET_IN_H
326     # include <netinet/in.h>
327     #endif
328     #if HAVE_NETINET_IP_H
329     # include <netinet/ip.h>
330     #endif
331   ]]
332 )
333
334 AC_CHECK_HEADERS([netinet/udp.h], [], [],
335   [[
336     #include <stdint.h>
337     #if HAVE_SYS_TYPES_H
338     # include <sys/types.h>
339     #endif
340     #if HAVE_NETINET_IN_SYSTM_H
341     # include <netinet/in_systm.h>
342     #endif
343     #if HAVE_NETINET_IN_H
344     # include <netinet/in.h>
345     #endif
346     #if HAVE_NETINET_IP_H
347     # include <netinet/ip.h>
348     #endif
349   ]]
350 )
351
352 # For cpu modules
353 AC_CHECK_HEADERS([sys/dkstat.h])
354 if test "x$ac_system" = "xDarwin"; then
355   AC_CHECK_HEADERS(
356     [ \
357       mach/mach_init.h \
358       mach/host_priv.h \
359       mach/mach_error.h \
360       mach/mach_host.h \
361       mach/mach_port.h \
362       mach/mach_types.h \
363       mach/message.h \
364       mach/processor_set.h \
365       mach/processor.h \
366       mach/processor_info.h \
367       mach/task.h \
368       mach/thread_act.h \
369       mach/vm_region.h \
370       mach/vm_map.h \
371       mach/vm_prot.h \
372       mach/vm_statistics.h \
373       mach/kern_return.h \
374       CoreFoundation/CoreFoundation.h \
375       IOKit/IOKitLib.h \
376       IOKit/IOTypes.h \
377       IOKit/ps/IOPSKeys.h \
378       IOKit/IOBSD.h \
379       IOKit/storage/IOBlockStorageDriver.h
380     ]
381   )
382
383   # For the battery plugin
384   AC_CHECK_HEADERS([IOKit/ps/IOPowerSources.h], [], [],
385     [[
386       #if HAVE_IOKIT_IOKITLIB_H
387       #  include <IOKit/IOKitLib.h>
388       #endif
389       #if HAVE_IOKIT_IOTYPES_H
390       #  include <IOKit/IOTypes.h>
391       #endif
392     ]]
393   )
394 fi
395
396 AC_CHECK_HEADERS([sys/sysctl.h], [], [],
397   [[
398     #if HAVE_SYS_TYPES_H
399     #  include <sys/types.h>
400     #endif
401     #if HAVE_SYS_PARAM_H
402     # include <sys/param.h>
403     #endif
404   ]]
405 )
406
407 # For interface plugin
408 AC_CHECK_HEADERS([ifaddrs.h])
409 AC_CHECK_HEADERS([net/if.h], [], [],
410   [[
411     #if HAVE_SYS_TYPES_H
412     #  include <sys/types.h>
413     #endif
414     #if HAVE_SYS_SOCKET_H
415     #  include <sys/socket.h>
416     #endif
417   ]]
418 )
419
420 if test "x$ac_system" = "xLinux"; then
421   # For hddtemp module
422   AC_CHECK_HEADERS([linux/major.h])
423
424   # For md module (Linux only)
425   AC_CHECK_HEADERS([linux/raid/md_u.h],
426     [have_linux_raid_md_u_h="yes"],
427     [have_linux_raid_md_u_h="no"],
428     [[
429       #include <sys/ioctl.h>
430       #include <linux/major.h>
431       #include <linux/types.h>
432     ]]
433   )
434   AC_CHECK_HEADERS([sys/sysmacros.h])
435
436   AC_CHECK_HEADERS([linux/wireless.h],
437     [have_linux_wireless_h="yes"],
438     [have_linux_wireless_h="no"],
439     [[
440       #include <dirent.h>
441       #include <sys/ioctl.h>
442       #include <sys/socket.h>
443     ]]
444   )
445
446   AC_CHECK_HEADERS([linux/if.h], [], [],
447     [[
448       #if HAVE_SYS_TYPES_H
449       #  include <sys/types.h>
450       #endif
451       #if HAVE_SYS_SOCKET_H
452       #  include <sys/socket.h>
453       #endif
454     ]]
455   )
456
457   AC_CHECK_HEADERS([linux/inet_diag.h], [], [],
458     [[
459       #if HAVE_SYS_TYPES_H
460       #  include <sys/types.h>
461       #endif
462       #if HAVE_SYS_SOCKET_H
463       #  include <sys/socket.h>
464       #endif
465     ]]
466   )
467
468   AC_CHECK_HEADERS([linux/netdevice.h], [], [],
469     [[
470       #if HAVE_SYS_TYPES_H
471       #  include <sys/types.h>
472       #endif
473       #if HAVE_SYS_SOCKET_H
474       #  include <sys/socket.h>
475       #endif
476       #if HAVE_LINUX_IF_H
477       # include <linux/if.h>
478       #endif
479     ]]
480   )
481
482   # For ethstat module
483   AC_CHECK_HEADERS([linux/sockios.h],
484     [have_linux_sockios_h="yes"],
485     [have_linux_sockios_h="no"],
486     [[
487       #if HAVE_SYS_IOCTL_H
488       # include <sys/ioctl.h>
489       #endif
490       #if HAVE_NET_IF_H
491       # include <net/if.h>
492       #endif
493     ]]
494   )
495
496   AC_CHECK_HEADERS([linux/ethtool.h],
497     [have_linux_ethtool_h="yes"],
498     [have_linux_ethtool_h="no"],
499     [[
500       #if HAVE_SYS_IOCTL_H
501       # include <sys/ioctl.h>
502       #endif
503       #if HAVE_NET_IF_H
504       # include <net/if.h>
505       #endif
506       #if HAVE_LINUX_SOCKIOS_H
507       # include <linux/sockios.h>
508       #endif
509     ]]
510   )
511
512   # For ipvs module
513   AC_CHECK_HEADERS_ONCE([linux/ip_vs.h])
514
515   # For the email plugin
516   AC_CHECK_HEADERS([linux/un.h], [], [],
517     [[
518       #if HAVE_SYS_SOCKET_H
519       #  include <sys/socket.h>
520       #endif
521     ]]
522   )
523   # For the turbostat plugin
524   AC_CHECK_HEADERS([cpuid.h],
525     [have_cpuid_h="yes"],
526     [have_cpuid_h="no (cpuid.h not found)"]
527   )
528
529   AC_CHECK_HEADERS([sys/capability.h],
530     [have_capability="yes"],
531     [have_capability="no (<sys/capability.h> not found)"]
532   )
533
534   if test "x$have_capability" = "xyes"; then
535     AC_CHECK_LIB([cap], [cap_get_proc],
536       [have_capability="yes"],
537       [have_capability="no (cap_get_proc() not found)"]
538     )
539   fi
540
541   if test "x$have_capability" = "xyes"; then
542     AC_CHECK_DECL([CAP_IS_SUPPORTED],
543       [have_capability="yes"],
544       [have_capability="no (CAP_IS_SUPPORTED not found)"],
545       [[#include <sys/capability.h>]]
546     )
547   fi
548
549   if test "x$have_capability" = "xyes"; then
550     AC_DEFINE([HAVE_CAPABILITY], [1], [Define to 1 if you have cap_get_proc() (-lcap).])
551   fi
552
553 else
554   have_linux_raid_md_u_h="no"
555   have_linux_wireless_h="no"
556 fi
557
558 AM_CONDITIONAL([BUILD_WITH_CAPABILITY], [test "x$have_capability" = "xyes"])
559
560 # For the swap module
561 have_sys_swap_h="yes"
562 AC_CHECK_HEADERS([sys/swap.h vm/anon.h],
563   [],
564   [have_sys_swap_h="no"],
565   [[
566     #undef _FILE_OFFSET_BITS
567     #undef _LARGEFILE64_SOURCE
568     #if HAVE_SYS_TYPES_H
569     #  include <sys/types.h>
570     #endif
571     #if HAVE_SYS_PARAM_H
572     # include <sys/param.h>
573     #endif
574   ]]
575 )
576
577 # For load module
578 # For the processes plugin
579 # For users module
580 AC_CHECK_HEADERS([sys/loadavg.h linux/config.h utmp.h utmpx.h])
581
582 # For quota module
583 AC_CHECK_HEADERS([sys/ucred.h], [], [],
584   [[
585     #if HAVE_SYS_TYPES_H
586     #  include <sys/types.h>
587     #endif
588     #if HAVE_SYS_PARAM_H
589     # include <sys/param.h>
590     #endif
591   ]]
592 )
593
594 # For mount interface
595 AC_CHECK_HEADERS([sys/mount.h], [], [],
596   [[
597     #if HAVE_SYS_TYPES_H
598     #  include <sys/types.h>
599     #endif
600     #if HAVE_SYS_PARAM_H
601     # include <sys/param.h>
602     #endif
603   ]]
604 )
605
606 # --enable-xfs {{{
607 AC_ARG_ENABLE([xfs],
608   [AS_HELP_STRING([--enable-xfs], [xfs support in df plugin @<:@default=yes@:>@])],
609   [],
610   [enable_xfs="auto"]
611 )
612
613 if test "x$enable_xfs" != "xno"; then
614   AC_CHECK_HEADERS([xfs/xqm.h],
615     [],
616     [
617       if test "x$enable_xfs" = "xyes"; then
618         AC_MSG_ERROR([xfs/xqm.h not found])
619       fi
620     ],
621     [[#define _GNU_SOURCE]]
622   )
623 fi
624
625 # }}}
626
627 # For the dns plugin
628 AC_CHECK_HEADERS([arpa/nameser.h])
629 AC_CHECK_HEADERS([arpa/nameser_compat.h], [], [],
630   [[
631     #if HAVE_ARPA_NAMESER_H
632     # include <arpa/nameser.h>
633     #endif
634   ]]
635 )
636
637 AC_CHECK_HEADERS([net/if_arp.h], [], [],
638   [[
639     #if HAVE_SYS_SOCKET_H
640     # include <sys/socket.h>
641     #endif
642   ]]
643 )
644
645 AC_CHECK_HEADERS([net/ppp_defs.h])
646 AC_CHECK_HEADERS([net/if_ppp.h], [], [],
647   [[
648     #if HAVE_NET_PPP_DEFS_H
649     # include <net/ppp_defs.h>
650     #endif
651   ]]
652 )
653
654 AC_CHECK_HEADERS([netinet/if_ether.h], [], [],
655   [[
656     #include <stdint.h>
657     #if HAVE_SYS_TYPES_H
658     # include <sys/types.h>
659     #endif
660     #if HAVE_SYS_SOCKET_H
661     # include <sys/socket.h>
662     #endif
663     #if HAVE_NET_IF_H
664     # include <net/if.h>
665     #endif
666     #if HAVE_NETINET_IN_H
667     # include <netinet/in.h>
668     #endif
669   ]]
670 )
671
672 AC_CHECK_HEADERS([net/pfvar.h],
673   [have_net_pfvar_h="yes"],
674   [have_net_pfvar_h="no"],
675   [[
676     #if HAVE_SYS_IOCTL_H
677     # include <sys/ioctl.h>
678     #endif
679     #if HAVE_SYS_SOCKET_H
680     # include <sys/socket.h>
681     #endif
682     #if HAVE_NET_IF_H
683     # include <net/if.h>
684     #endif
685     #if HAVE_NETINET_IN_H
686     # include <netinet/in.h>
687     #endif
688   ]]
689 )
690
691 # For the multimeter plugin
692 AC_CHECK_HEADERS([termios.h],
693   [have_termios_h="yes"],
694   [have_termios_h="no"]
695 )
696
697 # For cpusleep plugin
698 AC_CACHE_CHECK([whether clock_boottime and clock_monotonic are supported],
699   [c_cv_have_clock_boottime_monotonic],
700   [
701     AC_COMPILE_IFELSE(
702       [AC_LANG_PROGRAM(
703         [[#include <time.h>]],
704         [[
705           struct timespec b, m;
706           clock_gettime(CLOCK_BOOTTIME, &b );
707           clock_gettime(CLOCK_MONOTONIC, &m );
708         ]]
709       )
710       ],
711       [c_cv_have_clock_boottime_monotonic="yes"],
712       [c_cv_have_clock_boottime_monotonic="no"]
713     )
714   ]
715 )
716
717
718 #
719 # Checks for typedefs, structures, and compiler characteristics.
720 #
721 AC_C_CONST
722 AC_TYPE_PID_T
723 AC_TYPE_SIZE_T
724 AC_TYPE_UID_T
725 AC_HEADER_TIME
726
727 test_cxx_flags() {
728   AC_LANG_PUSH([C++])
729   AC_LANG_CONFTEST(
730     [AC_LANG_SOURCE([[int main(void){}]]) ]
731   )
732   $CXX -c conftest.cpp $CXXFLAGS $@ > /dev/null 2> /dev/null
733   ret=$?
734   rm -f conftest.o
735   AC_LANG_POP([C++])
736   return $ret
737 }
738
739 #
740 # Checks for library functions.
741 #
742 AC_CHECK_FUNCS_ONCE([ \
743     asprintf \
744     closelog \
745     getaddrinfo \
746     getgrnam_r \
747     getnameinfo \
748     getpwnam_r \
749     gettimeofday \
750     if_indextoname \
751     openlog \
752     regcomp \
753     regerror \
754     regexec \
755     regfree \
756     select \
757     setenv \
758     setgroups \
759     strcasecmp \
760     strdup \
761     strncasecmp \
762     sysconf
763   ]
764 )
765
766 AC_FUNC_STRERROR_R
767
768 SAVE_CFLAGS="$CFLAGS"
769 # Emulate behavior of src/Makefile.am
770 if test "x$GCC" = "xyes"; then
771   CFLAGS="$CFLAGS -Wall -Werror"
772 fi
773
774 AC_CACHE_CHECK([for strtok_r],
775   [c_cv_have_strtok_r_default],
776   [
777     AC_LINK_IFELSE(
778       [
779         AC_LANG_PROGRAM(
780           [[
781             #include <stdlib.h>
782             #include <stdio.h>
783             #include <string.h>
784           ]],
785           [[
786             char buffer[] = "foo,bar,baz";
787             char *token;
788             char *dummy;
789             char *saveptr;
790
791             dummy = buffer;
792             saveptr = NULL;
793             while ((token = strtok_r (dummy, ",", &saveptr)) != NULL)
794             {
795               dummy = NULL;
796               printf ("token = %s;\n", token);
797             }
798           ]]
799         )
800       ],
801       [c_cv_have_strtok_r_default="yes"],
802       [c_cv_have_strtok_r_default="no"]
803     )
804   ]
805 )
806
807 if test "x$c_cv_have_strtok_r_default" = "xno"; then
808   CFLAGS="$CFLAGS -D_REENTRANT=1"
809
810   AC_CACHE_CHECK([if strtok_r needs _REENTRANT],
811     [c_cv_have_strtok_r_reentrant],
812     [
813       AC_LINK_IFELSE(
814         [
815           AC_LANG_PROGRAM(
816             [[
817               #include <stdlib.h>
818               #include <stdio.h>
819               #include <string.h>
820             ]],
821             [[
822               char buffer[] = "foo,bar,baz";
823               char *token;
824               char *dummy;
825               char *saveptr;
826
827               dummy = buffer;
828               saveptr = NULL;
829               while ((token = strtok_r (dummy, ",", &saveptr)) != NULL)
830               {
831                 dummy = NULL;
832                 printf ("token = %s;\n", token);
833               }
834             ]]
835           )
836         ],
837         [c_cv_have_strtok_r_reentrant="yes"],
838         [AC_MSG_FAILURE([strtok_r is not available. Please file a bugreport!])]
839       )
840     ]
841   )
842 fi
843
844 CFLAGS="$SAVE_CFLAGS"
845 if test "x$c_cv_have_strtok_r_reentrant" = "xyes"; then
846   CFLAGS="$CFLAGS -D_REENTRANT=1"
847 fi
848
849 AC_CHECK_FUNCS([socket],
850   [],
851   [
852     AC_CHECK_LIB([socket], [socket],
853       [socket_needs_socket="yes"],
854       [AC_MSG_ERROR([cannot find socket() in libsocket])]
855     )
856   ]
857 )
858 AM_CONDITIONAL([BUILD_WITH_LIBSOCKET], [test "x$socket_needs_socket" = "xyes"])
859
860 clock_gettime_needs_posix4="no"
861 AC_CHECK_FUNCS([clock_gettime],
862   [have_clock_gettime="yes"],
863   [have_clock_gettime="no"]
864 )
865
866 if test "x$have_clock_gettime" = "xno"; then
867   AC_CHECK_LIB([rt], [clock_gettime],
868     [
869       clock_gettime_needs_rt="yes"
870       have_clock_gettime="yes"
871     ]
872   )
873 fi
874
875 if test "x$have_clock_gettime" = "xno"; then
876   AC_CHECK_LIB([posix4], [clock_gettime],
877     [
878       clock_gettime_needs_posix4="yes"
879       have_clock_gettime="yes"
880     ]
881   )
882 fi
883
884 if test "x$have_clock_gettime" = "xyes"; then
885   AC_DEFINE([HAVE_CLOCK_GETTIME], [1], [Define if the clock_gettime(2) function is available.])
886 fi
887
888 AC_CHECK_FUNCS([nanosleep], [],
889   AC_CHECK_LIB([rt], [nanosleep],
890     [nanosleep_needs_rt="yes"],
891     [
892       AC_CHECK_LIB([posix4], [nanosleep],
893         [nanosleep_needs_posix4="yes"],
894         [AC_MSG_ERROR([cannot find nanosleep])]
895       )
896     ]
897   )
898 )
899
900 AM_CONDITIONAL([BUILD_WITH_LIBRT], [test "x$clock_gettime_needs_rt" = "xyes" || test "x$nanosleep_needs_rt" = "xyes"])
901 AM_CONDITIONAL([BUILD_WITH_LIBPOSIX4], [test "x$clock_gettime_needs_posix4" = "xyes" || test "x$nanosleep_needs_posix4" = "xyes"])
902
903 AC_CHECK_FUNCS([getifaddrs], [have_getifaddrs="yes"], [have_getifaddrs="no"])
904 AC_CHECK_FUNCS([getloadavg], [have_getloadavg="yes"], [have_getloadavg="no"])
905 AC_CHECK_FUNCS([getutent], [have_getutent="yes"], [have_getutent="no"])
906 AC_CHECK_FUNCS([getutxent], [have_getutxent="yes"], [have_getutxent="no"])
907 AC_CHECK_FUNCS([host_statistics], [have_host_statistics="yes"], [have_host_statistics="no"])
908 AC_CHECK_FUNCS([processor_info], [have_processor_info="yes"], [have_processor_info="no"])
909 AC_CHECK_FUNCS([statfs], [have_statfs="yes"], [have_statfs="no"])
910 AC_CHECK_FUNCS([statvfs], [have_statvfs="yes"], [have_statvfs="no"])
911 AC_CHECK_FUNCS([sysctl], [have_sysctl="yes"], [have_sysctl="no"])
912 AC_CHECK_FUNCS([sysctlbyname], [have_sysctlbyname="yes"], [have_sysctlbyname="no"])
913 AC_CHECK_FUNCS([syslog], [have_syslog="yes"], [have_syslog="no"])
914 AC_CHECK_FUNCS([thread_info], [have_thread_info="yes"], [have_thread_info="no"])
915
916 # Check for strptime {{{
917 if test "x$GCC" = "xyes"; then
918   SAVE_CFLAGS="$CFLAGS"
919   CFLAGS="$CFLAGS -Wall -Wextra -Werror"
920 fi
921
922 AC_CHECK_FUNCS([strptime], [have_strptime="yes"], [have_strptime="no"])
923 if test "x$have_strptime" = "xyes"; then
924   AC_CACHE_CHECK([whether strptime is exported by default],
925     [c_cv_have_strptime_default],
926     [
927       AC_COMPILE_IFELSE(
928         [
929           AC_LANG_PROGRAM(
930             [[#include <time.h>]],
931             [[
932               struct tm stm;
933               (void)strptime ("2010-12-30%13:42:42", "%Y-%m-%dT%T", &stm);
934             ]]
935           )
936         ],
937         [c_cv_have_strptime_default="yes"],
938         [c_cv_have_strptime_default="no"])
939     ]
940   )
941 fi
942
943 if test "x$have_strptime" = "xyes" && test "x$c_cv_have_strptime_default" = "xno"; then
944   AC_CACHE_CHECK([whether strptime needs standards mode],
945     [c_cv_have_strptime_standards],
946     [
947       AC_COMPILE_IFELSE(
948         [
949           AC_LANG_PROGRAM(
950             [[
951               #ifndef _ISOC99_SOURCE
952               # define _ISOC99_SOURCE 1
953               #endif
954               #ifndef _POSIX_C_SOURCE
955               # define _POSIX_C_SOURCE 200112L
956               #endif
957               #ifndef _XOPEN_SOURCE
958               # define _XOPEN_SOURCE 500
959               #endif
960               #include <time.h>
961             ]],
962             [[
963               struct tm stm;
964               (void)strptime ("2010-12-30%13:42:42", "%Y-%m-%dT%T", &stm);
965             ]]
966           )
967         ],
968         [c_cv_have_strptime_standards="yes"],
969         [c_cv_have_strptime_standards="no"]
970       )
971     ]
972   )
973
974   if test "x$c_cv_have_strptime_standards" = "xyes"; then
975     AC_DEFINE([STRPTIME_NEEDS_STANDARDS], [1],
976       [Set to true if strptime is only exported in X/Open mode (GNU libc).]
977     )
978   else
979     have_strptime="no"
980   fi
981 fi
982
983 if test "x$GCC" = "xyes"; then
984   CFLAGS="$SAVE_CFLAGS"
985 fi
986 # }}} Check for strptime
987
988 # Check for timegm {{{
989
990 # These checks need -Werror because implicit function declarations are only a
991 # warning ...
992 SAVE_CFLAGS="$CFLAGS"
993 CFLAGS="$CFLAGS -Werror"
994
995 AC_CACHE_CHECK([for timegm],
996   [c_cv_have_timegm],
997   AC_LINK_IFELSE(
998     [AC_LANG_PROGRAM(
999 [[[
1000 #if STRPTIME_NEEDS_STANDARDS
1001 # ifndef _ISOC99_SOURCE
1002 #  define _ISOC99_SOURCE 1
1003 # endif
1004 # ifndef _POSIX_C_SOURCE
1005 #  define _POSIX_C_SOURCE 200112L
1006 # endif
1007 # ifndef _XOPEN_SOURCE
1008 #  define _XOPEN_SOURCE 500
1009 # endif
1010 #endif
1011 #include <time.h>
1012 ]]],
1013 [[[
1014  time_t t = timegm(&(struct tm){0});
1015  if (t == ((time_t) -1)) {
1016    return 1;
1017  }
1018 ]]]
1019     )],
1020     [c_cv_have_timegm="yes"],
1021     [c_cv_have_timegm="no"]
1022   )
1023 )
1024
1025 if test "x$c_cv_have_timegm" != "xyes"
1026 then
1027   AC_CACHE_CHECK([for timegm with _BSD_SOURCE],
1028     [c_cv_have_timegm_bsd],
1029     AC_LINK_IFELSE(
1030       [AC_LANG_PROGRAM(
1031 [[[
1032 #if STRPTIME_NEEDS_STANDARDS
1033 # ifndef _ISOC99_SOURCE
1034 #  define _ISOC99_SOURCE 1
1035 # endif
1036 # ifndef _POSIX_C_SOURCE
1037 #  define _POSIX_C_SOURCE 200112L
1038 # endif
1039 # ifndef _XOPEN_SOURCE
1040 #  define _XOPEN_SOURCE 500
1041 # endif
1042 #endif
1043 #ifndef _BSD_SOURCE
1044 # define _BSD_SOURCE 1
1045 #endif
1046 #include <time.h>
1047 ]]],
1048 [[[
1049  time_t t = timegm(&(struct tm){0});
1050  if (t == ((time_t) -1)) {
1051    return 1;
1052  }
1053 ]]]
1054       )],
1055       [c_cv_have_timegm_bsd="yes"
1056        c_cv_have_timegm="yes"],
1057       [c_cv_have_timegm_bsd="no"]
1058     )
1059   )
1060 fi
1061
1062 if test "x$c_cv_have_timegm" = "xyes"
1063 then
1064   AC_DEFINE(HAVE_TIMEGM, 1, [Define if the timegm(3) function is available.])
1065   if test "x$c_cv_have_timegm_bsd" = "xyes"
1066   then
1067     AC_DEFINE(TIMEGM_NEEDS_BSD, 1, [Set to true if timegm is only exported in BSD mode.])
1068   fi
1069 fi
1070
1071 CFLAGS="$SAVE_CFLAGS"
1072 # }}} Check for timegm
1073
1074 AC_MSG_CHECKING([for sysctl kern.cp_times])
1075 if test -x /sbin/sysctl; then
1076   /sbin/sysctl kern.cp_times >/dev/null 2>&1
1077   if test $? -eq 0; then
1078     AC_MSG_RESULT([yes])
1079     AC_DEFINE([HAVE_SYSCTL_KERN_CP_TIMES], [1], [Define if sysctl supports kern.cp_times])
1080   else
1081     AC_MSG_RESULT([no])
1082   fi
1083 else
1084   AC_MSG_RESULT([no])
1085 fi
1086
1087 AC_MSG_CHECKING([for sysctl kern.cp_time])
1088 if test -x /sbin/sysctl; then
1089   /sbin/sysctl kern.cp_time >/dev/null 2>&1
1090   if test $? -eq 0
1091   then
1092     AC_MSG_RESULT([yes])
1093     AC_DEFINE([HAVE_SYSCTL_KERN_CP_TIME], [1], [Define if sysctl supports kern.cp_time])
1094   else
1095     AC_MSG_RESULT([no])
1096   fi
1097 else
1098   AC_MSG_RESULT([no])
1099 fi
1100
1101 AC_CHECK_FUNCS([swapctl], [have_swapctl="yes"], [have_swapctl="no"])
1102 if test "x$have_swapctl" = "xyes"; then
1103   AC_CACHE_CHECK([whether swapctl takes two arguments],
1104     [c_cv_have_swapctl_two_args],
1105     [
1106       AC_COMPILE_IFELSE(
1107         [
1108           AC_LANG_PROGRAM(
1109             [[
1110               #if HAVE_SYS_SWAP_H && !defined(_LP64) && _FILE_OFFSET_BITS == 64
1111               #  undef _FILE_OFFSET_BITS
1112               #  undef _LARGEFILE64_SOURCE
1113               #endif
1114               #include <sys/stat.h>
1115               #include <sys/param.h>
1116               #include <sys/swap.h>
1117               #include <unistd.h>
1118             ]],
1119             [[int num = swapctl(0, NULL);]]
1120           )
1121         ],
1122         [c_cv_have_swapctl_two_args="yes"],
1123         [c_cv_have_swapctl_two_args="no"]
1124       )
1125     ]
1126   )
1127
1128   AC_CACHE_CHECK([whether swapctl takes three arguments],
1129     [c_cv_have_swapctl_three_args],
1130     [
1131       AC_COMPILE_IFELSE(
1132         [
1133           AC_LANG_PROGRAM(
1134             [[
1135               #if HAVE_SYS_SWAP_H && !defined(_LP64) && _FILE_OFFSET_BITS == 64
1136               #  undef _FILE_OFFSET_BITS
1137               #  undef _LARGEFILE64_SOURCE
1138               #endif
1139               #include <sys/stat.h>
1140               #include <sys/param.h>
1141               #include <sys/swap.h>
1142               #include <unistd.h>
1143             ]],
1144             [[int num = swapctl(0, NULL, 0);]]
1145           )
1146         ],
1147         [c_cv_have_swapctl_three_args="yes"],
1148         [c_cv_have_swapctl_three_args="no"]
1149       )
1150     ]
1151   )
1152 fi
1153
1154 # Check for different versions of `swapctl' here..
1155 if test "x$have_swapctl" = "xyes"; then
1156   if test "x$c_cv_have_swapctl_two_args" = "xyes"; then
1157     AC_DEFINE([HAVE_SWAPCTL_TWO_ARGS], [1], [Define if the function swapctl exists and takes two arguments.])
1158   fi
1159
1160   if test "x$c_cv_have_swapctl_three_args" = "xyes"; then
1161     AC_DEFINE([HAVE_SWAPCTL_THREE_ARGS], [1], [Define if the function swapctl exists and takes three arguments.])
1162   fi
1163 fi
1164
1165 # Check for NAN
1166 AC_ARG_WITH([nan-emulation],
1167   [AS_HELP_STRING([--with-nan-emulation], [use emulated NAN. For crosscompiling only.])],
1168   [
1169     if test "x$withval" = "xno"; then
1170       nan_type="none"
1171     else if test "x$withval" = "xyes"; then
1172       nan_type="zero"
1173     else
1174       nan_type="$withval"
1175     fi; fi
1176   ],
1177   [nan_type="none"]
1178 )
1179
1180 if test "x$nan_type" = "xnone"; then
1181   AC_CACHE_CHECK([whether NAN is defined by default],
1182     [c_cv_have_nan_default],
1183     [
1184       AC_COMPILE_IFELSE(
1185         [
1186           AC_LANG_PROGRAM(
1187             [[
1188               #include <stdlib.h>
1189               #include <math.h>
1190               static double foo = NAN;
1191             ]],
1192             [[
1193               if (isnan (foo))
1194                 return 0;
1195               return 1;
1196             ]]
1197           )
1198         ],
1199         [c_cv_have_nan_default="yes"],
1200         [c_cv_have_nan_default="no"]
1201       )
1202     ]
1203   )
1204 fi
1205
1206 if test "x$c_cv_have_nan_default" = "xyes"; then
1207   nan_type="default"
1208 fi
1209
1210 if test "x$nan_type" = "xnone"; then
1211   AC_CACHE_CHECK([whether NAN is defined by __USE_ISOC99],
1212     [c_cv_have_nan_isoc],
1213     [
1214       AC_COMPILE_IFELSE(
1215         [
1216           AC_LANG_PROGRAM(
1217             [[
1218               #include <stdlib.h>
1219               #define __USE_ISOC99 1
1220               #include <math.h>
1221               static double foo = NAN;
1222             ]],
1223             [[
1224               if (isnan (foo))
1225                 return 0;
1226               return 1;
1227             ]]
1228           )
1229         ],
1230         [c_cv_have_nan_isoc="yes"],
1231         [c_cv_have_nan_isoc="no"]
1232       )
1233     ]
1234   )
1235 fi
1236
1237 if test "x$c_cv_have_nan_isoc" = "xyes"; then
1238   nan_type="isoc99"
1239 fi
1240
1241 if test "x$nan_type" = "xnone"; then
1242   SAVE_LDFLAGS="$LDFLAGS"
1243   LDFLAGS="$LDFLAGS -lm"
1244   AC_CACHE_CHECK([whether NAN can be defined by 0/0],
1245     [c_cv_have_nan_zero],
1246     [
1247       AC_RUN_IFELSE(
1248         [
1249           AC_LANG_PROGRAM(
1250             [[
1251               #include <stdlib.h>
1252               #include <math.h>
1253               #ifdef NAN
1254               # undef NAN
1255               #endif
1256               #define NAN (0.0 / 0.0)
1257               #ifndef isnan
1258               # define isnan(f) ((f) != (f))
1259               #endif
1260               static double foo = NAN;
1261             ]],
1262             [[
1263               if (isnan (foo))
1264                 return 0;
1265               return 1;
1266             ]]
1267           )
1268         ],
1269         [c_cv_have_nan_zero="yes"],
1270         [c_cv_have_nan_zero="no"]
1271       )
1272     ]
1273   )
1274   LDFLAGS=$SAVE_LDFLAGS
1275 fi
1276
1277 if test "x$c_cv_have_nan_zero" = "xyes"; then
1278   nan_type="zero"
1279 fi
1280
1281 if test "x$nan_type" = "xdefault"; then
1282   AC_DEFINE([NAN_STATIC_DEFAULT], [1],
1283     [Define if NAN is defined by default and can initialize static variables.]
1284   )
1285 else if test "x$nan_type" = "xisoc99"; then
1286   AC_DEFINE([NAN_STATIC_ISOC], [1],
1287     [Define if NAN is defined by __USE_ISOC99 and can initialize static variables.]
1288   )
1289 else if test "x$nan_type" = "xzero"; then
1290   AC_DEFINE([NAN_ZERO_ZERO], [1],
1291     [Define if NAN can be defined as (0.0 / 0.0)]
1292   )
1293 else
1294   AC_MSG_ERROR([Didn't find out how to statically initialize variables to NAN. Sorry.])
1295 fi; fi; fi
1296
1297 AC_ARG_WITH([fp-layout],
1298   [
1299     AS_HELP_STRING([--with-fp-layout],
1300       [set the memory layout of doubles. For crosscompiling only.]
1301     )
1302   ],
1303   [
1304     if test "x$withval" = "xnothing"; then
1305       fp_layout_type="nothing"
1306     else if test "x$withval" = "xendianflip"; then
1307       fp_layout_type="endianflip"
1308     else if test "x$withval" = "xintswap"; then
1309       fp_layout_type="intswap"
1310     else
1311       AC_MSG_ERROR([Invalid argument for --with-fp-layout. Valid arguments are: nothing, endianflip, intswap]);
1312     fi; fi; fi
1313   ],
1314   [fp_layout_type="unknown"]
1315 )
1316
1317 if test "x$fp_layout_type" = "xunknown"; then
1318   AC_CACHE_CHECK([if doubles are stored in x86 representation],
1319     [c_cv_fp_layout_need_nothing],
1320     [
1321       AC_RUN_IFELSE(
1322         [
1323           AC_LANG_PROGRAM(
1324             [[
1325               #include <stdlib.h>
1326               #include <stdio.h>
1327               #include <string.h>
1328               #include <stdint.h>
1329               #include <inttypes.h>
1330               #include <stdbool.h>
1331             ]],
1332             [[
1333               uint64_t i0;
1334               uint64_t i1;
1335               uint8_t c[8];
1336               double d;
1337
1338               d = 8.642135e130;
1339               memcpy ((void *) &i0, (void *) &d, 8);
1340
1341               i1 = i0;
1342               memcpy ((void *) c, (void *) &i1, 8);
1343
1344               if ((c[0] == 0x2f) && (c[1] == 0x25)
1345                   && (c[2] == 0xc0) && (c[3] == 0xc7)
1346                   && (c[4] == 0x43) && (c[5] == 0x2b)
1347                   && (c[6] == 0x1f) && (c[7] == 0x5b))
1348                 return 0;
1349               return 1;
1350             ]]
1351           )
1352         ],
1353         [c_cv_fp_layout_need_nothing="yes"],
1354         [c_cv_fp_layout_need_nothing="no"]
1355       )
1356     ]
1357   )
1358 fi
1359
1360 if test "x$c_cv_fp_layout_need_nothing" = "xyes"; then
1361   fp_layout_type="nothing"
1362 fi
1363
1364 if test "x$fp_layout_type" = "xunknown"; then
1365   AC_CACHE_CHECK([if endianflip converts to x86 representation],
1366     [c_cv_fp_layout_need_endianflip],
1367     [
1368       AC_RUN_IFELSE(
1369         [
1370           AC_LANG_PROGRAM(
1371             [[
1372               #include <stdlib.h>
1373               #include <stdio.h>
1374               #include <string.h>
1375               #include <stdint.h>
1376               #include <inttypes.h>
1377               #include <stdbool.h>
1378               #define endianflip(A) ((((uint64_t)(A) & 0xff00000000000000LL) >> 56) | \
1379                                      (((uint64_t)(A) & 0x00ff000000000000LL) >> 40) | \
1380                                      (((uint64_t)(A) & 0x0000ff0000000000LL) >> 24) | \
1381                                      (((uint64_t)(A) & 0x000000ff00000000LL) >> 8)  | \
1382                                      (((uint64_t)(A) & 0x00000000ff000000LL) << 8)  | \
1383                                      (((uint64_t)(A) & 0x0000000000ff0000LL) << 24) | \
1384                                      (((uint64_t)(A) & 0x000000000000ff00LL) << 40) | \
1385                                      (((uint64_t)(A) & 0x00000000000000ffLL) << 56))
1386             ]],
1387             [[
1388               uint64_t i0;
1389               uint64_t i1;
1390               uint8_t c[8];
1391               double d;
1392
1393               d = 8.642135e130;
1394               memcpy ((void *) &i0, (void *) &d, 8);
1395
1396               i1 = endianflip (i0);
1397               memcpy ((void *) c, (void *) &i1, 8);
1398
1399               if ((c[0] == 0x2f) && (c[1] == 0x25)
1400                   && (c[2] == 0xc0) && (c[3] == 0xc7)
1401                   && (c[4] == 0x43) && (c[5] == 0x2b)
1402                   && (c[6] == 0x1f) && (c[7] == 0x5b))
1403                 return 0;
1404               return 1;
1405             ]]
1406           )
1407         ],
1408         [c_cv_fp_layout_need_endianflip="yes"],
1409         [c_cv_fp_layout_need_endianflip="no"]
1410       ]
1411     )
1412   )
1413 fi
1414
1415 if test "x$c_cv_fp_layout_need_endianflip" = "xyes"; then
1416   fp_layout_type="endianflip"
1417 fi
1418
1419 if test "x$fp_layout_type" = "xunknown"; then
1420   AC_CACHE_CHECK([if intswap converts to x86 representation],
1421     [c_cv_fp_layout_need_intswap],
1422     [
1423       AC_RUN_IFELSE(
1424         [
1425           AC_LANG_PROGRAM(
1426             [[
1427               #include <stdlib.h>
1428               #include <stdio.h>
1429               #include <string.h>
1430               #include <stdint.h>
1431               #include <inttypes.h>
1432               #include <stdbool.h>
1433               #define intswap(A)    ((((uint64_t)(A) & 0xffffffff00000000LL) >> 32) | \
1434                                      (((uint64_t)(A) & 0x00000000ffffffffLL) << 32))
1435             ]],
1436             [[
1437               uint64_t i0;
1438               uint64_t i1;
1439               uint8_t c[8];
1440               double d;
1441
1442               d = 8.642135e130;
1443               memcpy ((void *) &i0, (void *) &d, 8);
1444
1445               i1 = intswap (i0);
1446               memcpy ((void *) c, (void *) &i1, 8);
1447
1448               if ((c[0] == 0x2f) && (c[1] == 0x25)
1449                   && (c[2] == 0xc0) && (c[3] == 0xc7)
1450                   && (c[4] == 0x43) && (c[5] == 0x2b)
1451                   && (c[6] == 0x1f) && (c[7] == 0x5b))
1452                 return 0;
1453               return 1;
1454             ]]
1455           )
1456         ],
1457         [c_cv_fp_layout_need_intswap="yes"],
1458         [c_cv_fp_layout_need_intswap="no"]
1459       )
1460     ]
1461   )
1462 fi
1463
1464 if test "x$c_cv_fp_layout_need_intswap" = "xyes"; then
1465   fp_layout_type="intswap"
1466 fi
1467
1468 if test "x$fp_layout_type" = "xnothing"; then
1469   AC_DEFINE([FP_LAYOUT_NEED_NOTHING], [1],
1470     [Define if doubles are stored in x86 representation.]
1471   )
1472 else if test "x$fp_layout_type" = "xendianflip"; then
1473   AC_DEFINE([FP_LAYOUT_NEED_ENDIANFLIP], [1],
1474     [Define if endianflip is needed to convert to x86 representation.]
1475   )
1476 else if test "x$fp_layout_type" = "xintswap"; then
1477   AC_DEFINE([FP_LAYOUT_NEED_INTSWAP], [1],
1478     [Define if intswap is needed to convert to x86 representation.]
1479   )
1480 else
1481   AC_MSG_ERROR([Didn't find out how doubles are stored in memory. Sorry.])
1482 fi; fi; fi
1483
1484 # For cpusleep plugin
1485 AC_CACHE_CHECK([whether clock_boottime and clock_monotonic are supported],
1486   [c_cv_have_clock_boottime_monotonic],
1487   [
1488     AC_COMPILE_IFELSE(
1489       [AC_LANG_PROGRAM(
1490         [[#include <time.h>]],
1491         [[
1492           struct timespec b, m;
1493           clock_gettime(CLOCK_BOOTTIME, &b );
1494           clock_gettime(CLOCK_MONOTONIC, &m );
1495         ]]
1496       )
1497       ],
1498       [c_cv_have_clock_boottime_monotonic="yes"],
1499       [c_cv_have_clock_boottime_monotonic="no"]
1500     )
1501   ]
1502 )
1503
1504 # --with-useragent {{{
1505 AC_ARG_WITH([useragent],
1506   [AS_HELP_STRING([--with-useragent@<:@=AGENT@:>@], [User agent to use on http requests])],
1507   [
1508     if test "x$withval" != "xno" && test "x$withval" != "xyes"; then
1509       AC_DEFINE_UNQUOTED([COLLECTD_USERAGENT], ["$withval"], [User agent for http requests])
1510     fi
1511   ]
1512 )
1513
1514 # }}}
1515
1516 # --with-data-max-name-len {{{
1517 AC_ARG_WITH([data-max-name-len],
1518   [AS_HELP_STRING([--with-data-max-name-len@<:@=VALUE@:>@], [Maximum length of data buffers])],
1519   [
1520     if test "x$withval" != "x" && test $withval -gt 0; then
1521       AC_DEFINE_UNQUOTED([DATA_MAX_NAME_LEN], [$withval], [Maximum length of data buffers])
1522     else
1523       AC_MSG_ERROR([DATA_MAX_NAME_LEN must be a positive integer -- $withval given])
1524     fi
1525   ],
1526   [AC_DEFINE([DATA_MAX_NAME_LEN], [128], [Maximum length of data buffers])]
1527 )
1528 # }}}
1529
1530 AC_CHECK_FUNCS([getfsstat], [have_getfsstat="yes"], [have_getfsstat="no"])
1531 AC_CHECK_FUNCS(getvfsstat, [have_getvfsstat="yes"], [have_getvfsstat="no"])
1532 AC_CHECK_FUNCS(listmntent, [have_listmntent="yes"], [have_listmntent="no"])
1533 AC_CHECK_FUNCS(getmntent_r, [have_getmntent_r="yes"], [have_getmntent_r="no"])
1534
1535 AC_CHECK_FUNCS(getmntent, [have_getmntent="libc"], [have_getmntent="no"])
1536 if test "x$have_getmntent" = "xno"; then
1537   AC_CHECK_LIB([sun], [getmntent],
1538     [have_getmntent="sun"],
1539     [have_gemntent="no"]
1540   )
1541 fi
1542
1543 if test "x$have_getmntent" = "xno"; then
1544   AC_CHECK_LIB([seq], [getmntent],
1545     [have_getmntent="seq"],
1546     [have_getmntent="no"]
1547   )
1548 fi
1549
1550 if test "x$have_getmntent" = "xno"; then
1551   AC_CHECK_LIB([gen], [getmntent],
1552     [have_getmntent="gen"],
1553     [have_getmntent="no"]
1554   )
1555 fi
1556
1557 if test "x$have_getmntent" = "xlibc"; then
1558   AC_CACHE_CHECK([whether getmntent takes one argument],
1559     [c_cv_have_one_getmntent],
1560     [
1561       AC_COMPILE_IFELSE(
1562         [
1563           AC_LANG_PROGRAM(
1564             [[#include "$srcdir/src/utils_mount.h"]],
1565             [[
1566               FILE *fh;
1567               struct mntent *me;
1568               fh = setmntent ("/etc/mtab", "r");
1569               me = getmntent (fh);
1570               return(me->mnt_passno);
1571             ]]
1572           )
1573         ],
1574         [c_cv_have_one_getmntent="yes"],
1575         [c_cv_have_one_getmntent="no"]
1576       )
1577     ]
1578   )
1579
1580   AC_CACHE_CHECK([whether getmntent takes two arguments],
1581     [c_cv_have_two_getmntent],
1582     [
1583       AC_COMPILE_IFELSE(
1584         [
1585           AC_LANG_PROGRAM(
1586             [[#include "$srcdir/src/utils_mount.h"]],
1587             [[
1588               FILE *fh;
1589               struct mnttab mt;
1590               int status;
1591               fh = fopen ("/etc/mnttab", "r");
1592               status = getmntent (fh, &mt);
1593               return(status);
1594             ]]
1595           )
1596         ],
1597         [c_cv_have_two_getmntent="yes"],
1598         [c_cv_have_two_getmntent="no"]
1599       )
1600     ]
1601   )
1602 fi
1603
1604 # Check for different versions of `getmntent' here..
1605
1606 if test "x$have_getmntent" = "xlibc"; then
1607   if test "x$c_cv_have_one_getmntent" = "xyes"; then
1608     AC_DEFINE([HAVE_ONE_GETMNTENT], [1],
1609       [Define if the function getmntent exists and takes one argument.]
1610     )
1611   fi
1612
1613   if test "x$c_cv_have_two_getmntent" = "xyes"; then
1614     AC_DEFINE([HAVE_TWO_GETMNTENT], [1],
1615       [Define if the function getmntent exists and takes two arguments.]
1616     )
1617   fi
1618 fi
1619
1620 if test "x$have_getmntent" = "xsun"; then
1621   AC_DEFINE([HAVE_SUN_GETMNTENT], [1],
1622     [Define if the function getmntent exists. It is the version from libsun.]
1623   )
1624 fi
1625
1626 if test "x$have_getmntent" = "xgen"; then
1627   AC_DEFINE([HAVE_GEN_GETMNTENT], [1],
1628     [Define if the function getmntent exists. It is the version from libgen.]
1629   )
1630 fi
1631
1632 # Check for htonll
1633 AC_CACHE_CHECK([whether htonll is defined],
1634   [c_cv_have_htonll],
1635   [
1636     AC_LINK_IFELSE(
1637       [
1638         AC_LANG_PROGRAM(
1639           [[
1640             #include <inttypes.h>
1641             #include <sys/types.h>
1642             #include <netinet/in.h>
1643           ]],
1644           [[return htonll(0);]]
1645         )
1646       ],
1647       [c_cv_have_htonll="yes"],
1648       [c_cv_have_htonll="no"]
1649     )
1650   ]
1651 )
1652
1653 if test "x$c_cv_have_htonll" = "xyes"; then
1654   AC_DEFINE([HAVE_HTONLL], [1], [Define if the function htonll exists.])
1655 fi
1656
1657 # Check for structures
1658 AC_CHECK_MEMBERS([struct if_data.ifi_ibytes, struct if_data.ifi_opackets, struct if_data.ifi_ierrors],
1659   [AC_DEFINE([HAVE_STRUCT_IF_DATA], [1], [Define if struct if_data exists and is usable.])],
1660   [],
1661   [[
1662     #include <sys/types.h>
1663     #include <sys/socket.h>
1664     #include <net/if.h>
1665   ]]
1666 )
1667
1668 AC_CHECK_MEMBERS([struct net_device_stats.rx_bytes, struct net_device_stats.tx_packets, struct net_device_stats.rx_errors],
1669   [AC_DEFINE([HAVE_STRUCT_NET_DEVICE_STATS], [1], [Define if struct net_device_stats exists and is usable.])],
1670   [],
1671   [[
1672     #include <sys/types.h>
1673     #include <sys/socket.h>
1674     #include <linux/if.h>
1675     #include <linux/netdevice.h>
1676   ]]
1677 )
1678
1679 AC_CHECK_MEMBERS([struct inet_diag_req.id, struct inet_diag_req.idiag_states],
1680   [AC_DEFINE([HAVE_STRUCT_LINUX_INET_DIAG_REQ], [1], [Define if struct inet_diag_req exists and is usable.])],
1681   [],
1682   [[#include <linux/inet_diag.h>]]
1683 )
1684
1685 AC_CHECK_MEMBERS([struct ip_mreqn.imr_ifindex], [],
1686   [],
1687   [[
1688     #include <netinet/in.h>
1689     #include <net/if.h>
1690   ]]
1691 )
1692
1693 AC_CHECK_MEMBERS([struct kinfo_proc.ki_pid, struct kinfo_proc.ki_rssize, struct kinfo_proc.ki_rusage],
1694   [
1695     AC_DEFINE([HAVE_STRUCT_KINFO_PROC_FREEBSD], [1], [Define if struct kinfo_proc exists in the FreeBSD variant.])
1696     have_struct_kinfo_proc_freebsd="yes"
1697   ],
1698   [],
1699   [[
1700     #include <kvm.h>
1701     #include <sys/param.h>
1702     #include <sys/sysctl.h>
1703     #include <sys/user.h>
1704   ]]
1705 )
1706
1707 AC_CHECK_MEMBERS([struct kinfo_proc.p_pid, struct kinfo_proc.p_vm_rssize],
1708   [
1709     AC_DEFINE([HAVE_STRUCT_KINFO_PROC_OPENBSD], [1], [Define if struct kinfo_proc exists in the OpenBSD variant.])
1710     have_struct_kinfo_proc_openbsd="yes"
1711   ],
1712   [],
1713   [[
1714     #include <sys/param.h>
1715     #include <sys/sysctl.h>
1716     #include <kvm.h>
1717   ]]
1718 )
1719
1720 AC_CHECK_MEMBERS([struct kinfo_proc2.p_pid, struct kinfo_proc2.p_uru_maxrss],
1721   [
1722     AC_DEFINE([HAVE_STRUCT_KINFO_PROC2_NETBSD], [1], [Define if struct kinfo_proc2 exists in the NetBSD variant.])
1723     have_struct_kinfo_proc2_netbsd="yes"
1724   ],
1725   [],
1726   [[
1727     #include <sys/param.h>
1728     #include <sys/sysctl.h>
1729     #include <kvm.h>
1730   ]]
1731 )
1732
1733 AC_CHECK_MEMBERS([struct udphdr.uh_dport, struct udphdr.uh_sport],
1734   [],
1735   [],
1736   [[
1737     #define _BSD_SOURCE
1738     #define _DEFAULT_SOURCE
1739     #include <stdint.h>
1740     #if HAVE_SYS_TYPES_H
1741     # include <sys/types.h>
1742     #endif
1743     #if HAVE_NETINET_IN_SYSTM_H
1744     # include <netinet/in_systm.h>
1745     #endif
1746     #if HAVE_NETINET_IN_H
1747     # include <netinet/in.h>
1748     #endif
1749     #if HAVE_NETINET_IP_H
1750     # include <netinet/ip.h>
1751     #endif
1752     #if HAVE_NETINET_UDP_H
1753     # include <netinet/udp.h>
1754     #endif
1755   ]]
1756 )
1757
1758 AC_CHECK_MEMBERS([struct udphdr.dest, struct udphdr.source],
1759   [],
1760   [],
1761   [[
1762     #define _BSD_SOURCE
1763     #define _DEFAULT_SOURCE
1764     #include <stdint.h>
1765     #if HAVE_SYS_TYPES_H
1766     # include <sys/types.h>
1767     #endif
1768     #if HAVE_NETINET_IN_SYSTM_H
1769     # include <netinet/in_systm.h>
1770     #endif
1771     #if HAVE_NETINET_IN_H
1772     # include <netinet/in.h>
1773     #endif
1774     #if HAVE_NETINET_IP_H
1775     # include <netinet/ip.h>
1776     #endif
1777     #if HAVE_NETINET_UDP_H
1778     # include <netinet/udp.h>
1779     #endif
1780   ]]
1781 )
1782
1783 AC_CHECK_MEMBERS([kstat_io_t.nwritten, kstat_io_t.writes, kstat_io_t.nwrites, kstat_io_t.wtime],
1784   [],
1785   [],
1786   [[# include <kstat.h>]]
1787 )
1788
1789 # check for pthread_setname_np
1790 SAVE_LDFLAGS="$LDFLAGS"
1791 LDFLAGS="$LDFLAGS -lpthread"
1792
1793 AC_MSG_CHECKING([for pthread_setname_np])
1794 have_pthread_setname_np="no"
1795 AC_LINK_IFELSE(
1796   [
1797     AC_LANG_PROGRAM(
1798       [[
1799         #define _GNU_SOURCE
1800         #include <pthread.h>
1801       ]],
1802       [[pthread_setname_np((pthread_t) {0}, "conftest");]]
1803     )
1804   ],
1805   [
1806     have_pthread_setname_np="yes"
1807     AC_DEFINE(HAVE_PTHREAD_SETNAME_NP, 1, [pthread_setname_np() is available.])
1808   ]
1809 )
1810
1811 AC_MSG_RESULT([$have_pthread_setname_np])
1812
1813 # check for pthread_set_name_np(3) (FreeBSD)
1814 AC_MSG_CHECKING([for pthread_set_name_np])
1815 have_pthread_set_name_np="no"
1816 AC_LINK_IFELSE(
1817   [
1818     AC_LANG_PROGRAM(
1819       [[#include <pthread_np.h>]],
1820       [[pthread_set_name_np((pthread_t) {0}, "conftest");]]
1821     )
1822    ],
1823   [
1824     have_pthread_set_name_np="yes"
1825     AC_DEFINE(HAVE_PTHREAD_SET_NAME_NP, 1, [pthread_set_name_np() is available.])
1826   ]
1827 )
1828 AC_MSG_RESULT([$have_pthread_set_name_np])
1829
1830 LDFLAGS="$SAVE_LDFLAGS"
1831
1832 AC_CHECK_TYPES([struct ip6_ext],
1833   [have_ip6_ext="yes"],
1834   [have_ip6_ext="no"],
1835   [[
1836     #include <stdint.h>
1837     #if HAVE_SYS_TYPES_H
1838     # include <sys/types.h>
1839     #endif
1840     #if HAVE_NETINET_IN_SYSTM_H
1841     # include <netinet/in_systm.h>
1842     #endif
1843     #if HAVE_NETINET_IN_H
1844     # include <netinet/in.h>
1845     #endif
1846     #if HAVE_NETINET_IP6_H
1847     # include <netinet/ip6.h>
1848     #endif
1849   ]]
1850 )
1851
1852 if test "x$have_ip6_ext" = "xno"; then
1853   SAVE_CFLAGS="$CFLAGS"
1854   CFLAGS="$CFLAGS -DSOLARIS2=8"
1855   AC_CHECK_TYPES([struct ip6_ext],
1856     [have_ip6_ext="yes, with -DSOLARIS2=8"],
1857     [have_ip6_ext="no"],
1858     [[
1859       #include <stdint.h>
1860       #if HAVE_SYS_TYPES_H
1861       # include <sys/types.h>
1862       #endif
1863       #if HAVE_NETINET_IN_SYSTM_H
1864       # include <netinet/in_systm.h>
1865       #endif
1866       #if HAVE_NETINET_IN_H
1867       # include <netinet/in.h>
1868       #endif
1869       #if HAVE_NETINET_IP6_H
1870       # include <netinet/ip6.h>
1871       #endif
1872     ]]
1873   )
1874   if test "x$have_ip6_ext" = "xno"; then
1875     CFLAGS="$SAVE_CFLAGS"
1876   fi
1877 fi
1878
1879 # libi2c-dev
1880 if test "x$ac_system" = "xLinux"; then
1881   AC_CHECK_DECL([i2c_smbus_read_i2c_block_data],
1882     [with_libi2c="yes"],
1883     [with_libi2c="no (symbol i2c_smbus_read_i2c_block_data not found - have you installed libi2c-dev ?)"],
1884     [[
1885       #include <stdlib.h>
1886       #include <linux/i2c-dev.h>
1887     ]]
1888   )
1889 else
1890   with_libi2c="no (Linux only)"
1891 fi
1892
1893 #
1894 # Checks for libraries begin here
1895 #
1896
1897 # Check for libpthread
1898 SAVE_LIBS="$LIBS"
1899 AC_CHECK_LIB([pthread],
1900   [pthread_create],
1901   [],
1902   [AC_MSG_ERROR([Symbol 'pthread_create' not found in libpthread])],
1903   []
1904 )
1905 PTHREAD_LIBS="$LIBS"
1906 LIBS="$SAVE_LIBS"
1907 AC_SUBST([PTHREAD_LIBS])
1908
1909 AC_CHECK_HEADERS([pthread.h],
1910   [],
1911   [AC_MSG_ERROR([pthread.h not found])]
1912 )
1913
1914 m4_divert_once([HELP_WITH], [
1915 Collectd additional packages:])
1916
1917 if test "x$ac_system" = "xAIX"; then
1918   with_perfstat="yes"
1919   with_procinfo="yes"
1920 else
1921   with_perfstat="no (AIX only)"
1922   with_procinfo="no (AIX only)"
1923 fi
1924
1925 if test "x$with_perfstat" = "xyes"; then
1926   AC_CHECK_LIB([perfstat], [perfstat_reset],
1927     [with_perfstat="yes"],
1928     [with_perfstat="no (perfstat not found)"]
1929   )
1930 fi
1931
1932 if test "x$with_perfstat" = "xyes"; then
1933   AC_DEFINE([HAVE_PERFSTAT], [1], [Define to 1 if you have the 'perfstat' library (-lperfstat)])
1934   # struct members pertaining to donation have been added to libperfstat somewhere between AIX5.3ML5 and AIX5.3ML9
1935   AC_CHECK_MEMBER([perfstat_partition_type_t.b.donate_enabled],
1936     [],
1937     [],
1938     [[#include <libperfstat.h]]
1939   )
1940   if test "x$av_cv_member_perfstat_partition_type_t_b_donate_enabled" = "xyes"; then
1941     AC_DEFINE([PERFSTAT_SUPPORTS_DONATION], [1], [Define to 1 if your version of the 'perfstat' library supports donation])
1942   fi
1943 fi
1944 AM_CONDITIONAL([BUILD_WITH_PERFSTAT], [test "x$with_perfstat" = "xyes"])
1945
1946 # Processes plugin under AIX.
1947 if test "x$with_procinfo" = "xyes"; then
1948   AC_CHECK_HEADERS([procinfo.h],
1949     [AC_DEFINE([HAVE_PROCINFO_H], [1], [Define to 1 if you have the procinfo.h])],
1950     [with_procinfo="no (procinfo.h not found)"]
1951   )
1952 fi
1953
1954 if test "x$ac_system" = "xSolaris"; then
1955   with_kstat="yes"
1956   with_devinfo="yes"
1957 else
1958   with_kstat="no (Solaris only)"
1959   with_devinfo="no (Solaris only)"
1960 fi
1961
1962 if test "x$with_kstat" = "xyes"; then
1963   AC_CHECK_LIB([kstat], [kstat_open],
1964     [with_kstat="yes"],
1965     [with_kstat="no (libkstat not found)"]
1966   )
1967 fi
1968
1969 if test "x$with_kstat" = "xyes"; then
1970   AC_CHECK_LIB([devinfo], [di_init],
1971     [with_devinfo="yes"],
1972     [with_devinfo="no (not found)"]
1973   )
1974   AC_CHECK_HEADERS([kstat.h],
1975     [AC_DEFINE(HAVE_LIBKSTAT, [1], [Define to 1 if you have the 'kstat' library (-lkstat)])],
1976     [with_kstat="no (kstat.h not found)"]
1977   )
1978 fi
1979
1980 AM_CONDITIONAL([BUILD_WITH_LIBDEVINFO], [test "x$with_devinfo" = "xyes"])
1981 AM_CONDITIONAL([BUILD_WITH_LIBKSTAT], [test "x$with_kstat" = "xyes"])
1982
1983 if test "x$ac_system" = "xDarwin"; then
1984   with_libiokit="yes"
1985 else
1986   with_libiokit="no"
1987 fi
1988 AM_CONDITIONAL([BUILD_WITH_LIBIOKIT], [test "x$with_libiokit" = "xyes"])
1989
1990 with_libkvm="no"
1991 AC_CHECK_LIB([kvm], [kvm_getprocs],
1992   [with_kvm_getprocs="yes"],
1993   [with_kvm_getprocs="no"]
1994 )
1995
1996 if test "x$with_kvm_getprocs" = "xyes"; then
1997   AC_DEFINE([HAVE_LIBKVM_GETPROCS], [1],
1998     [Define to 1 if you have the 'kvm' library with the 'kvm_getprocs' symbol (-lkvm)]
1999   )
2000   with_libkvm="yes"
2001 fi
2002
2003 AM_CONDITIONAL([BUILD_WITH_LIBKVM_GETPROCS], [test "x$with_kvm_getprocs" = "xyes"])
2004
2005 AC_CHECK_LIB([kvm], [kvm_getswapinfo],
2006   [with_kvm_getswapinfo="yes"],
2007   [with_kvm_getswapinfo="no"]
2008 )
2009
2010 if test "x$with_kvm_getswapinfo" = "xyes"; then
2011   AC_DEFINE([HAVE_LIBKVM_GETSWAPINFO], [1],
2012     [Define to 1 if you have the 'kvm' library with the 'kvm_getswapinfo' symbol (-lkvm)]
2013   )
2014   with_libkvm="yes"
2015 fi
2016
2017 AM_CONDITIONAL([BUILD_WITH_LIBKVM_GETSWAPINFO], [test "x$with_kvm_getswapinfo" = "xyes"])
2018
2019 AC_CHECK_LIB([kvm], [kvm_nlist],
2020   [with_kvm_nlist="yes"],
2021   [with_kvm_nlist="no"]
2022 )
2023
2024 if test "x$with_kvm_nlist" = "xyes"; then
2025   AC_CHECK_HEADERS([bsd/nlist.h nlist.h])
2026   AC_DEFINE([HAVE_LIBKVM_NLIST], [1],
2027     [Define to 1 if you have the 'kvm' library with the 'kvm_nlist' symbol (-lkvm)]
2028   )
2029   with_libkvm="yes"
2030 fi
2031
2032 AM_CONDITIONAL([BUILD_WITH_LIBKVM_NLIST], [test "x$with_kvm_nlist" = "xyes"])
2033
2034 AC_CHECK_LIB([kvm], [kvm_openfiles],
2035   [with_kvm_openfiles="yes"],
2036   [with_kvm_openfiles="no"]
2037 )
2038
2039 if test "x$with_kvm_openfiles" = "xyes"; then
2040   AC_DEFINE([HAVE_LIBKVM_NLIST], [1],
2041     [Define to 1 if you have the 'kvm' library with the 'kvm_openfiles' symbol (-lkvm)]
2042   )
2043   with_libkvm="yes"
2044 fi
2045
2046 # --with-libaquaero5 {{{
2047 AC_ARG_WITH([libaquaero5],
2048   [AS_HELP_STRING([--with-libaquaero5@<:@=PREFIX@:>@], [Path to aquatools-ng source code.])],
2049   [
2050     if test "x$withval" = "xyes"; then
2051       with_libaquaero5="yes"
2052     else if test "x$withval" = "xno"; then
2053       with_libaquaero5="no"
2054     else
2055       with_libaquaero5="yes"
2056       LIBAQUAERO5_CFLAGS="$LIBAQUAERO5_CFLAGS -I$withval/src"
2057       LIBAQUAERO5_LDFLAGS="$LIBAQUAERO5_LDFLAGS -L$withval/obj"
2058     fi; fi
2059   ],
2060   [with_libaquaero5="yes"]
2061 )
2062
2063 SAVE_CPPFLAGS="$CPPFLAGS"
2064 SAVE_LDFLAGS="$LDFLAGS"
2065 CPPFLAGS="$CPPFLAGS $LIBAQUAERO5_CFLAGS"
2066 LDFLAGS="$LDFLAGS $LIBAQUAERO5_LDFLAGS"
2067
2068 if test "x$with_libaquaero5" = "xyes"; then
2069   if test "x$LIBAQUAERO5_CFLAGS" != "x"; then
2070     AC_MSG_NOTICE([libaquaero5 CPPFLAGS: $LIBAQUAERO5_CFLAGS])
2071   fi
2072   AC_CHECK_HEADERS([libaquaero5.h],
2073     [with_libaquaero5="yes"],
2074     [with_libaquaero5="no (libaquaero5.h not found)"]
2075   )
2076 fi
2077
2078 if test "x$with_libaquaero5" = "xyes"; then
2079   if test "x$LIBAQUAERO5_LDFLAGS" != "x"; then
2080     AC_MSG_NOTICE([libaquaero5 LDFLAGS: $LIBAQUAERO5_LDFLAGS])
2081   fi
2082   AC_CHECK_LIB([aquaero5], libaquaero5_poll,
2083     [with_libaquaero5="yes"],
2084     [with_libaquaero5="no (symbol 'libaquaero5_poll' not found)"]
2085   )
2086 fi
2087
2088 CPPFLAGS="$SAVE_CPPFLAGS"
2089 LDFLAGS="$SAVE_LDFLAGS"
2090
2091 if test "x$with_libaquaero5" = "xyes"; then
2092   BUILD_WITH_LIBAQUAERO5_CFLAGS="$LIBAQUAERO5_CFLAGS"
2093   BUILD_WITH_LIBAQUAERO5_LDFLAGS="$LIBAQUAERO5_LDFLAGS"
2094 fi
2095 AC_SUBST([BUILD_WITH_LIBAQUAERO5_CFLAGS])
2096 AC_SUBST([BUILD_WITH_LIBAQUAERO5_LDFLAGS])
2097 # }}}
2098
2099 # --with-libhiredis {{{
2100 AC_ARG_WITH([libhiredis],
2101   [AS_HELP_STRING([--with-libhiredis@<:@=PREFIX@:>@], [Path to libhiredis.])],
2102   [
2103     if test "x$withval" = "xyes"; then
2104       with_libhiredis="yes"
2105     else if test "x$withval" = "xno"; then
2106       with_libhiredis="no"
2107     else
2108       with_libhiredis="yes"
2109       LIBHIREDIS_CPPFLAGS="$LIBHIREDIS_CPPFLAGS -I$withval/include"
2110       LIBHIREDIS_LDFLAGS="$LIBHIREDIS_LDFLAGS -L$withval/lib"
2111     fi; fi
2112   ],
2113   [with_libhiredis="yes"]
2114 )
2115
2116 SAVE_CPPFLAGS="$CPPFLAGS"
2117 SAVE_LDFLAGS="$LDFLAGS"
2118 CPPFLAGS="$CPPFLAGS $LIBHIREDIS_CPPFLAGS"
2119 LDFLAGS="$LDFLAGS $LIBHIREDIS_LDFLAGS"
2120
2121 if test "x$with_libhiredis" = "xyes"; then
2122   if test "x$LIBHIREDIS_CPPFLAGS" != "x"; then
2123     AC_MSG_NOTICE([libhiredis CPPFLAGS: $LIBHIREDIS_CPPFLAGS])
2124   fi
2125   AC_CHECK_HEADERS([hiredis/hiredis.h],
2126     [with_libhiredis="yes"],
2127     [with_libhiredis="no (hiredis.h not found)"]
2128   )
2129 fi
2130
2131 if test "x$with_libhiredis" = "xyes"; then
2132   if test "x$LIBHIREDIS_LDFLAGS" != "x"; then
2133     AC_MSG_NOTICE([libhiredis LDFLAGS: $LIBHIREDIS_LDFLAGS])
2134   fi
2135   AC_CHECK_LIB([hiredis], [redisCommand],
2136     [with_libhiredis="yes"],
2137     [with_libhiredis="no (symbol 'redisCommand' not found)"]
2138   )
2139 fi
2140
2141 CPPFLAGS="$SAVE_CPPFLAGS"
2142 LDFLAGS="$SAVE_LDFLAGS"
2143
2144 if test "x$with_libhiredis" = "xyes"; then
2145   BUILD_WITH_LIBHIREDIS_CPPFLAGS="$LIBHIREDIS_CPPFLAGS"
2146   BUILD_WITH_LIBHIREDIS_LDFLAGS="$LIBHIREDIS_LDFLAGS"
2147 fi
2148
2149 AC_SUBST([BUILD_WITH_LIBHIREDIS_CPPFLAGS])
2150 AC_SUBST([BUILD_WITH_LIBHIREDIS_LDFLAGS])
2151 # }}}
2152
2153 # --with-libcurl {{{
2154 with_curl_config="curl-config"
2155 with_curl_cflags=""
2156 with_curl_libs=""
2157 AC_ARG_WITH(libcurl,
2158   [AS_HELP_STRING([--with-libcurl@<:@=PREFIX@:>@], [Path to libcurl.])],
2159   [
2160     if test "x$withval" = "xno"; then
2161       with_libcurl="no"
2162     else if test "x$withval" = "xyes"; then
2163       with_libcurl="yes"
2164     else
2165       if test -f "$withval" && test -x "$withval"; then
2166         with_curl_config="$withval"
2167         with_libcurl="yes"
2168       else if test -x "$withval/bin/curl-config"; then
2169         with_curl_config="$withval/bin/curl-config"
2170         with_libcurl="yes"
2171       fi; fi
2172       with_libcurl="yes"
2173     fi; fi
2174   ],
2175   [with_libcurl="yes"]
2176 )
2177
2178 if test "x$with_libcurl" = "xyes"; then
2179   with_curl_cflags=`$with_curl_config --cflags 2>/dev/null`
2180   curl_config_status=$?
2181
2182   if test $curl_config_status -ne 0; then
2183     with_libcurl="no ($with_curl_config failed)"
2184   else
2185     SAVE_CPPFLAGS="$CPPFLAGS"
2186     CPPFLAGS="$CPPFLAGS $with_curl_cflags"
2187
2188     AC_CHECK_HEADERS([curl/curl.h],
2189       [with_libcurl="yes"],
2190       [with_libcurl="no (curl/curl.h not found)"]
2191     )
2192
2193     CPPFLAGS="$SAVE_CPPFLAGS"
2194   fi
2195 fi
2196
2197 if test "x$with_libcurl" = "xyes"; then
2198   with_curl_libs=`$with_curl_config --libs 2>/dev/null`
2199   curl_config_status=$?
2200
2201   if test $curl_config_status -ne 0; then
2202     with_libcurl="no ($with_curl_config failed)"
2203   else
2204     AC_CHECK_LIB([curl], [curl_easy_init],
2205       [with_libcurl="yes"],
2206       [with_libcurl="no (symbol 'curl_easy_init' not found)"],
2207       [$with_curl_libs]
2208     )
2209
2210     AC_CHECK_DECL([CURLOPT_USERNAME],
2211       [have_curlopt_username="yes"],
2212       [have_curlopt_username="no"],
2213       [[#include <curl/curl.h>]]
2214     )
2215
2216     AC_CHECK_DECL(CURLOPT_TIMEOUT_MS,
2217       [have_curlopt_timeout="yes"],
2218       [have_curlopt_timeout="no"],
2219       [[#include <curl/curl.h>]]
2220     )
2221   fi
2222 fi
2223
2224 if test "x$with_libcurl" = "xyes"; then
2225   SAVE_CPPFLAGS="$CPPFLAGS"
2226   SAVE_LDFLAGS="$LDFLAGS"
2227   CPPFLAGS="$CPPFLAGS $with_curl_cflags"
2228   LDFLAGS="$LDFLAGS $with_curl_libs"
2229   AC_CACHE_CHECK([for CURLINFO_APPCONNECT_TIME],
2230     [c_cv_have_curlinfo_appconnect_time],
2231     [
2232       AC_LINK_IFELSE(
2233         [
2234           AC_LANG_PROGRAM(
2235             [[#include <curl/curl.h>]],
2236             [[
2237               int val = CURLINFO_APPCONNECT_TIME;
2238               return val;
2239             ]]
2240           )
2241         ],
2242         [c_cv_have_curlinfo_appconnect_time="yes"],
2243         [c_cv_have_curlinfo_appconnect_time="no"]
2244       )
2245     ]
2246   )
2247   CPPFLAGS="$SAVE_CPPFLAGS"
2248   LDFLAGS="$SAVE_LDFLAGS"
2249 fi
2250
2251 if test "x$c_cv_have_curlinfo_appconnect_time" = "xyes"; then
2252   AC_DEFINE([HAVE_CURLINFO_APPCONNECT_TIME], [1],
2253     [Define if curl.h defines CURLINFO_APPCONNECT_TIME.]
2254   )
2255 fi
2256
2257 if test "x$with_libcurl" = "xyes"; then
2258   BUILD_WITH_LIBCURL_CFLAGS="$with_curl_cflags"
2259   BUILD_WITH_LIBCURL_LIBS="$with_curl_libs"
2260
2261   if test "x$have_curlopt_username" = "xyes"; then
2262     AC_DEFINE([HAVE_CURLOPT_USERNAME], [1],
2263       [Define if libcurl supports CURLOPT_USERNAME option.]
2264     )
2265   fi
2266
2267   if test "x$have_curlopt_timeout" = "xyes"; then
2268     AC_DEFINE([HAVE_CURLOPT_TIMEOUT_MS], [1],
2269       [Define if libcurl supports CURLOPT_TIMEOUT_MS option.]
2270     )
2271   fi
2272 fi
2273
2274 AC_SUBST(BUILD_WITH_LIBCURL_CFLAGS)
2275 AC_SUBST(BUILD_WITH_LIBCURL_LIBS)
2276 # }}}
2277
2278 # --with-libdbi {{{
2279 AC_ARG_WITH([libdbi],
2280   [AS_HELP_STRING([--with-libdbi@<:@=PREFIX@:>@], [Path to libdbi.])],
2281   [
2282     if test "x$withval" != "xno" && test "x$withval" != "xyes"; then
2283       with_libdbi_cppflags="-I$withval/include"
2284       with_libdbi_ldflags="-L$withval/lib"
2285       with_libdbi="yes"
2286     else
2287       with_libdbi="$withval"
2288     fi
2289   ],
2290   [with_libdbi="yes"]
2291 )
2292
2293 if test "x$with_libdbi" = "xyes"; then
2294   SAVE_CPPFLAGS="$CPPFLAGS"
2295   CPPFLAGS="$CPPFLAGS $with_libdbi_cppflags"
2296
2297   AC_CHECK_HEADERS([dbi/dbi.h],
2298     [with_libdbi="yes"],
2299     [with_libdbi="no (dbi/dbi.h not found)"]
2300   )
2301
2302   CPPFLAGS="$SAVE_CPPFLAGS"
2303 fi
2304
2305 if test "x$with_libdbi" = "xyes"; then
2306   SAVE_LDFLAGS="$LDFLAGS"
2307   LDFLAGS="$LDFLAGS $with_libdbi_ldflags"
2308
2309   AC_CHECK_LIB([dbi], [dbi_initialize],
2310     [with_libdbi="yes"],
2311     [with_libdbi="no (Symbol 'dbi_initialize' not found)"]
2312   )
2313
2314   LDFLAGS="$SAVE_LDFLAGS"
2315 fi
2316
2317 BUILD_WITH_LIBDBI_CPPFLAGS="$with_libdbi_cppflags"
2318 BUILD_WITH_LIBDBI_LDFLAGS="$with_libdbi_ldflags"
2319 BUILD_WITH_LIBDBI_LIBS="-ldbi"
2320 AC_SUBST(BUILD_WITH_LIBDBI_CPPFLAGS)
2321 AC_SUBST(BUILD_WITH_LIBDBI_LDFLAGS)
2322 AC_SUBST(BUILD_WITH_LIBDBI_LIBS)
2323 # }}}
2324
2325 # --with-libdpdk {{{
2326 AC_ARG_VAR([LIBDPDK_CPPFLAGS], [Preprocessor flags for libdpdk])
2327 AC_ARG_VAR([LIBDPDK_CFLAGS], [Compiler flags for libdpdk])
2328 AC_ARG_VAR([LIBDPDK_LDFLAGS], [Linker flags for libdpdk])
2329 AC_ARG_VAR([LIBDPDK_LIBS], [Libraries to link for libdpdk])
2330
2331 AC_ARG_WITH([libdpdk],
2332   [AS_HELP_STRING([--without-libdpdk], [Disable libdpdk.])],
2333   [with_libdpdk="$withval"],
2334   [with_libdpdk="yes"]
2335 )
2336
2337 if test "x$with_libdpdk" != "xno"; then
2338   PKG_CHECK_MODULES([DPDK], [libdpdk], [],
2339     [AC_MSG_NOTICE([no DPDK pkg-config, using defaults])])
2340   if test "x$LIBDPDK_CPPFLAGS" = "x"; then
2341     LIBDPDK_CPPFLAGS="-I/usr/include/dpdk"
2342   fi
2343   if test "x$LIBDPDK_CFLAGS" = "x"; then
2344     LIBDPDK_CFLAGS="$DPDK_CFLAGS"
2345     LIBDPDK_CPPFLAGS="$LIBDPDK_CPPFLAGS $DPDK_CFLAGS"
2346   fi
2347   if test "x$LIBDPDK_LIBS" = "x"; then
2348     if test "x$DPDK_LIBS" != "x"; then
2349       LIBDPDK_LIBS="$DPDK_LIBS"
2350     else
2351       LIBDPDK_LIBS="-ldpdk"
2352     fi
2353   fi
2354   SAVE_CPPFLAGS="$CPPFLAGS"
2355   CPPFLAGS="$LIBDPDK_CPPFLAGS $CPPFLAGS"
2356   SAVE_CFLAGS="$CFLAGS"
2357   CFLAGS="$LIBDPDK_CFLAGS $CFLAGS"
2358   AC_CHECK_HEADERS([rte_config.h],
2359     [
2360       with_libdpdk="yes"
2361       AC_PREPROC_IFELSE(
2362         [
2363           AC_LANG_SOURCE(
2364             [[
2365               #include <rte_version.h>
2366               #if RTE_VERSION < RTE_VERSION_NUM(16,7,0,0)
2367               #error "required DPDK >= 16.07"
2368               #endif
2369             ]]
2370           )
2371         ],
2372         [dpdk_keepalive="yes"],
2373         [dpdk_keepalive="no (DPDK version < 16.07)"]
2374       )
2375     ],
2376     [with_libdpdk="no (rte_config.h not found)"]
2377   )
2378   CPPFLAGS="$SAVE_CPPFLAGS"
2379   CFLAGS="$SAVE_CFLAGS"
2380 fi
2381
2382 if test "x$with_libdpdk" = "xyes"; then
2383   SAVE_LIBS="$LIBS"
2384   LIBS="$LIBDPDK_LIBS $LIBS"
2385   SAVE_LDFLAGS="$LDFLAGS"
2386   LDFLAGS="$LIBDPDK_LDFLAGS $LDFLAGS"
2387   SAVE_CPPFLAGS="$CPPFLAGS"
2388   CPPFLAGS="$LIBDPDK_CPPFLAGS $CPPFLAGS"
2389   SAVE_CFLAGS="$CFLAGS"
2390   CFLAGS="$LIBDPDK_CFLAGS $CFLAGS"
2391   AC_LINK_IFELSE(
2392     [
2393       AC_LANG_PROGRAM(
2394         [[
2395           #include <rte_eal.h>
2396         ]],
2397         [[return rte_eal_init(0, NULL);]]
2398       )
2399     ],
2400     [with_libdpdk="yes"],
2401     [with_libdpdk="no (symbol 'rte_eal_init' not found)"]
2402   )
2403   LIBS="$SAVE_LIBS"
2404   LDFLAGS="$SAVE_LDFLAGS"
2405   CPPFLAGS="$SAVE_CPPFLAGS"
2406   CFLAGS="$SAVE_CFLAGS"
2407 fi
2408
2409 # }}}
2410
2411 # --with-libesmtp {{{
2412 AC_ARG_WITH([libesmtp],
2413   [AS_HELP_STRING([--with-libesmtp@<:@=PREFIX@:>@], [Path to libesmtp.])],
2414   [
2415     if test "x$withval" != "xno" && test "x$withval" != "xyes"; then
2416       with_libesmtp_cppflags="-I$withval/include"
2417       with_libesmtp_ldflags="-L$withval/lib"
2418       with_libesmtp="yes"
2419     else
2420       with_libesmtp="$withval"
2421     fi
2422   ],
2423   [with_libesmtp="yes"]
2424 )
2425
2426 if test "x$with_libesmtp" = "xyes"; then
2427   SAVE_CPPFLAGS="$CPPFLAGS"
2428   CPPFLAGS="$CPPFLAGS $with_libesmtp_cppflags"
2429
2430   AC_CHECK_HEADERS([libesmtp.h],
2431     [with_libesmtp="yes"],
2432     [with_libesmtp="no (libesmtp.h not found)"]
2433   )
2434
2435   CPPFLAGS="$SAVE_CPPFLAGS"
2436 fi
2437
2438 if test "x$with_libesmtp" = "xyes"; then
2439   SAVE_LDFLAGS="$LDFLAGS"
2440   LDFLAGS="$LDFLAGS $with_esmtp_ldflags"
2441
2442   AC_CHECK_LIB([esmtp], [smtp_create_session],
2443     [with_libesmtp="yes"],
2444     [with_libesmtp="no (Symbol 'smtp_create_session' not found)"]
2445   )
2446
2447   LDFLAGS="$SAVE_LDFLAGS"
2448 fi
2449
2450 BUILD_WITH_LIBESMTP_CPPFLAGS="$with_libesmtp_cppflags"
2451 BUILD_WITH_LIBESMTP_LDFLAGS="$with_libesmtp_ldflags"
2452 BUILD_WITH_LIBESMTP_LIBS="-lesmtp"
2453 AC_SUBST(BUILD_WITH_LIBESMTP_CPPFLAGS)
2454 AC_SUBST(BUILD_WITH_LIBESMTP_LDFLAGS)
2455 AC_SUBST(BUILD_WITH_LIBESMTP_LIBS)
2456 # }}}
2457
2458 # --with-libganglia {{{
2459 AC_ARG_WITH([libganglia],
2460   [AS_HELP_STRING([--with-libganglia@<:@=PREFIX@:>@], [Path to libganglia.])],
2461   [
2462     if test -f "$withval" && test -x "$withval"; then
2463       with_libganglia_config="$withval"
2464       with_libganglia="yes"
2465     else if test -f "$withval/bin/ganglia-config" && test -x "$withval/bin/ganglia-config"; then
2466       with_libganglia_config="$withval/bin/ganglia-config"
2467       with_libganglia="yes"
2468     else if test -d "$withval"; then
2469       GANGLIA_CPPFLAGS="-I$withval/include"
2470       GANGLIA_LDFLAGS="-L$withval/lib"
2471       with_libganglia="yes"
2472     else
2473       with_libganglia="$withval"
2474     fi; fi; fi
2475   ],
2476   [with_libganglia="yes"]
2477 )
2478
2479 if test "x$with_libganglia" = "xyes"; then
2480   if test "x$with_libganglia_config" != "x"; then
2481     if test "x$GANGLIA_CPPFLAGS" = "x"; then
2482       GANGLIA_CPPFLAGS=`"$with_libganglia_config" --cflags 2>/dev/null`
2483     fi
2484
2485     if test "x$GANGLIA_LDFLAGS" = "x"; then
2486       GANGLIA_LDFLAGS=`"$with_libganglia_config" --ldflags 2>/dev/null`
2487     fi
2488
2489     if test "x$GANGLIA_LIBS" = "x"; then
2490       GANGLIA_LIBS=`"$with_libganglia_config" --libs 2>/dev/null`
2491     fi
2492   else
2493     GANGLIA_LIBS="-lganglia"
2494   fi
2495 fi
2496
2497 SAVE_CPPFLAGS="$CPPFLAGS"
2498 SAVE_LDFLAGS="$LDFLAGS"
2499 CPPFLAGS="$CPPFLAGS $GANGLIA_CPPFLAGS"
2500 LDFLAGS="$LDFLAGS $GANGLIA_LDFLAGS"
2501
2502 if test "x$with_libganglia" = "xyes"; then
2503   AC_CHECK_HEADERS([gm_protocol.h],
2504     [with_libganglia="yes"],
2505     [with_libganglia="no (gm_protocol.h not found)"]
2506   )
2507 fi
2508
2509 if test "x$with_libganglia" = "xyes"; then
2510   AC_CHECK_LIB([ganglia], [xdr_Ganglia_value_msg],
2511     [with_libganglia="yes"],
2512     [with_libganglia="no (symbol xdr_Ganglia_value_msg not found)"]
2513   )
2514 fi
2515
2516 CPPFLAGS="$SAVE_CPPFLAGS"
2517 LDFLAGS="$SAVE_LDFLAGS"
2518
2519 AC_SUBST(GANGLIA_CPPFLAGS)
2520 AC_SUBST(GANGLIA_LDFLAGS)
2521 AC_SUBST(GANGLIA_LIBS)
2522 # }}}
2523
2524 # --with-libgcrypt {{{
2525 GCRYPT_CPPFLAGS="$GCRYPT_CPPFLAGS"
2526 GCRYPT_LDFLAGS="$GCRYPT_LDFLAGS"
2527 GCRYPT_LIBS="$GCRYPT_LIBS"
2528 AC_ARG_WITH([libgcrypt],
2529   [AS_HELP_STRING([--with-libgcrypt@<:@=PREFIX@:>@], [Path to libgcrypt.])],
2530   [
2531     if test -f "$withval" && test -x "$withval"; then
2532       with_libgcrypt_config="$withval"
2533       with_libgcrypt="yes"
2534     else if test -f "$withval/bin/gcrypt-config" && test -x "$withval/bin/gcrypt-config"; then
2535       with_libgcrypt_config="$withval/bin/gcrypt-config"
2536       with_libgcrypt="yes"
2537     else if test -d "$withval"; then
2538       GCRYPT_CPPFLAGS="$GCRYPT_CPPFLAGS -I$withval/include"
2539       GCRYPT_LDFLAGS="$GCRYPT_LDFLAGS -L$withval/lib"
2540       with_libgcrypt="yes"
2541     else
2542       with_libgcrypt_config="gcrypt-config"
2543       with_libgcrypt="$withval"
2544     fi; fi; fi
2545   ],
2546   [
2547     with_libgcrypt_config="libgcrypt-config"
2548     with_libgcrypt="yes"
2549   ]
2550 )
2551
2552 if test "x$with_libgcrypt" = "xyes" && test "x$with_libgcrypt_config" != "x"; then
2553   if test "x$GCRYPT_CPPFLAGS" = "x"; then
2554     GCRYPT_CPPFLAGS=`"$with_libgcrypt_config" --cflags 2>/dev/null`
2555   fi
2556
2557   if test "x$GCRYPT_LIBS" = "x"; then
2558     GCRYPT_LIBS=`"$with_libgcrypt_config" --libs 2>/dev/null`
2559   fi
2560 fi
2561
2562 SAVE_CPPFLAGS="$CPPFLAGS"
2563 SAVE_LDFLAGS="$LDFLAGS"
2564 SAVE_LIBS="$LIBS"
2565 CPPFLAGS="$CPPFLAGS $GCRYPT_CPPFLAGS"
2566 LDFLAGS="$LDFLAGS $GCRYPT_LDFLAGS"
2567 LIBS="$LIBS $GCRYPT_LIBS"
2568
2569 if test "x$with_libgcrypt" = "xyes"; then
2570   if test "x$GCRYPT_CPPFLAGS" != "x"; then
2571     AC_MSG_NOTICE([gcrypt CPPFLAGS: $GCRYPT_CPPFLAGS])
2572   fi
2573   AC_CHECK_HEADERS([gcrypt.h],
2574     [with_libgcrypt="yes"],
2575     [with_libgcrypt="no (gcrypt.h not found)"]
2576   )
2577 fi
2578
2579 if test "x$with_libgcrypt" = "xyes"; then
2580   AC_CHECK_LIB(gcrypt, gcry_md_hash_buffer,
2581     [with_libgcrypt="yes"],
2582     [with_libgcrypt="no (symbol gcry_md_hash_buffer not found)"]
2583   )
2584 fi
2585
2586 CPPFLAGS="$SAVE_CPPFLAGS"
2587 LDFLAGS="$SAVE_LDFLAGS"
2588 LIBS="$SAVE_LIBS"
2589
2590 AC_SUBST([GCRYPT_CPPFLAGS])
2591 AC_SUBST([GCRYPT_LDFLAGS])
2592 AC_SUBST([GCRYPT_LIBS])
2593 AM_CONDITIONAL([BUILD_WITH_LIBGCRYPT], [test "x$with_libgcrypt" = "xyes"])
2594 # }}}
2595
2596 # --with-libgps {{{
2597 AC_ARG_WITH([libgps],
2598   [AS_HELP_STRING([--with-libgps@<:@=PREFIX@:>@], [Path to libgps.])],
2599   [
2600     if test "x$withval" != "xno" && test "x$withval" != "xyes"; then
2601       with_libgps_cflags="-I$withval/include"
2602       with_libgps_ldflags="-L$withval/lib"
2603       with_libgps="yes"
2604     else
2605       with_libgps="$withval"
2606     fi
2607   ],
2608   [with_libgps="yes"]
2609 )
2610
2611 if test "x$with_libgps" = "xyes"; then
2612   SAVE_CFLAGS="$CFLAGS"
2613   CFLAGS="$CFLAGS $with_libgps_cflags"
2614
2615   AC_CHECK_HEADERS([gps.h],
2616     [with_libgps="yes"],
2617     [with_libgps="no (gps.h not found)"]
2618   )
2619
2620   CFLAGS="$SAVE_CFLAGS"
2621 fi
2622
2623 if test "x$with_libgps" = "xyes"; then
2624   SAVE_LDFLAGS="$LDFLAGS"
2625   LDFLAGS="$LDFLAGS $with_libgps_ldflags"
2626
2627   AC_CHECK_LIB([gps], [gps_open],
2628     [with_libgps="yes"],
2629     [with_libgps="no (symbol gps_open not found)"]
2630   )
2631
2632   LDFLAGS="$SAVE_LDFLAGS"
2633 fi
2634
2635 if test "x$with_libgps" = "xyes"; then
2636   BUILD_WITH_LIBGPS_CFLAGS="$with_libgps_cflags"
2637   BUILD_WITH_LIBGPS_LDFLAGS="$with_libgps_ldflags"
2638   BUILD_WITH_LIBGPS_LIBS="-lgps"
2639 fi
2640
2641 AC_SUBST([BUILD_WITH_LIBGPS_CFLAGS])
2642 AC_SUBST([BUILD_WITH_LIBGPS_LDFLAGS])
2643 AC_SUBST([BUILD_WITH_LIBGPS_LIBS])
2644
2645 # }}}
2646
2647 # --with-libgrpc++ {{{
2648 AC_ARG_WITH([libgrpc++],
2649   [AS_HELP_STRING([--with-libgrpc++@<:@=PREFIX@:>@], [Path to libgrpc++.])],
2650   [
2651     with_grpcpp="$withval"
2652     if test "x$withval" != "xno" && test "x$withval" != "xyes"; then
2653       with_libgrpcpp_cppflags="-I$withval/include"
2654       with_libgrpcpp_ldflags="-L$withval/lib"
2655       with_libgrpcpp="yes"
2656     fi
2657     if test "x$withval" = "xno"; then
2658       with_libgrpcpp="no (disabled on command line)"
2659     fi
2660   ],
2661   [withval="yes"]
2662 )
2663 if test "x$withval" = "xyes"; then
2664 PKG_CHECK_MODULES([GRPCPP], [grpc++],
2665   [with_libgrpcpp="yes"],
2666   [with_libgrpcpp="no (pkg-config could not find libgrpc++)"]
2667 )
2668 fi
2669
2670 if test "x$withval" != "xno"; then
2671   AC_MSG_CHECKING([whether $CXX accepts -std=c++11])
2672   if test_cxx_flags -std=c++11; then
2673     AC_MSG_RESULT([yes])
2674   else
2675     AC_MSG_RESULT([no])
2676     with_libgrpcpp="no (requires C++11 support)"
2677   fi
2678 fi
2679
2680 if test "x$with_libgrpcpp" = "xyes"; then
2681   AC_LANG_PUSH(C++)
2682   SAVE_CPPFLAGS="$CPPFLAGS"
2683   CPPFLAGS="-std=c++11 $with_libgrpcpp_cppflags $GRPCPP_CFLAGS $CPPFLAGS"
2684   AC_CHECK_HEADERS([grpc++/grpc++.h],
2685     [with_libgrpcpp="yes"],
2686     [with_libgrpcpp="no (<grpc++/grpc++.h> not found)"]
2687   )
2688   CPPFLAGS="$SAVE_CPPFLAGS"
2689   AC_LANG_POP(C++)
2690 fi
2691
2692 if test "x$with_libgrpcpp" = "xyes"; then
2693   AC_LANG_PUSH(C++)
2694   SAVE_CPPFLAGS="$CPPFLAGS"
2695   SAVE_LDFLAGS="$LDFLAGS"
2696   SAVE_LIBS="$LIBS"
2697   CPPFLAGS="-std=c++11 $with_libgrpcpp_cppflags $GRPCPP_CFLAGS $CPPFLAGS"
2698   LDFLAGS="$with_libgrpcpp_ldflags"
2699   if test "x$GRPCPP_LIBS" = "x"; then
2700     LIBS="-lgrpc++"
2701   else
2702     LIBS="$GRPCPP_LIBS"
2703   fi
2704   AC_LINK_IFELSE(
2705     [
2706       AC_LANG_PROGRAM(
2707         [[#include <grpc++/grpc++.h>]],
2708         [[grpc::ServerBuilder sb;]]
2709       )
2710     ],
2711     [
2712       with_libgrpcpp="yes"
2713       if test "x$GRPCPP_LIBS" = "x"; then
2714         GRPCPP_LIBS="-lgrpc++"
2715       fi
2716     ],
2717     [with_libgrpcpp="no (libgrpc++ not found)"]
2718   )
2719   CPPFLAGS="$SAVE_CPPFLAGS"
2720   LDFLAGS="$SAVE_LDFLAGS"
2721   LIBS="$SAVE_LIBS"
2722   AC_LANG_POP(C++)
2723 fi
2724
2725 BUILD_WITH_LIBGRPCPP_CPPFLAGS="-std=c++11 $with_libgrpcpp_cppflags $GRPCPP_CFLAGS"
2726 BUILD_WITH_LIBGRPCPP_LDFLAGS="$with_libgrpcpp_ldflags"
2727 BUILD_WITH_LIBGRPCPP_LIBS="$GRPCPP_LIBS"
2728 AC_SUBST([BUILD_WITH_LIBGRPCPP_CPPFLAGS])
2729 AC_SUBST([BUILD_WITH_LIBGRPCPP_LDFLAGS])
2730 AC_SUBST([BUILD_WITH_LIBGRPCPP_LIBS])
2731 # }}}
2732
2733 AC_ARG_VAR([GRPC_CPP_PLUGIN], [path to the grpc_cpp_plugin binary])
2734 AC_PATH_PROG([GRPC_CPP_PLUGIN], [grpc_cpp_plugin])
2735 AM_CONDITIONAL([HAVE_GRPC_CPP], [test "x$GRPC_CPP_PLUGIN" != "x"])
2736
2737 # --with-libiptc {{{
2738 AC_ARG_WITH([libiptc],
2739   [AS_HELP_STRING([--with-libiptc@<:@=PREFIX@:>@], [Path to libiptc.])],
2740   [
2741     if test "x$withval" = "xyes"; then
2742       with_libiptc="pkgconfig"
2743     else if test "x$withval" = "xno"; then
2744       with_libiptc="no"
2745     else
2746       with_libiptc="yes"
2747       with_libiptc_cflags="-I$withval/include"
2748       with_libiptc_libs="-L$withval/lib"
2749     fi; fi
2750   ],
2751   [
2752     if test "x$ac_system" = "xLinux"; then
2753       with_libiptc="pkgconfig"
2754     else
2755       with_libiptc="no (Linux only)"
2756     fi
2757   ]
2758 )
2759
2760 if test "x$with_libiptc" = "xpkgconfig"; then
2761   $PKG_CONFIG --exists 'libiptc' 2>/dev/null
2762   if test $? -ne 0; then
2763     with_libiptc="no (pkg-config doesn't know libiptc)"
2764   fi
2765 fi
2766
2767 if test "x$with_libiptc" = "xpkgconfig"; then
2768   with_libiptc_cflags="`$PKG_CONFIG --cflags 'libiptc'`"
2769   if test $? -ne 0; then
2770     with_libiptc="no ($PKG_CONFIG failed)"
2771   fi
2772
2773   with_libiptc_libs="`$PKG_CONFIG --libs 'libiptc'`"
2774   if test $? -ne 0; then
2775     with_libiptc="no ($PKG_CONFIG failed)"
2776   fi
2777 fi
2778
2779 SAVE_CPPFLAGS="$CPPFLAGS"
2780 CPPFLAGS="$CPPFLAGS $with_libiptc_cflags"
2781
2782 # check whether the header file for libiptc is available.
2783 if test "x$with_libiptc" = "xpkgconfig"; then
2784   AC_CHECK_HEADERS([libiptc/libiptc.h libiptc/libip6tc.h],
2785     [],
2786     [with_libiptc="no (header file missing)"]
2787   )
2788 fi
2789
2790 # If the header file is available, check for the required type declaractions.
2791 # They may be missing in old versions of libiptc. In that case, they will be
2792 # declared in the iptables plugin.
2793 if test "x$with_libiptc" = "xpkgconfig"; then
2794   AC_CHECK_TYPES([iptc_handle_t, ip6tc_handle_t], [], [])
2795 fi
2796
2797 # Check for the iptc_init symbol in the library.
2798 # This could be in iptc or ip4tc
2799 if test "x$with_libiptc" = "xpkgconfig"; then
2800   SAVE_LIBS="$LIBS"
2801   AC_SEARCH_LIBS([iptc_init], [iptc ip4tc],
2802     [with_libiptc="pkgconfig"],
2803     [with_libiptc="no"],
2804     [$with_libiptc_libs]
2805   )
2806   LIBS="$SAVE_LIBS"
2807 fi
2808
2809 if test "x$with_libiptc" = "xpkgconfig"; then
2810   with_libiptc="yes"
2811 fi
2812
2813 CPPFLAGS="$SAVE_CPPFLAGS"
2814
2815 if test "x$with_libiptc" = "xyes"; then
2816   BUILD_WITH_LIBIPTC_CPPFLAGS="$with_libiptc_cflags"
2817   BUILD_WITH_LIBIPTC_LDFLAGS="$with_libiptc_libs"
2818 fi
2819 AC_SUBST([BUILD_WITH_LIBIPTC_CPPFLAGS])
2820 AC_SUBST([BUILD_WITH_LIBIPTC_LDFLAGS])
2821 # }}}
2822
2823 # --with-java {{{
2824 with_java_home="$JAVA_HOME"
2825 if test "x$with_java_home" = "x"; then
2826   with_java_home="/usr/lib/jvm"
2827 fi
2828
2829 JAVAC="$JAVAC"
2830 JAR="$JAR"
2831 AC_ARG_WITH([java],
2832   [AS_HELP_STRING([--with-java@<:@=PREFIX@:>@], [Path to Java home.])],
2833   [
2834     if test "x$withval" = "xno"; then
2835       with_java="no"
2836     else if test "x$withval" = "xyes"; then
2837       with_java="yes"
2838     else
2839       with_java_home="$withval"
2840       with_java="yes"
2841     fi; fi
2842   ],
2843   [with_java="yes"]
2844 )
2845
2846 AX_COMPARE_VERSION([$am__api_version],[lt],[1.12],
2847   [JAVA_TIMESTAMP_FILE="classdist_noinst.stamp"],
2848   [JAVA_TIMESTAMP_FILE="classnoinst.stamp"])
2849 if test "x$with_java" = "xyes"; then
2850   if test -d "$with_java_home"; then
2851     AC_MSG_CHECKING([for jni.h])
2852     TMPVAR=`find -L "$with_java_home" -name jni.h -type f -exec 'dirname' '{}' ';' 2>/dev/null | LC_ALL=C sort | head -n 1`
2853     if test "x$TMPVAR" != "x"; then
2854       AC_MSG_RESULT([found in $TMPVAR])
2855       JAVA_CPPFLAGS="$JAVA_CPPFLAGS -I$TMPVAR"
2856     else
2857       AC_MSG_RESULT([not found])
2858     fi
2859
2860     AC_MSG_CHECKING([for jni_md.h])
2861     TMPVAR=`find -L "$with_java_home" -name jni_md.h -type f -exec 'dirname' '{}' ';' 2>/dev/null | LC_ALL=C sort | head -n 1`
2862     if test "x$TMPVAR" != "x"; then
2863       AC_MSG_RESULT([found in $TMPVAR])
2864       JAVA_CPPFLAGS="$JAVA_CPPFLAGS -I$TMPVAR"
2865     else
2866       AC_MSG_RESULT([not found])
2867     fi
2868
2869     AC_MSG_CHECKING([for libjvm.so])
2870     TMPVAR=`find -L "$with_java_home" -type f \( -name libjvm.so -o -name libjvm.dylib \) -exec 'dirname' '{}' ';' 2>/dev/null | LC_ALL=C sort | head -n 1`
2871     if test "x$TMPVAR" != "x"; then
2872       AC_MSG_RESULT([found in $TMPVAR])
2873       JAVA_LDFLAGS="$JAVA_LDFLAGS -L$TMPVAR -Wl,-rpath -Wl,$TMPVAR"
2874     else
2875       AC_MSG_RESULT([not found])
2876     fi
2877
2878     if test "x$JAVAC" = "x"; then
2879       AC_MSG_CHECKING([for javac])
2880       TMPVAR=`find -L "$with_java_home" -name javac -type f 2>/dev/null | LC_ALL=C sort | head -n 1`
2881       if test "x$TMPVAR" != "x"; then
2882         JAVAC="$TMPVAR"
2883         AC_MSG_RESULT([$JAVAC])
2884       else
2885         AC_MSG_RESULT([not found])
2886       fi
2887     fi
2888
2889     if test "x$JAR" = "x"; then
2890       AC_MSG_CHECKING([for jar])
2891       TMPVAR=`find -L "$with_java_home" -name jar -type f 2>/dev/null | LC_ALL=C sort | head -n 1`
2892       if test "x$TMPVAR" != "x"; then
2893         JAR="$TMPVAR"
2894         AC_MSG_RESULT([$JAR])
2895       else
2896         AC_MSG_RESULT([not found])
2897       fi
2898     fi
2899   else if test "x$with_java_home" != "x"; then
2900     AC_MSG_WARN([JAVA_HOME: No such directory: $with_java_home])
2901   fi; fi
2902 fi
2903
2904 if test "x$JAVA_CPPFLAGS" != "x"; then
2905   AC_MSG_NOTICE([Building with JAVA_CPPFLAGS set to: $JAVA_CPPFLAGS])
2906 fi
2907 if test "x$JAVA_CFLAGS" != "x"; then
2908   AC_MSG_NOTICE([Building with JAVA_CFLAGS set to: $JAVA_CFLAGS])
2909 fi
2910 if test "x$JAVA_LDFLAGS" != "x"; then
2911   AC_MSG_NOTICE([Building with JAVA_LDFLAGS set to: $JAVA_LDFLAGS])
2912 fi
2913 if test "x$JAVA_LIBS" != "x"; then
2914   AC_MSG_NOTICE([Building with JAVA_LIBS set to: $JAVA_LIBS])
2915 fi
2916 if test "x$JAVAC" = "x"; then
2917   with_javac_path="$PATH"
2918   if test "x$with_java_home" != "x"; then
2919     with_javac_path="$with_java_home:with_javac_path"
2920     if test -d "$with_java_home/bin"; then
2921       with_javac_path="$with_java_home/bin:with_javac_path"
2922     fi
2923   fi
2924
2925   AC_PATH_PROG([JAVAC], [javac], [], "$with_javac_path")
2926 fi
2927
2928 if test "x$JAVAC" = "x"; then
2929   with_java="no (javac not found)"
2930 fi
2931
2932 if test "x$JAR" = "x"; then
2933   with_jar_path="$PATH"
2934   if test "x$with_java_home" != "x"; then
2935     with_jar_path="$with_java_home:$with_jar_path"
2936     if test -d "$with_java_home/bin"; then
2937       with_jar_path="$with_java_home/bin:$with_jar_path"
2938     fi
2939   fi
2940
2941   AC_PATH_PROG([JAR], [jar], [], "$with_jar_path")
2942 fi
2943
2944 if test "x$JAR" = "x"; then
2945   with_java="no (jar not found)"
2946 fi
2947
2948 SAVE_CPPFLAGS="$CPPFLAGS"
2949 SAVE_CFLAGS="$CFLAGS"
2950 SAVE_LDFLAGS="$LDFLAGS"
2951 SAVE_LIBS="$LIBS"
2952 CPPFLAGS="$CPPFLAGS $JAVA_CPPFLAGS"
2953 CFLAGS="$CFLAGS $JAVA_CFLAGS"
2954 LDFLAGS="$LDFLAGS $JAVA_LDFLAGS"
2955 LIBS="$LIBS $JAVA_LIBS"
2956
2957 if test "x$with_java" = "xyes"; then
2958   AC_CHECK_HEADERS([jni.h],
2959     [with_jave="yes"],
2960     [with_java="no (jni.h not found)"])
2961 fi
2962
2963 if test "x$with_java" = "xyes"; then
2964   AC_CHECK_LIB([jvm], [JNI_CreateJavaVM],
2965     [with_java="yes"],
2966     [with_java="no (Symbol 'JNI_CreateJavaVM' not found)"],
2967     [$JAVA_LIBS $PTHREAD_LIBS]
2968   )
2969 fi
2970
2971 if test "x$with_java" = "xyes"; then
2972   JAVA_LIBS="$JAVA_LIBS -ljvm"
2973   AC_MSG_NOTICE([Building with JAVA_LIBS set to: $JAVA_LIBS])
2974 fi
2975
2976 CPPFLAGS="$SAVE_CPPFLAGS"
2977 CFLAGS="$SAVE_CFLAGS"
2978 LDFLAGS="$SAVE_LDFLAGS"
2979 LIBS="$SAVE_LIBS"
2980
2981 AC_SUBST([JAVA_CPPFLAGS])
2982 AC_SUBST([JAVA_CFLAGS])
2983 AC_SUBST([JAVA_LDFLAGS])
2984 AC_SUBST([JAVA_LIBS])
2985 AC_SUBST([JAVA_TIMESTAMP_FILE])
2986 AM_CONDITIONAL([BUILD_WITH_JAVA], [test "x$with_java" = "xyes"])
2987 # }}}
2988
2989 # --with-libldap {{{
2990 AC_ARG_WITH([libldap],
2991   [AS_HELP_STRING([--with-libldap@<:@=PREFIX@:>@], [Path to libldap.])],
2992   [
2993     if test "x$withval" = "xyes"; then
2994       with_libldap="yes"
2995     else if test "x$withval" = "xno"; then
2996       with_libldap="no"
2997     else
2998       with_libldap="yes"
2999       LIBLDAP_CPPFLAGS="$LIBLDAP_CPPFLAGS -I$withval/include"
3000       LIBLDAP_LDFLAGS="$LIBLDAP_LDFLAGS -L$withval/lib"
3001     fi; fi
3002   ],
3003   [with_libldap="yes"]
3004 )
3005
3006 SAVE_CPPFLAGS="$CPPFLAGS"
3007 SAVE_LDFLAGS="$LDFLAGS"
3008
3009 CPPFLAGS="$CPPFLAGS $LIBLDAP_CPPFLAGS"
3010 LDFLAGS="$LDFLAGS $LIBLDAP_LDFLAGS"
3011
3012 if test "x$with_libldap" = "xyes"; then
3013   if test "x$LIBLDAP_CPPFLAGS" != "x"; then
3014     AC_MSG_NOTICE([libldap CPPFLAGS: $LIBLDAP_CPPFLAGS])
3015   fi
3016
3017   AC_CHECK_HEADERS([ldap.h],
3018     [with_libldap="yes"],
3019     [with_libldap="no ('ldap.h' not found)"]
3020   )
3021 fi
3022
3023 if test "x$with_libldap" = "xyes"; then
3024   if test "x$LIBLDAP_LDFLAGS" != "x"; then
3025     AC_MSG_NOTICE([libldap LDFLAGS: $LIBLDAP_LDFLAGS])
3026   fi
3027
3028   AC_CHECK_LIB([ldap], [ldap_initialize],
3029     [with_libldap="yes"],
3030     [with_libldap="no (symbol 'ldap_initialize' not found)"]
3031   )
3032 fi
3033
3034 CPPFLAGS="$SAVE_CPPFLAGS"
3035 LDFLAGS="$SAVE_LDFLAGS"
3036
3037 if test "x$with_libldap" = "xyes"
3038 then
3039   BUILD_WITH_LIBLDAP_CPPFLAGS="$LIBLDAP_CPPFLAGS"
3040   BUILD_WITH_LIBLDAP_LDFLAGS="$LIBLDAP_LDFLAGS"
3041 fi
3042 AC_SUBST([BUILD_WITH_LIBLDAP_CPPFLAGS])
3043 AC_SUBST([BUILD_WITH_LIBLDAP_LDFLAGS])
3044 # }}}
3045
3046 # --with-liblua {{{
3047 AC_ARG_VAR([LIBLUA_PKG_CONFIG_NAME], [Name of liblua used by pkg-config])
3048 if test "x$LIBLUA_PKG_CONFIG_NAME" != "x"
3049 then
3050   PKG_CHECK_MODULES([LUA], [$LIBLUA_PKG_CONFIG_NAME],
3051     [with_liblua="yes"],
3052     [with_liblua="no"]
3053   )
3054 else
3055   PKG_CHECK_MODULES([LUA], [lua],
3056     [with_liblua="yes"],
3057     [
3058       PKG_CHECK_MODULES([LUA], [lua-5.3],
3059         [with_liblua="yes"],
3060         [
3061           PKG_CHECK_MODULES([LUA], [lua5.3],
3062             [with_liblua="yes"],
3063             [
3064               PKG_CHECK_MODULES([LUA], [lua-5.2],
3065                 [with_liblua="yes"],
3066                 [
3067                   PKG_CHECK_MODULES([LUA], [lua5.2],
3068                     [with_liblua="yes"],
3069                     [
3070                       PKG_CHECK_MODULES([LUA], [lua-5.1],
3071                         [with_liblua="yes"],
3072                         [
3073                           PKG_CHECK_MODULES([LUA], [lua5.1],
3074                             [with_liblua="yes"],
3075                             [with_liblua="no (pkg-config cannot find liblua)"]
3076                           )
3077                         ]
3078                       )
3079                     ]
3080                   )
3081                 ]
3082               )
3083             ]
3084           )
3085         ]
3086       )
3087     ]
3088   )
3089 fi
3090
3091 if test "x$with_liblua" = "xyes"
3092 then
3093   SAVE_CPPFLAGS="$CPPFLAGS"
3094   CPPFLAGS="$CPPFLAGS $LUA_CFLAGS"
3095
3096   AC_CHECK_HEADERS([lua.h lauxlib.h lualib.h],
3097     [with_liblua="yes"],
3098     [with_liblua="no (header not found)"]
3099   )
3100
3101   CPPFLAGS="$SAVE_CPPFLAGS"
3102 fi
3103
3104 if test "x$with_liblua" = "xyes"
3105 then
3106   SAVE_LIBS="$LIBS"
3107   LIBS="$LIBS $LUA_LIBS"
3108
3109   AC_CHECK_FUNC([lua_settop],
3110     [with_liblua="yes"],
3111     [with_liblua="no (symbol 'lua_settop' not found)"]
3112   )
3113
3114   LIBS="$SAVE_LIBS"
3115 fi
3116
3117 if test "x$with_liblua" = "xyes"
3118 then
3119     BUILD_WITH_LIBLUA_CFLAGS="$LUA_CFLAGS"
3120     BUILD_WITH_LIBLUA_LIBS="$LUA_LIBS"
3121 fi
3122 AC_SUBST(BUILD_WITH_LIBLUA_CFLAGS)
3123 AC_SUBST(BUILD_WITH_LIBLUA_LIBS)
3124 # }}}
3125
3126 # --with-liblvm2app {{{
3127 AC_ARG_WITH([liblvm2app],
3128   [AS_HELP_STRING([--with-liblvm2app@<:@=PREFIX@:>@], [Path to liblvm2app.])],
3129   [
3130     if test "x$withval" = "xno"; then
3131       with_liblvm2app="no"
3132     else
3133       with_liblvm2app="yes"
3134       if test "x$withval" != "xyes"; then
3135         with_liblvm2app_cppflags="-I$withval/include"
3136         with_liblvm2app_ldflags="-L$withval/lib"
3137       fi
3138     fi
3139   ],
3140   [
3141     if test "x$ac_system" = "xLinux"; then
3142       with_liblvm2app="yes"
3143     else
3144       with_liblvm2app="no (Linux only library)"
3145     fi
3146   ]
3147 )
3148
3149 if test "x$with_liblvm2app" = "xyes"; then
3150   SAVE_CPPFLAGS="$CPPFLAGS"
3151   CPPFLAGS="$CPPFLAGS $with_liblvm2app_cppflags"
3152
3153   AC_CHECK_HEADERS([lvm2app.h],
3154     [with_liblvm2app="yes"],
3155     [with_liblvm2app="no (lvm2app.h not found)"]
3156   )
3157
3158   CPPFLAGS="$SAVE_CPPFLAGS"
3159 fi
3160
3161 if test "x$with_liblvm2app" = "xyes"; then
3162   SAVE_CPPFLAGS="$CPPFLAGS"
3163   SAVE_LDFLAGS="$LDFLAGS"
3164   CPPFLAGS="$CPPFLAGS $with_liblvm2app_cppflags"
3165   LDFLAGS="$LDFLAGS $with_liblvm2app_ldflags"
3166
3167   AC_CHECK_LIB([lvm2app], [lvm_lv_get_property],
3168     [with_liblvm2app="yes"],
3169     [with_liblvm2app="no (Symbol 'lvm_lv_get_property' not found)"]
3170   )
3171
3172   CPPFLAGS="$SAVE_CPPFLAGS"
3173   LDFLAGS="$SAVE_LDFLAGS"
3174 fi
3175
3176 if test "x$with_liblvm2app" = "xyes"; then
3177   BUILD_WITH_LIBLVM2APP_CPPFLAGS="$with_liblvm2app_cppflags"
3178   BUILD_WITH_LIBLVM2APP_LDFLAGS="$with_liblvm2app_ldflags"
3179   BUILD_WITH_LIBLVM2APP_LIBS="-llvm2app"
3180 fi
3181
3182 AC_SUBST([BUILD_WITH_LIBLVM2APP_CPPFLAGS])
3183 AC_SUBST([BUILD_WITH_LIBLVM2APP_LDFLAGS])
3184 AC_SUBST([BUILD_WITH_LIBLVM2APP_LIBS])
3185 # }}}
3186
3187 # --with-libmemcached {{{
3188 AC_ARG_WITH([libmemcached],
3189   [AS_HELP_STRING([--with-libmemcached@<:@=PREFIX@:>@], [Path to libmemcached.])],
3190   [
3191     if test "x$withval" != "xno" && test "x$withval" != "xyes"; then
3192       with_libmemcached_cppflags="-I$withval/include"
3193       with_libmemcached_ldflags="-L$withval/lib"
3194       with_libmemcached="yes"
3195     else
3196       with_libmemcached="$withval"
3197     fi
3198   ],
3199   [with_libmemcached="yes"]
3200 )
3201
3202 if test "x$with_libmemcached" = "xyes"; then
3203   SAVE_CPPFLAGS="$CPPFLAGS"
3204   CPPFLAGS="$CPPFLAGS $with_libmemcached_cppflags"
3205
3206   AC_CHECK_HEADERS([libmemcached/memcached.h],
3207     [with_libmemcached="yes"],
3208     [with_libmemcached="no (libmemcached/memcached.h not found)"]
3209   )
3210
3211   CPPFLAGS="$SAVE_CPPFLAGS"
3212 fi
3213
3214 if test "x$with_libmemcached" = "xyes"; then
3215   SAVE_CPPFLAGS="$CPPFLAGS"
3216   SAVE_LDFLAGS="$LDFLAGS"
3217   CPPFLAGS="$CPPFLAGS $with_libmemcached_cppflags"
3218   LDFLAGS="$LDFLAGS $with_libmemcached_ldflags"
3219
3220   AC_CHECK_LIB([memcached], [memcached_create],
3221     [with_libmemcached="yes"],
3222     [with_libmemcached="no (Symbol 'memcached_create' not found)"]
3223   )
3224
3225   CPPFLAGS="$SAVE_CPPFLAGS"
3226   LDFLAGS="$SAVE_LDFLAGS"
3227 fi
3228
3229 if test "x$with_libmemcached" = "xyes"; then
3230   BUILD_WITH_LIBMEMCACHED_CPPFLAGS="$with_libmemcached_cppflags"
3231   BUILD_WITH_LIBMEMCACHED_LDFLAGS="$with_libmemcached_ldflags"
3232   BUILD_WITH_LIBMEMCACHED_LIBS="-lmemcached"
3233 fi
3234
3235 AC_SUBST([BUILD_WITH_LIBMEMCACHED_CPPFLAGS])
3236 AC_SUBST([BUILD_WITH_LIBMEMCACHED_LDFLAGS])
3237 AC_SUBST([BUILD_WITH_LIBMEMCACHED_LIBS])
3238 # }}}
3239
3240 # --with-libmicrohttpd {{{
3241 with_libmicrohttpd_cppflags=""
3242 with_libmicrohttpd_ldflags=""
3243 AC_ARG_WITH([libmicrohttpd], [AS_HELP_STRING([--with-libmicrohttpd@<:@=PREFIX@:>@], [Path to libmicrohttpd.])],
3244   [
3245     if test "x$withval" != "xno" && test "x$withval" != "xyes"; then
3246       with_libmicrohttpd_cppflags="-I$withval/include"
3247       with_libmicrohttpd_ldflags="-L$withval/lib"
3248       with_libmicrohttpd="yes"
3249     fi
3250     if test "x$withval" = "xno"; then
3251       with_libmicrohttpd="no (disabled on command line)"
3252     fi
3253   ],
3254   [withval="yes"]
3255 )
3256 if test "x$withval" = "xyes"; then
3257   PKG_CHECK_MODULES([MICROHTTPD], [libmicrohttpd],
3258     [with_libmicrohttpd="yes"],
3259     [with_libmicrohttpd="no (pkg-config could not find libmicrohttpd)"]
3260   )
3261 fi
3262
3263 if test "x$MICROHTTPD_LIBS" = "x"; then
3264   MICROHTTPD_LIBS="-lmicrohttpd"
3265 fi
3266
3267 SAVE_CPPFLAGS="$CPPFLAGS"
3268 SAVE_LDFLAGS="$LDFLAGS"
3269 SAVE_LIBS="$LIBS"
3270 CPPFLAGS="$with_libmicrohttpd_cppflags $MICROHTTPD_CFLAGS"
3271 LDFLAGS="$with_libmicrohttpd_ldflags $LDFLAGS"
3272 LIBS="$LIBS $MICROHTTPD_LIBS"
3273
3274 if test "x$with_libmicrohttpd" = "xyes"; then
3275   AC_CHECK_HEADERS([microhttpd.h],
3276    [with_libmicrohttpd="yes"],
3277    [with_libmicrohttpd="no (<microhttpd.h> not found)"]
3278   )
3279 fi
3280
3281 if test "x$with_libmicrohttpd" = "xyes"; then
3282   AC_CHECK_LIB([microhttpd], [MHD_start_daemon],
3283     [with_libmicrohttpd="yes"],
3284     [with_libmicrohttpd="no (libmicrohttpd not found)"]
3285   )
3286 fi
3287
3288 CPPFLAGS="$SAVE_CPPFLAGS"
3289 LDFLAGS="$SAVE_LDFLAGS"
3290 LIBS="$SAVE_LIBS"
3291
3292 BUILD_WITH_LIBMICROHTTPD_CPPFLAGS="$with_libmicrohttpd_cppflags $MICROHTTPD_CFLAGS"
3293 BUILD_WITH_LIBMICROHTTPD_LDFLAGS="$with_libmicrohttpd_ldflags"
3294 BUILD_WITH_LIBMICROHTTPD_LIBS="$MICROHTTPD_LIBS"
3295 AC_SUBST([BUILD_WITH_LIBMICROHTTPD_CPPFLAGS])
3296 AC_SUBST([BUILD_WITH_LIBMICROHTTPD_LDFLAGS])
3297 AC_SUBST([BUILD_WITH_LIBMICROHTTPD_LIBS])
3298 # }}}
3299
3300 # --with-libmodbus {{{
3301 AC_ARG_WITH([libmodbus],
3302   [AS_HELP_STRING([--with-libmodbus@<:@=PREFIX@:>@], [Path to the modbus library.])],
3303   [
3304     if test "x$withval" = "xno"; then
3305       with_libmodbus="no"
3306     else if test "x$withval" = "xyes"; then
3307       with_libmodbus="use_pkgconfig"
3308     else if test -d "$with_libmodbus/lib"; then
3309       AC_MSG_NOTICE([Not checking for libmodbus: Manually configured])
3310       with_libmodbus_cflags="-I$withval/include"
3311       with_libmodbus_libs="-L$withval/lib -lmodbus"
3312       with_libmodbus="yes"
3313     fi; fi; fi
3314   ],
3315   [with_libmodbus="use_pkgconfig"]
3316 )
3317
3318 # configure using pkg-config
3319 if test "x$with_libmodbus" = "xuse_pkgconfig"; then
3320   AC_MSG_NOTICE([Checking for libmodbus using $PKG_CONFIG])
3321   $PKG_CONFIG --exists 'libmodbus' 2>/dev/null
3322   if test $? -ne 0; then
3323     with_libmodbus="no (pkg-config doesn't know libmodbus)"
3324   fi
3325 fi
3326
3327 if test "x$with_libmodbus" = "xuse_pkgconfig"; then
3328   with_libmodbus_cflags="`$PKG_CONFIG --cflags 'libmodbus'`"
3329   if test $? -ne 0; then
3330     with_libmodbus="no ($PKG_CONFIG failed)"
3331   fi
3332
3333   with_libmodbus_libs="`$PKG_CONFIG --libs 'libmodbus'`"
3334   if test $? -ne 0; then
3335     with_libmodbus="no ($PKG_CONFIG failed)"
3336   fi
3337 fi
3338
3339 if test "x$with_libmodbus" = "xuse_pkgconfig"; then
3340   with_libmodbus="yes"
3341 fi
3342
3343 if test "x$with_libmodbus" = "xyes"; then
3344   SAVE_CPPFLAGS="$CPPFLAGS"
3345   CPPFLAGS="$CPPFLAGS $with_libmodbus_cflags"
3346
3347   AC_CHECK_HEADERS([modbus.h],
3348     [with_libmodbus="yes"],
3349     [with_libmodbus="no (modbus.h not found)"]
3350   )
3351
3352   CPPFLAGS="$SAVE_CPPFLAGS"
3353 fi
3354
3355 if test "x$with_libmodbus" = "xyes"; then
3356   SAVE_LDFLAGS="$LDFLAGS"
3357   LDFLAGS="$LDFLAGS $with_libmodbus_libs"
3358
3359   AC_CHECK_LIB([modbus], [modbus_connect],
3360     [with_libmodbus="yes"],
3361     [with_libmodbus="no (symbol modbus_connect not found)"]
3362   )
3363
3364   LDFLAGS="$SAVE_LDFLAGS"
3365 fi
3366
3367 if test "x$with_libmodbus" = "xyes"; then
3368   BUILD_WITH_LIBMODBUS_CFLAGS="$with_libmodbus_cflags"
3369   BUILD_WITH_LIBMODBUS_LIBS="$with_libmodbus_libs"
3370 fi
3371
3372 AC_SUBST([BUILD_WITH_LIBMODBUS_CFLAGS])
3373 AC_SUBST([BUILD_WITH_LIBMODBUS_LIBS])
3374 # }}}
3375
3376 # --with-libmongoc {{{
3377 AC_ARG_WITH([libmongoc],
3378   [AS_HELP_STRING([--with-libmongoc@<:@=PREFIX@:>@], [Path to libmongoc.])],
3379   [
3380     if test "x$withval" = "xyes"; then
3381       with_libmongoc="yes"
3382     else if test "x$withval" = "xno"; then
3383       with_libmongoc="no"
3384     else
3385       with_libmongoc="no"
3386     fi; fi
3387   ],
3388   [with_libmongoc="yes"]
3389 )
3390
3391 if test "x$with_libmongoc" = "xyes"; then
3392   PKG_CHECK_MODULES([LIBMONGOC], [libmongoc-1.0],
3393     [with_libmongoc="yes"],
3394     [with_libmongoc="no (pkg-config could not find libmongoc)"]
3395   )
3396 fi
3397
3398 if test "x$with_libmongoc" = "xyes"; then
3399   SAVE_CPPFLAGS="$CPPFLAGS"
3400
3401   CPPFLAGS="$CPPFLAGS $LIBMONGOC_CFLAGS"
3402
3403   if test "x$CPPFLAGS" != "x"; then
3404     AC_MSG_NOTICE([libmongoc CPPFLAGS: $LIBMONGOC_CFLAGS])
3405   fi
3406
3407   AC_CHECK_HEADERS([mongoc.h],
3408     [with_libmongoc="yes"],
3409     [with_libmongoc="no ('mongoc.h' not found)"]
3410   )
3411
3412   CPPFLAGS="$SAVE_CPPFLAGS"
3413 fi
3414
3415 if test "x$with_libmongoc" = "xyes"; then
3416   SAVE_CPPFLAGS="$CPPFLAGS"
3417   SAVE_LDFLAGS="$LDFLAGS"
3418
3419   CPPFLAGS="$CPPFLAGS $LIBMONGOC_CFLAGS"
3420   LDFLAGS="$LDFLAGS $LIBMONGOC_LDFLAGS"
3421
3422   if test "x$LIBMONGOC_LDFLAGS" != "x"; then
3423     AC_MSG_NOTICE([libmongoc LDFLAGS: $LIBMONGOC_LDFLAGS])
3424   fi
3425
3426   AC_CHECK_LIB([mongoc-1.0], [mongoc_init],
3427     [with_libmongoc="yes"],
3428     [with_libmongoc="no (symbol 'mongoc_init' not found)"]
3429   )
3430
3431   CPPFLAGS="$SAVE_CPPFLAGS"
3432   LDFLAGS="$SAVE_LDFLAGS"
3433 fi
3434
3435 if test "x$with_libmongoc" = "xyes"; then
3436   BUILD_WITH_LIBMONGOC_CFLAGS="$LIBMONGOC_CFLAGS"
3437   BUILD_WITH_LIBMONGOC_LDFLAGS="$LIBMONGOC_LDFLAGS"
3438   BUILD_WITH_LIBMONGOC_LIBS="$LIBMONGOC_LIBS"
3439 fi
3440
3441 AC_SUBST([BUILD_WITH_LIBMONGOC_CFLAGS])
3442 AC_SUBST([BUILD_WITH_LIBMONGOC_LDFLAGS])
3443 AC_SUBST([BUILD_WITH_LIBMONGOC_LIBS])
3444 # }}}
3445
3446 # --with-libmosquitto {{{
3447 AC_ARG_WITH([libmosquitto],
3448   [AS_HELP_STRING([--with-libmosquitto@<:@=PREFIX@:>@], [Path to libmosquitto.])],
3449   [
3450     if test "x$withval" != "xno" && test "x$withval" != "xyes"; then
3451       with_libmosquitto_cppflags="-I$withval/include"
3452       with_libmosquitto_ldflags="-L$withval/lib"
3453       with_libmosquitto="yes"
3454     else
3455       with_libmosquitto="$withval"
3456     fi
3457   ],
3458   [with_libmosquitto="yes"]
3459 )
3460
3461 if test "x$with_libmosquitto" = "xyes"; then
3462   SAVE_CPPFLAGS="$CPPFLAGS"
3463   CPPFLAGS="$CPPFLAGS $with_libmosquitto_cppflags"
3464
3465   AC_CHECK_HEADERS([mosquitto.h],
3466     [with_libmosquitto="yes"],
3467     [with_libmosquitto="no (mosquitto.h not found)"]
3468   )
3469
3470   CPPFLAGS="$SAVE_CPPFLAGS"
3471 fi
3472
3473 if test "x$with_libmosquitto" = "xyes"; then
3474   SAVE_LDFLAGS="$LDFLAGS"
3475   LDFLAGS="$LDFLAGS $with_libmosquitto_ldflags"
3476
3477   AC_CHECK_LIB([mosquitto], [mosquitto_connect],
3478     [with_libmosquitto="yes"],
3479     [with_libmosquitto="no (libmosquitto not found)"]
3480   )
3481
3482   LDFLAGS="$SAVE_LDFLAGS"
3483 fi
3484
3485 if test "x$with_libmosquitto" = "xyes"; then
3486   BUILD_WITH_LIBMOSQUITTO_CPPFLAGS="$with_libmosquitto_cppflags"
3487   BUILD_WITH_LIBMOSQUITTO_LDFLAGS="$with_libmosquitto_ldflags"
3488   BUILD_WITH_LIBMOSQUITTO_LIBS="-lmosquitto"
3489 fi
3490
3491 AC_SUBST([BUILD_WITH_LIBMOSQUITTO_CPPFLAGS])
3492 AC_SUBST([BUILD_WITH_LIBMOSQUITTO_LDFLAGS])
3493 AC_SUBST([BUILD_WITH_LIBMOSQUITTO_LIBS])
3494 # }}}
3495
3496 # --with-libmysql {{{
3497 with_mysql_config="mysql_config"
3498 AC_ARG_WITH([libmysql],
3499   [AS_HELP_STRING([--with-libmysql@<:@=PREFIX@:>@], [Path to libmysql.])],
3500   [
3501     if test "x$withval" = "xno"; then
3502       with_libmysql="no"
3503     else if test "x$withval" = "xyes"; then
3504       with_libmysql="yes"
3505     else
3506       if test -f "$withval" && test -x "$withval"; then
3507         with_mysql_config="$withval"
3508       else if test -x "$withval/bin/mysql_config"; then
3509         with_mysql_config="$withval/bin/mysql_config"
3510       fi; fi
3511       with_libmysql="yes"
3512     fi; fi
3513   ],
3514   [with_libmysql="yes"]
3515 )
3516
3517 if test "x$with_libmysql" = "xyes"; then
3518   with_mysql_cflags=`$with_mysql_config --include 2>/dev/null`
3519   if test $? -ne 0; then
3520     with_libmysql="no ($with_mysql_config failed)"
3521   else
3522     SAVE_CPPFLAGS="$CPPFLAGS"
3523     CPPFLAGS="$CPPFLAGS $with_mysql_cflags"
3524
3525     AC_CHECK_HEADERS([mysql.h],
3526       [have_mysql_h="yes"],
3527       [have_mysql_h="no"]
3528     )
3529
3530     if test "x$have_mysql_h" != "xyes"; then
3531       AC_CHECK_HEADERS([mysql/mysql.h],
3532         [have_mysql_mysql_h="yes"],
3533         [],
3534       )
3535     fi
3536
3537     if test "x$have_mysql_h" != "xyes" && test "x$have_mysql_mysql_h" != "xyes"; then
3538       with_libmysql="no (mysql.h not found)"
3539     fi
3540
3541     CPPFLAGS="$SAVE_CPPFLAGS"
3542   fi
3543 fi
3544
3545 if test "x$with_libmysql" = "xyes"; then
3546   with_mysql_libs=`$with_mysql_config --libs_r 2>/dev/null`
3547   if test $? -ne 0; then
3548     with_libmysql="no ($with_mysql_config failed)"
3549   else
3550     SAVE_LIBS="$LIBS"
3551     LIBS="$with_mysql_libs"
3552
3553     AC_SEARCH_LIBS([mysql_get_server_version],
3554       [],
3555       [with_libmysql="yes"],
3556       [with_libmysql="no (symbol 'mysql_get_server_version' not found in ${LIBS})"],
3557       []
3558     )
3559     LIBS="$SAVE_LIBS"
3560   fi
3561 fi
3562
3563 if test "x$with_libmysql" = "xyes"; then
3564   BUILD_WITH_LIBMYSQL_CFLAGS="$with_mysql_cflags"
3565   BUILD_WITH_LIBMYSQL_LIBS="$with_mysql_libs"
3566 fi
3567
3568 AC_SUBST([BUILD_WITH_LIBMYSQL_CFLAGS])
3569 AC_SUBST([BUILD_WITH_LIBMYSQL_LIBS])
3570 # }}}
3571
3572 # --with-libmnl {{{
3573 AC_ARG_WITH([libmnl],
3574   [AS_HELP_STRING([--with-libmnl@<:@=PREFIX@:>@], [Path to libmnl.])],
3575   [
3576     if test "x$withval" = "xyes"; then
3577       with_libmnl="yes"
3578      else if test "x$withval" = "xno"; then
3579        with_libmnl="no"
3580      else
3581        if test -d "$withval/include"; then
3582          with_libmnl_cflags="-I$withval/include"
3583          with_libmnl_libs="-L$withval/lib -lmnl"
3584          with_libmnl="yes"
3585        else
3586          AC_MSG_ERROR("no such directory: $withval/include")
3587        fi
3588      fi; fi
3589   ],
3590   [
3591     if test "x$ac_system" = "xLinux"; then
3592       with_libmnl="yes"
3593     else
3594       with_libmnl="no (Linux only library)"
3595     fi
3596   ]
3597 )
3598
3599 if test "x$with_libmnl" = "xyes"; then
3600   if $PKG_CONFIG --exists libmnl 2>/dev/null; then
3601     with_libmnl_cflags="$with_libmnl_ldflags `$PKG_CONFIG --cflags libmnl`"
3602     with_libmnl_libs="$with_libmnl_libs `$PKG_CONFIG --libs libmnl`"
3603   fi
3604
3605   AC_CHECK_HEADERS([libmnl.h libmnl/libmnl.h],
3606     [
3607       with_libmnl="yes"
3608       break
3609     ],
3610     [],
3611     [[
3612       #include <stdio.h>
3613       #include <sys/types.h>
3614       #include <asm/types.h>
3615       #include <sys/socket.h>
3616       #include <linux/netlink.h>
3617       #include <linux/rtnetlink.h>]]
3618   )
3619
3620   AC_CHECK_HEADERS([linux/gen_stats.h linux/pkt_sched.h],
3621     [],
3622     [],
3623     [[
3624       #include <stdio.h>
3625       #include <sys/types.h>
3626       #include <asm/types.h>
3627       #include <sys/socket.h>
3628     ]]
3629   )
3630
3631   AC_COMPILE_IFELSE(
3632     [
3633       AC_LANG_PROGRAM(
3634         [[
3635           #include <stdio.h>
3636           #include <sys/types.h>
3637           #include <asm/types.h>
3638           #include <sys/socket.h>
3639           #include <linux/netlink.h>
3640           #include <linux/rtnetlink.h>
3641         ]],
3642         [[
3643           int retval = TCA_STATS2;
3644           return retval;
3645         ]]
3646       )
3647     ],
3648     [AC_DEFINE([HAVE_TCA_STATS2], [1], [True if the enum-member TCA_STATS2 exists])]
3649   )
3650
3651   AC_COMPILE_IFELSE(
3652     [
3653       AC_LANG_PROGRAM(
3654         [[
3655           #include <stdio.h>
3656           #include <sys/types.h>
3657           #include <asm/types.h>
3658           #include <sys/socket.h>
3659           #include <linux/netlink.h>
3660           #include <linux/rtnetlink.h>
3661         ]],
3662         [[
3663           int retval = TCA_STATS;
3664           return retval;
3665         ]]
3666       )
3667     ],
3668     [AC_DEFINE([HAVE_TCA_STATS], 1, [True if the enum-member TCA_STATS exists])]
3669   )
3670
3671   AC_CHECK_MEMBERS([struct rtnl_link_stats64.tx_window_errors],
3672     [AC_DEFINE(HAVE_RTNL_LINK_STATS64, 1, [Define if struct rtnl_link_stats64 exists and is usable.])],
3673     [],
3674     [[#include <linux/if_link.h>]]
3675   )
3676
3677   AC_CHECK_LIB([mnl], [mnl_nlmsg_get_payload],
3678     [with_libmnl="yes"],
3679     [with_libmnl="no (symbol 'mnl_nlmsg_get_payload' not found)"],
3680     [$with_libmnl_libs]
3681   )
3682 fi
3683
3684 if test "x$with_libmnl" = "xyes"; then
3685   BUILD_WITH_LIBMNL_CFLAGS="$with_libmnl_cflags"
3686   BUILD_WITH_LIBMNL_LIBS="$with_libmnl_libs"
3687 fi
3688 AC_SUBST([BUILD_WITH_LIBMNL_CFLAGS])
3689 AC_SUBST([BUILD_WITH_LIBMNL_LIBS])
3690 # }}}
3691
3692 # --with-libnetapp {{{
3693 AC_ARG_VAR([LIBNETAPP_CPPFLAGS], [C preprocessor flags required to build with libnetapp])
3694 AC_ARG_VAR([LIBNETAPP_LDFLAGS],  [Linker flags required to build with libnetapp])
3695 AC_ARG_VAR([LIBNETAPP_LIBS],     [Other libraries required to link against libnetapp])
3696 AC_ARG_WITH([libnetapp],
3697   [AS_HELP_STRING([--with-libnetapp@<:@=PREFIX@:>@], [Path to libnetapp.])],
3698   [
3699    if test -d "$withval"; then
3700      LIBNETAPP_CPPFLAGS="$LIBNETAPP_CPPFLAGS -I$withval/include"
3701      LIBNETAPP_LDFLAGS="$LIBNETAPP_LDFLAGS -L$withval/lib"
3702      with_libnetapp="yes"
3703    else
3704      with_libnetapp="$withval"
3705    fi
3706   ],
3707   [with_libnetapp="yes"]
3708 )
3709
3710 SAVE_CPPFLAGS="$CPPFLAGS"
3711 SAVE_LDFLAGS="$LDFLAGS"
3712 CPPFLAGS="$CPPFLAGS $LIBNETAPP_CPPFLAGS"
3713 LDFLAGS="$LDFLAGS $LIBNETAPP_LDFLAGS"
3714
3715 if test "x$with_libnetapp" = "xyes"; then
3716   if test "x$LIBNETAPP_CPPFLAGS" != "x"; then
3717     AC_MSG_NOTICE([netapp CPPFLAGS: $LIBNETAPP_CPPFLAGS])
3718   fi
3719   AC_CHECK_HEADERS([netapp_api.h],
3720     [with_libnetapp="yes"],
3721     [with_libnetapp="no (netapp_api.h not found)"]
3722   )
3723 fi
3724
3725 if test "x$with_libnetapp" = "xyes"; then
3726   if test "x$LIBNETAPP_LDFLAGS" != "x"; then
3727     AC_MSG_NOTICE([netapp LDFLAGS: $LIBNETAPP_LDFLAGS])
3728   fi
3729
3730   if test "x$LIBNETAPP_LIBS" = "x"; then
3731     LIBNETAPP_LIBS="$PTHREAD_LIBS -lxml -ladt -lssl -lm -lcrypto -lz"
3732   fi
3733
3734   AC_MSG_NOTICE([netapp LIBS: $LIBNETAPP_LIBS])
3735
3736   AC_CHECK_LIB([netapp], [na_server_invoke_elem],
3737     [with_libnetapp="yes"],
3738     [with_libnetapp="no (symbol na_server_invoke_elem not found)"],
3739     [$LIBNETAPP_LIBS]
3740   )
3741
3742   LIBNETAPP_LIBS="-lnetapp $LIBNETAPP_LIBS"
3743 fi
3744
3745 CPPFLAGS="$SAVE_CPPFLAGS"
3746 LDFLAGS="$SAVE_LDFLAGS"
3747
3748 AC_SUBST([LIBNETAPP_CPPFLAGS])
3749 AC_SUBST([LIBNETAPP_LDFLAGS])
3750 AC_SUBST([LIBNETAPP_LIBS])
3751 # }}}
3752
3753 # --with-libnetsnmp {{{
3754 AC_ARG_WITH([libnetsnmp],
3755   [AS_HELP_STRING([--with-libnetsnmp@<:@=PREFIX@:>@], [Path to libnetsnmp.])],
3756   [
3757     if test "x$withval" = "xno"; then
3758      with_libnetsnmp="no"
3759     else if test "x$withval" = "xyes"; then
3760      with_libnetsnmp="yes"
3761     else
3762       with_libnetsnmp_cppflags="-I$withval/include"
3763       with_libnetsnmp_ldflags="-I$withval/lib"
3764       with_libnetsnmp="yes"
3765     fi; fi
3766   ],
3767   [with_libnetsnmp="yes"]
3768 )
3769
3770 if test "x$with_libnetsnmp" = "xyes"; then
3771   SAVE_CPPFLAGS="$CPPFLAGS"
3772   CPPFLAGS="$CPPFLAGS $with_libnetsnmp_cppflags"
3773
3774   AC_CHECK_HEADERS([net-snmp/net-snmp-config.h],
3775     [with_libnetsnmp="yes"],
3776     [with_libnetsnmp="no (net-snmp/net-snmp-config.h not found)"]
3777   )
3778
3779   AC_CHECK_HEADERS([net-snmp/net-snmp-includes.h],
3780     [with_libnetsnmp="yes"],
3781     [with_libnetsnmp="no (net-snmp/net-snmp-includes.h not found)"],
3782     [[
3783       #if HAVE_NET_SNMP_NET_SNMP_CONFIG_H
3784       # include <net-snmp/net-snmp-config.h>
3785       #endif
3786     ]]
3787   )
3788
3789   CPPFLAGS="$SAVE_CPPFLAGS"
3790 fi
3791
3792 if test "x$with_libnetsnmp" = "xyes"; then
3793   SAVE_LDFLAGS="$LDFLAGS"
3794   LDFLAGS="$LDFLAGS $with_libnetsnmp_ldflags"
3795
3796   AC_CHECK_LIB([netsnmp], [init_snmp],
3797     [with_libnetsmp="yes"],
3798     [with_libnetsnmp="no (libnetsnmp not found)"]
3799   )
3800
3801   LDFLAGS="$SAVE_LDFLAGS"
3802 fi
3803
3804 if test "x$with_libnetsnmp" = "xyes"; then
3805   BUILD_WITH_LIBNETSNMP_CPPFLAGS="$with_libnetsnmp_cppflags"
3806   BUILD_WITH_LIBNETSNMP_LDFLAGS="$with_libnetsnmp_ldflags"
3807   BUILD_WITH_LIBNETSNMP_LIBS="-lnetsnmp"
3808 fi
3809
3810 AC_SUBST([BUILD_WITH_LIBNETSNMP_CPPFLAGS])
3811 AC_SUBST([BUILD_WITH_LIBNETSNMP_LDFLAGS])
3812 AC_SUBST([BUILD_WITH_LIBNETSNMP_LIBS])
3813 # }}}
3814
3815 # --with-libnetsmpagent {{{
3816 AC_ARG_WITH([libnetsnmpagent],
3817   [AS_HELP_STRING([--with-libnetsnmpagent@<:@=PREFIX@:>@], [Path to libnetsnmpagent.])],
3818   [
3819     if test "x$withval" = "xno"; then
3820       with_libnetsnmpagent="no"
3821     else if test "x$withval" = "xyes"; then
3822       with_libnetsnmpagent="yes"
3823     else
3824       with_libnetsnmpagent_cppflags="-I$withval/include"
3825       with_libnetsnmpagent_ldflags="-I$withval/lib"
3826       with_libnetsnmpagent="yes"
3827     fi; fi
3828   ],
3829   [with_libnetsnmpagent="yes"]
3830 )
3831
3832 if test "x$with_libnetsnmpagent" = "xyes"; then
3833   SAVE_CPPFLAGS="$CPPFLAGS"
3834   CPPFLAGS="$CPPFLAGS $with_libnetsnmpagent_cppflags"
3835
3836   AC_CHECK_HEADERS([net-snmp/agent/net-snmp-agent-includes.h],
3837     [],
3838     [with_libnetsnmpagent="no (net-snmp/agent/net-snmp-agent-includes.h not found)"],
3839     [[
3840       #if HAVE_NET_SNMP_NET_SNMP_CONFIG_H
3841       # include <net-snmp/net-snmp-config.h>
3842       #endif
3843       #if HAVE_NET_SNMP_NET_SNMP_INCLUDES_H
3844       # include <net-snmp/net-snmp-includes.h>
3845       #endif
3846     ]]
3847   )
3848
3849   CPPFLAGS="$SAVE_CPPFLAGS"
3850 fi
3851
3852 if test "x$with_libnetsnmpagent" = "xyes"; then
3853   SAVE_LDFLAGS="$LDFLAGS"
3854   LDFLAGS="$LDFLAGS $with_libnetsnmpagent_ldflags"
3855
3856   # older versions of libnetsnmpagent fail to link
3857   # against the helpers library, so do that explicitly
3858   AC_CHECK_LIB([netsnmphelpers], [netsnmp_init_helpers],
3859     [libnetsnmphelpers="-lnetsnmphelpers"],
3860     [libnetsnmphelpers=""]
3861   )
3862
3863   AC_CHECK_LIB([netsnmpagent], [init_agent],
3864     [with_libnetsnmpagent="yes"],
3865     [with_libnetsnmpagent="no (libnetsnmpagent not found)"],
3866     [$libnetsnmphelpers]
3867   )
3868
3869   LDFLAGS="$SAVE_LDFLAGS"
3870 fi
3871
3872 if test "x$with_libnetsnmpagent" = "xyes"; then
3873   BUILD_WITH_LIBNETSNMPAGENT_LIBS="-lnetsnmpagent $libnetsnmphelpers"
3874 fi
3875
3876 AC_SUBST([BUILD_WITH_LIBNETSNMPAGENT_CPPFLAGS])
3877 AC_SUBST([BUILD_WITH_LIBNETSNMPAGENT_LDFLAGS])
3878 AC_SUBST([BUILD_WITH_LIBNETSNMPAGENT_LIBS])
3879 # }}}
3880
3881 # --with-liboping {{{
3882 AC_ARG_WITH([liboping],
3883   [AS_HELP_STRING([--with-liboping@<:@=PREFIX@:>@], [Path to liboping.])],
3884   [
3885     if test "x$withval" = "xyes"; then
3886       with_liboping="yes"
3887     else if test "x$withval" = "xno"; then
3888       with_liboping="no"
3889     else
3890       with_liboping="yes"
3891       LIBOPING_CPPFLAGS="-I$withval/include"
3892       LIBOPING_LDFLAGS="-L$withval/lib"
3893     fi; fi
3894   ],
3895   [with_liboping="yes"]
3896 )
3897
3898 SAVE_CPPFLAGS="$CPPFLAGS"
3899 SAVE_LDFLAGS="$LDFLAGS"
3900 CPPFLAGS="$CPPFLAGS $LIBOPING_CPPFLAGS"
3901 LDFLAGS="$LDFLAGS $LIBOPING_LDFLAGS"
3902
3903 if test "x$with_liboping" = "xyes"; then
3904   AC_CHECK_HEADERS([oping.h],
3905     [with_liboping="yes"],
3906     [with_liboping="no (oping.h not found)"]
3907   )
3908 fi
3909
3910 if test "x$with_liboping" = "xyes"; then
3911   AC_CHECK_LIB([oping], [ping_construct],
3912     [with_liboping="yes"],
3913     [with_liboping="no (symbol 'ping_construct' not found)"]
3914   )
3915 fi
3916
3917 CPPFLAGS="$SAVE_CPPFLAGS"
3918 LDFLAGS="$SAVE_LDFLAGS"
3919
3920 if test "x$with_liboping" = "xyes"; then
3921   BUILD_WITH_LIBOPING_CPPFLAGS="$LIBOPING_CPPFLAGS"
3922   BUILD_WITH_LIBOPING_LDFLAGS="$LIBOPING_LDFLAGS"
3923 fi
3924
3925 AC_SUBST([BUILD_WITH_LIBOPING_CPPFLAGS])
3926 AC_SUBST([BUILD_WITH_LIBOPING_LDFLAGS])
3927 # }}}
3928
3929 # --with-oracle {{{
3930 AC_ARG_WITH([oracle],
3931   [AS_HELP_STRING([--with-oracle@<:@=ORACLE_HOME@:>@], [Path to Oracle.])],
3932   [
3933     if test "x$withval" = "xyes"; then
3934       if test "x$ORACLE_HOME" = "x"; then
3935         AC_MSG_WARN([Use of the Oracle library has been forced, but the environment variable ORACLE_HOME is not set.])
3936       fi
3937       with_oracle="yes"
3938     else if test "x$withval" = "xno"; then
3939       with_oracle="no"
3940     else
3941       with_oracle="yes"
3942       ORACLE_HOME="$withval"
3943     fi; fi
3944   ],
3945   [
3946     if test "x$ORACLE_HOME" = "x"; then
3947       with_oracle="no (ORACLE_HOME is not set)"
3948     else
3949       with_oracle="yes"
3950     fi
3951   ]
3952 )
3953
3954 if test "x$ORACLE_HOME" != "x"; then
3955   with_oracle_cppflags="-I$ORACLE_HOME/rdbms/public"
3956   if test -e "$ORACLE_HOME/lib/ldflags"; then
3957     with_oracle_libs=`cat "$ORACLE_HOME/lib/ldflags"`
3958   fi
3959   with_oracle_libs="-L$ORACLE_HOME/lib -lclntsh"
3960 fi
3961
3962 if test "x$with_oracle" = "xyes"; then
3963   SAVE_CPPFLAGS="$CPPFLAGS"
3964   CPPFLAGS="$CPPFLAGS $with_oracle_cppflags"
3965
3966   AC_CHECK_HEADERS([oci.h],
3967     [with_oracle="yes"],
3968     [with_oracle="no (oci.h not found)"]
3969   )
3970
3971   CPPFLAGS="$SAVE_CPPFLAGS"
3972 fi
3973
3974 if test "x$with_oracle" = "xyes"; then
3975   SAVE_CPPFLAGS="$CPPFLAGS"
3976   SAVE_LIBS="$LIBS"
3977   CPPFLAGS="$CPPFLAGS $with_oracle_cppflags"
3978   LIBS="$LIBS $with_oracle_libs"
3979
3980   AC_CHECK_FUNC([OCIEnvCreate],
3981     [with_oracle="yes"],
3982     [with_oracle="no (Symbol 'OCIEnvCreate' not found)"]
3983   )
3984
3985   CPPFLAGS="$SAVE_CPPFLAGS"
3986   LIBS="$SAVE_LIBS"
3987 fi
3988
3989 if test "x$with_oracle" = "xyes"; then
3990   BUILD_WITH_ORACLE_CPPFLAGS="$with_oracle_cppflags"
3991   BUILD_WITH_ORACLE_LIBS="$with_oracle_libs"
3992 fi
3993
3994 AC_SUBST([BUILD_WITH_ORACLE_CPPFLAGS])
3995 AC_SUBST([BUILD_WITH_ORACLE_LIBS])
3996 # }}}
3997
3998 # --with-libowcapi {{{
3999 AC_ARG_WITH([libowcapi],
4000   [AS_HELP_STRING([--with-libowcapi@<:@=PREFIX@:>@], [Path to libowcapi.])],
4001   [
4002     if test "x$withval" != "xno" && test "x$withval" != "xyes"; then
4003       with_libowcapi_cppflags="-I$withval/include"
4004       with_libowcapi_ldflags="-L$withval/lib"
4005       with_libowcapi="yes"
4006     else
4007       with_libowcapi="$withval"
4008     fi
4009   ],
4010   [with_libowcapi="yes"]
4011 )
4012
4013 if test "x$with_libowcapi" = "xyes"; then
4014   SAVE_CPPFLAGS="$CPPFLAGS"
4015   CPPFLAGS="$CPPFLAGS $with_libowcapi_cppflags"
4016
4017   AC_CHECK_HEADERS([owcapi.h],
4018     [with_libowcapi="yes"],
4019     [with_libowcapi="no (owcapi.h not found)"]
4020   )
4021
4022   CPPFLAGS="$SAVE_CPPFLAGS"
4023 fi
4024
4025 if test "x$with_libowcapi" = "xyes"; then
4026   SAVE_LDFLAGS="$LDFLAGS"
4027   LDFLAGS="$LDFLAGS $with_libowcapi_ldflags"
4028
4029   AC_CHECK_LIB([owcapi], [OW_get],
4030     [with_libowcapi="yes"],
4031     [with_libowcapi="no (libowcapi not found)"]
4032   )
4033
4034   LDFLAGS="$SAVE_LDFLAGS"
4035 fi
4036
4037 if test "x$with_libowcapi" = "xyes"; then
4038   BUILD_WITH_LIBOWCAPI_CPPFLAGS="$with_libowcapi_cppflags"
4039   BUILD_WITH_LIBOWCAPI_LDFLAGS="$with_libowcapi_ldflags"
4040   BUILD_WITH_LIBOWCAPI_LIBS="-lowcapi"
4041 fi
4042
4043 AC_SUBST([BUILD_WITH_LIBOWCAPI_CPPFLAGS])
4044 AC_SUBST([BUILD_WITH_LIBOWCAPI_LDFLAGS])
4045 AC_SUBST([BUILD_WITH_LIBOWCAPI_LIBS])
4046 # }}}
4047
4048 # --with-libpcap {{{
4049 AC_ARG_WITH([libpcap],
4050   [AS_HELP_STRING([--with-libpcap@<:@=PREFIX@:>@], [Path to libpcap.])],
4051   [
4052     if test "x$withval" != "xno" && test "x$withval" != "xyes"; then
4053       with_libpcap_cppflags="-I$withval/include"
4054       with_libpcap_ldflags="$LDFLAGS -L$withval/lib"
4055       with_libpcap="yes"
4056     else
4057       with_libpcap="$withval"
4058     fi
4059   ],
4060   [with_libpcap="yes"]
4061 )
4062
4063 if test "x$with_libpcap" = "xyes"; then
4064   SAVE_CPPFLAGS="$CPPFLAGS"
4065   CPPFLAGS="$CPPFLAGS $with_libpcap_cppflags"
4066
4067   AC_CHECK_HEADERS([pcap.h],
4068     [with_libpcap="yes"],
4069     [with_libpcap="no (pcap.h not found)"]
4070   )
4071
4072   CPPFLAGS="$SAVE_CPPFLAGS"
4073 fi
4074
4075 if test "x$with_libpcap" = "xyes"; then
4076   SAVE_LDFLAGS="$LDFLAGS"
4077   LDFLAGS="$LDFLAGS $with_libpcap_ldflags"
4078
4079   AC_CHECK_LIB([pcap], [pcap_open_live],
4080     [with_libpcap="yes"],
4081     [with_libpcap="no (libpcap not found)"]
4082   )
4083
4084   LDFLAGS="$SAVE_LDFLAGS"
4085 fi
4086
4087 if test "x$with_libpcap" = "xyes"; then
4088   AC_CACHE_CHECK([whether libpcap has PCAP_ERROR_IFACE_NOT_UP],
4089     [c_cv_libpcap_have_pcap_error_iface_not_up],
4090     [
4091       AC_COMPILE_IFELSE(
4092         [
4093           AC_LANG_PROGRAM(
4094             [[#include <pcap.h>]],
4095             [[
4096               int val = PCAP_ERROR_IFACE_NOT_UP;
4097               return(val);
4098             ]]
4099           )
4100         ],
4101         [c_cv_libpcap_have_pcap_error_iface_not_up="yes"],
4102         [c_cv_libpcap_have_pcap_error_iface_not_up="no"]
4103       )
4104     ]
4105   )
4106 fi
4107
4108 if test "x$c_cv_libpcap_have_pcap_error_iface_not_up" != "xyes"; then
4109   with_libpcap="no (pcap.h misses PCAP_ERROR_IFACE_NOT_UP)"
4110 fi
4111
4112 if test "x$with_libpcap" = "xyes"; then
4113   BUILD_WITH_LIBPCAP_CPPFLAGS="$with_libpcap_cppflags"
4114   BUILD_WITH_LIBPCAP_LDFLAGS="$with_libpcap_ldflags"
4115   BUILD_WITH_LIBPCAP_LIBS="-lpcap"
4116 fi
4117
4118 AC_SUBST([BUILD_WITH_LIBPCAP_CPPFLAGS])
4119 AC_SUBST([BUILD_WITH_LIBPCAP_LDFLAGS])
4120 AC_SUBST([BUILD_WITH_LIBPCAP_LIBS])
4121 # }}}
4122
4123 # --with-libperl {{{
4124 AC_ARG_WITH([libperl],
4125   [AS_HELP_STRING([--with-libperl@<:@=PREFIX@:>@], [Path to libperl.])],
4126   [
4127     if test "x$withval" != "xno" && test "x$withval" != "xyes"; then
4128       LDFLAGS="$LDFLAGS -L$withval/lib"
4129       CPPFLAGS="$CPPFLAGS -I$withval/include"
4130       with_libperl="yes"
4131     else
4132       with_libperl="$withval"
4133     fi
4134   ],
4135   [with_libperl="yes"]
4136 )
4137
4138 AC_ARG_VAR([PERL], [path to Perl interpreter])
4139 AC_PATH_PROG([PERL], [perl])
4140
4141 if test "x$PERL" = "x"; then
4142   with_libperl="no (no Perl interpreter found)"
4143 fi
4144
4145 if test "x$with_libperl" = "xyes"; then
4146   SAVE_CFLAGS="$CFLAGS"
4147   SAVE_LIBS="$LIBS"
4148   dnl ARCHFLAGS="" -> disable multi -arch on OSX (see Config_heavy.pl:fetch_string)
4149   PERL_CFLAGS=`ARCHFLAGS="" $PERL -MExtUtils::Embed -e perl_inc`
4150   PERL_LIBS=`ARCHFLAGS="" $PERL -MExtUtils::Embed -e ldopts`
4151   CFLAGS="$CFLAGS $PERL_CFLAGS"
4152   LIBS="$LIBS $PERL_LIBS"
4153
4154   AC_CACHE_CHECK([for libperl],
4155     [c_cv_have_libperl],
4156     [
4157       AC_LINK_IFELSE(
4158         [
4159           AC_LANG_PROGRAM(
4160             [[