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