java plugin: Add an early prototype of a Java binding, similar to the Perl plugin.
[collectd.git] / configure.in
1 dnl Process this file with autoconf to produce a configure script.
2 AC_INIT(collectd, m4_esyscmd(./version-gen.sh))
3 AC_CONFIG_SRCDIR(src/collectd.c)
4 AC_CONFIG_HEADERS(src/config.h)
5 AM_INIT_AUTOMAKE(dist-bzip2)
6 AC_LANG(C)
7
8 AC_PREFIX_DEFAULT("/opt/collectd")
9
10 AC_SYS_LARGEFILE
11
12 #
13 # Checks for programs.
14 #
15 AC_PROG_CC
16 AC_PROG_CPP
17 AC_PROG_INSTALL
18 AC_PROG_LN_S
19 AC_PROG_MAKE_SET
20 AM_PROG_CC_C_O
21 AM_CONDITIONAL(COMPILER_IS_GCC, test "x$GCC" = "xyes")
22
23 dnl configure libtool
24 AC_DISABLE_STATIC
25 AC_LIBLTDL_CONVENIENCE
26 AC_SUBST(LTDLINCL)
27 AC_SUBST(LIBLTDL)
28 AC_LIBTOOL_DLOPEN
29 AC_PROG_LIBTOOL
30 AC_PROG_LEX
31 AC_PROG_YACC
32 PKG_PROG_PKG_CONFIG
33 AC_CONFIG_SUBDIRS(libltdl)
34
35 AC_MSG_CHECKING([for kernel type ($host_os)])
36 case $host_os in
37         *linux*)
38         AC_DEFINE([KERNEL_LINUX], 1, [True if program is to be compiled for a Linux kernel])
39         ac_system="Linux"
40         ;;
41         *solaris*)
42         AC_DEFINE([KERNEL_SOLARIS], 1, [True if program is to be compiled for a Solaris kernel])
43         ac_system="Solaris"
44         ;;
45         *darwin*)
46         ac_system="Darwin"
47         ;;
48         *openbsd*)
49         ac_system="OpenBSD"
50         ;;
51         *)
52         ac_system="unknown"
53 esac
54 AC_MSG_RESULT([$ac_system])
55
56 if test "x$ac_system" = "xLinux"
57 then
58         AC_ARG_VAR([KERNEL_DIR], [path to Linux kernel sources])
59         if test -z "$KERNEL_DIR"
60         then
61                 KERNEL_DIR="/lib/modules/`uname -r`/source"
62         fi
63
64         KERNEL_CFLAGS="-I$KERNEL_DIR/include"
65         AC_SUBST(KERNEL_CFLAGS)
66 fi
67
68 if test "x$ac_system" = "xSolaris"
69 then
70         CPPFLAGS="$CPPFLAGS -D_POSIX_PTHREAD_SEMANTICS"
71 fi
72
73 # Where to install .pc files.
74 pkgconfigdir="${libdir}/pkgconfig"
75 AC_SUBST(pkgconfigdir)
76
77 #
78 # Checks for header files.
79 #
80 AC_HEADER_STDC
81 AC_HEADER_SYS_WAIT
82 AC_HEADER_DIRENT
83
84 AC_CHECK_HEADERS(stdio.h stdint.h stdbool.h errno.h math.h stdarg.h syslog.h fcntl.h signal.h assert.h sys/types.h sys/socket.h sys/select.h poll.h netdb.h arpa/inet.h sys/resource.h sys/param.h kstat.h regex.h sys/ioctl.h endian.h sys/isa_defs.h)
85
86 # For ping library
87 AC_CHECK_HEADERS(netinet/in_systm.h, [], [],
88 [#if HAVE_STDINT_H
89 # include <stdint.h>
90 #endif
91 #if HAVE_SYS_TYPES_H
92 # include <sys/types.h>
93 #endif
94 ])
95 AC_CHECK_HEADERS(netinet/in.h, [], [],
96 [#if HAVE_STDINT_H
97 # include <stdint.h>
98 #endif
99 #if HAVE_SYS_TYPES_H
100 # include <sys/types.h>
101 #endif
102 #if HAVE_NETINET_IN_SYSTM_H
103 # include <netinet/in_systm.h>
104 #endif
105 ])
106 AC_CHECK_HEADERS(netinet/ip.h, [], [],
107 [#if HAVE_STDINT_H
108 # include <stdint.h>
109 #endif
110 #if HAVE_SYS_TYPES_H
111 # include <sys/types.h>
112 #endif
113 #if HAVE_NETINET_IN_SYSTM_H
114 # include <netinet/in_systm.h>
115 #endif
116 #if HAVE_NETINET_IN_H
117 # include <netinet/in.h>
118 #endif
119 ])
120 AC_CHECK_HEADERS(netinet/ip_icmp.h, [], [],
121 [#if HAVE_STDINT_H
122 # include <stdint.h>
123 #endif
124 #if HAVE_SYS_TYPES_H
125 # include <sys/types.h>
126 #endif
127 #if HAVE_NETINET_IN_SYSTM_H
128 # include <netinet/in_systm.h>
129 #endif
130 #if HAVE_NETINET_IN_H
131 # include <netinet/in.h>
132 #endif
133 #if HAVE_NETINET_IP_H
134 # include <netinet/ip.h>
135 #endif
136 ])
137 AC_CHECK_HEADERS(netinet/ip_var.h, [], [],
138 [#if HAVE_STDINT_H
139 # include <stdint.h>
140 #endif
141 #if HAVE_SYS_TYPES_H
142 # include <sys/types.h>
143 #endif
144 #if HAVE_NETINET_IN_SYSTM_H
145 # include <netinet/in_systm.h>
146 #endif
147 #if HAVE_NETINET_IN_H
148 # include <netinet/in.h>
149 #endif
150 #if HAVE_NETINET_IP_H
151 # include <netinet/ip.h>
152 #endif
153 ])
154 AC_CHECK_HEADERS(netinet/ip6.h, [], [],
155 [#if HAVE_STDINT_H
156 # include <stdint.h>
157 #endif
158 #if HAVE_SYS_TYPES_H
159 # include <sys/types.h>
160 #endif
161 #if HAVE_NETINET_IN_SYSTM_H
162 # include <netinet/in_systm.h>
163 #endif
164 #if HAVE_NETINET_IN_H
165 # include <netinet/in.h>
166 #endif
167 ])
168 AC_CHECK_HEADERS(netinet/icmp6.h, [], [],
169 [#if HAVE_STDINT_H
170 # include <stdint.h>
171 #endif
172 #if HAVE_SYS_TYPES_H
173 # include <sys/types.h>
174 #endif
175 #if HAVE_NETINET_IN_SYSTM_H
176 # include <netinet/in_systm.h>
177 #endif
178 #if HAVE_NETINET_IN_H
179 # include <netinet/in.h>
180 #endif
181 #if HAVE_NETINET_IP6_H
182 # include <netinet/ip6.h>
183 #endif
184 ])
185 AC_CHECK_HEADERS(netinet/tcp.h, [], [],
186 [#if HAVE_STDINT_H
187 # include <stdint.h>
188 #endif
189 #if HAVE_SYS_TYPES_H
190 # include <sys/types.h>
191 #endif
192 #if HAVE_NETINET_IN_SYSTM_H
193 # include <netinet/in_systm.h>
194 #endif
195 #if HAVE_NETINET_IN_H
196 # include <netinet/in.h>
197 #endif
198 #if HAVE_NETINET_IP_H
199 # include <netinet/ip.h>
200 #endif
201 ])
202 AC_CHECK_HEADERS(netinet/udp.h, [], [],
203 [#if HAVE_STDINT_H
204 # include <stdint.h>
205 #endif
206 #if HAVE_SYS_TYPES_H
207 # include <sys/types.h>
208 #endif
209 #if HAVE_NETINET_IN_SYSTM_H
210 # include <netinet/in_systm.h>
211 #endif
212 #if HAVE_NETINET_IN_H
213 # include <netinet/in.h>
214 #endif
215 #if HAVE_NETINET_IP_H
216 # include <netinet/ip.h>
217 #endif
218 ])
219
220 # For cpu modules
221 AC_CHECK_HEADERS(sys/dkstat.h)
222 if test "x$ac_system" = "xDarwin"
223 then
224         AC_CHECK_HEADERS(mach/mach_init.h mach/host_priv.h mach/mach_error.h mach/mach_host.h mach/mach_port.h mach/mach_types.h mach/message.h mach/processor_set.h mach/processor.h mach/processor_info.h mach/task.h mach/thread_act.h mach/vm_region.h mach/vm_map.h mach/vm_prot.h mach/vm_statistics.h mach/kern_return.h)
225         AC_CHECK_HEADERS(CoreFoundation/CoreFoundation.h IOKit/IOKitLib.h IOKit/IOTypes.h IOKit/ps/IOPSKeys.h IOKit/IOBSD.h IOKit/storage/IOBlockStorageDriver.h)
226 fi
227 AC_CHECK_HEADERS(sys/sysctl.h, [], [],
228 [
229 #if HAVE_SYS_TYPES_H
230 #  include <sys/types.h>
231 #endif
232 #if HAVE_SYS_PARAM_H
233 # include <sys/param.h>
234 #endif
235 ])
236
237 # For hddtemp module
238 AC_CHECK_HEADERS(linux/major.h libgen.h)
239
240 # For the battery plugin
241 AC_CHECK_HEADERS(IOKit/ps/IOPowerSources.h, [], [],
242 [
243 #if HAVE_IOKIT_IOKITLIB_H
244 #  include <IOKit/IOKitLib.h>
245 #endif
246 #if HAVE_IOKIT_IOTYPES_H
247 #  include <IOKit/IOTypes.h>
248 #endif
249 ])
250
251 # For the swap module
252 have_sys_swap_h="yes"
253 AC_CHECK_HEADERS(sys/swap.h, [], [have_sys_swap_h="no"],
254 [
255 #if HAVE_SYS_TYPES_H
256 #  include <sys/types.h>
257 #endif
258 #if HAVE_SYS_PARAM_H
259 # include <sys/param.h>
260 #endif
261 ])
262
263 if test "x$have_sys_swap_h$ac_system" = "xnoSolaris"
264 then
265         AC_MSG_NOTICE([Solaris detected and sys/swap.h not found: Try building a 64bit binary.])
266 fi
267
268 # For load module
269 # For the processes plugin
270 # For users module
271 AC_CHECK_HEADERS(sys/loadavg.h linux/config.h utmp.h utmpx.h)
272
273 # For interface plugin
274 AC_CHECK_HEADERS(ifaddrs.h)
275 AC_CHECK_HEADERS(net/if.h, [], [],
276 [
277 #if HAVE_SYS_TYPES_H
278 #  include <sys/types.h>
279 #endif
280 #if HAVE_SYS_SOCKET_H
281 #  include <sys/socket.h>
282 #endif
283 ])
284 AC_CHECK_HEADERS(linux/if.h, [], [],
285 [
286 #if HAVE_SYS_TYPES_H
287 #  include <sys/types.h>
288 #endif
289 #if HAVE_SYS_SOCKET_H
290 #  include <sys/socket.h>
291 #endif
292 ])
293 AC_CHECK_HEADERS(linux/netdevice.h, [], [],
294 [
295 #if HAVE_SYS_TYPES_H
296 #  include <sys/types.h>
297 #endif
298 #if HAVE_SYS_SOCKET_H
299 #  include <sys/socket.h>
300 #endif
301 #if HAVE_LINUX_IF_H
302 # include <linux/if.h>
303 #endif
304 ])
305
306 # For ipvs module
307 have_net_ip_vs_h="no"
308 have_ip_vs_h="no"
309 if test "x$ac_system" = "xLinux"
310 then
311         SAVE_CFLAGS=$CFLAGS
312         CFLAGS="$CFLAGS $KERNEL_CFLAGS"
313
314         AC_CHECK_HEADERS(net/ip_vs.h, [have_net_ip_vs_h="yes"])
315         AC_CHECK_HEADERS(ip_vs.h, [have_ip_vs_h="yes"])
316
317         CFLAGS=$SAVE_CFLAGS
318 fi
319
320 # For quota module
321 AC_CHECK_HEADERS(sys/ucred.h, [], [],
322 [
323 #if HAVE_SYS_TYPES_H
324 #  include <sys/types.h>
325 #endif
326 #if HAVE_SYS_PARAM_H
327 # include <sys/param.h>
328 #endif
329 ])
330
331 # For mount interface
332 AC_CHECK_HEADERS(sys/mount.h, [], [],
333 [
334 #if HAVE_SYS_TYPES_H
335 #  include <sys/types.h>
336 #endif
337 #if HAVE_SYS_PARAM_H
338 # include <sys/param.h>
339 #endif
340 ])
341
342 # For the email plugin
343 AC_CHECK_HEADERS(linux/un.h, [], [],
344 [
345 #if HAVE_SYS_SOCKET_H
346 #       include <sys/socket.h>
347 #endif
348 ])
349
350 AC_CHECK_HEADERS(pwd.h grp.h sys/un.h ctype.h limits.h sys/quota.h xfs/xqm.h fs_info.h fshelp.h paths.h mntent.h mnttab.h sys/fstyp.h sys/fs_types.h sys/mntent.h sys/mnttab.h sys/statfs.h sys/statvfs.h sys/vfs.h sys/vfstab.h kvm.h wordexp.h)
351
352 # For the dns plugin
353 AC_CHECK_HEADERS(arpa/nameser.h)
354 AC_CHECK_HEADERS(arpa/nameser_compat.h, [], [],
355 [
356 #if HAVE_ARPA_NAMESER_H
357 # include <arpa/nameser.h>
358 #endif
359 ])
360
361 AC_CHECK_HEADERS(net/if_arp.h, [], [],
362 [#if HAVE_SYS_SOCKET_H
363 # include <sys/socket.h>
364 #endif
365 ])
366 AC_CHECK_HEADERS(net/ppp_defs.h)
367 AC_CHECK_HEADERS(net/if_ppp.h, [], [],
368 [#if HAVE_NET_PPP_DEFS_H
369 # include <net/ppp_defs.h>
370 #endif
371 ])
372 AC_CHECK_HEADERS(netinet/if_ether.h, [], [],
373 [#if HAVE_STDINT_H
374 # include <stdint.h>
375 #endif
376 #if HAVE_SYS_TYPES_H
377 # include <sys/types.h>
378 #endif
379 #if HAVE_SYS_SOCKET_H
380 # include <sys/socket.h>
381 #endif
382 #if HAVE_NET_IF_H
383 # include <net/if.h>
384 #endif
385 #if HAVE_NETINET_IN_H
386 # include <netinet/in.h>
387 #endif
388 ])
389
390 # For the multimeter plugin
391 have_termios_h="no"
392 AC_CHECK_HEADERS(termios.h, [have_termios_h="yes"])
393
394 #
395 # Checks for typedefs, structures, and compiler characteristics.
396 #
397 AC_C_CONST
398 AC_TYPE_PID_T
399 AC_TYPE_SIZE_T
400 AC_TYPE_UID_T
401 AC_HEADER_TIME
402
403 #
404 # Checks for library functions.
405 #
406 AC_PROG_GCC_TRADITIONAL
407 AC_CHECK_FUNCS(gettimeofday select strdup strtol getaddrinfo getnameinfo strchr memcpy strstr strcmp strncmp strncpy strlen strncasecmp strcasecmp openlog closelog sysconf)
408
409 AC_FUNC_STRERROR_R
410
411 AC_CACHE_CHECK([for strtok_r],
412   [have_strtok_r_default],
413   AC_LINK_IFELSE(
414     AC_LANG_PROGRAM(
415     [[[[
416 #include <stdlib.h>
417 #include <stdio.h>
418 #include <string.h>
419     ]]]],
420     [[[[
421       char buffer[] = "foo,bar,baz";
422       char *token;
423       char *dummy;
424       char *saveptr;
425
426       dummy = buffer;
427       saveptr = NULL;
428       while ((token = strtok_r (dummy, ",", &saveptr)) != NULL)
429       {
430         dummy = NULL;
431         printf ("token = %s;\n", token);
432       }
433     ]]]]),
434     [have_strtok_r_default="yes"],
435     [have_strtok_r_default="no"]
436   )
437 )
438
439 if test "x$have_strtok_r_default" = "xno"
440 then
441   SAVE_CFLAGS="$CFLAGS"
442   CFLAGS="$CFLAGS -D_REENTRANT=1"
443
444   AC_CACHE_CHECK([if strtok_r needs _REENTRANT],
445     [have_strtok_r_reentrant],
446     AC_LINK_IFELSE(
447       AC_LANG_PROGRAM(
448       [[[[
449 #include <stdlib.h>
450 #include <stdio.h>
451 #include <string.h>
452       ]]]],
453       [[[[
454         char buffer[] = "foo,bar,baz";
455         char *token;
456         char *dummy;
457         char *saveptr;
458
459         dummy = buffer;
460         saveptr = NULL;
461         while ((token = strtok_r (dummy, ",", &saveptr)) != NULL)
462         {
463           dummy = NULL;
464           printf ("token = %s;\n", token);
465         }
466       ]]]]),
467       [have_strtok_r_reentrant="yes"],
468       [AC_MSG_FAILURE([strtok_r isn't available. Please file a bugreport!])]
469     )
470   )
471 fi
472
473 AC_CHECK_FUNCS(getpwnam_r getgrnam_r setgroups regcomp regerror regexec regfree)
474
475 socket_needs_socket="no"
476 AC_CHECK_FUNCS(socket, [], AC_CHECK_LIB(socket, socket, [socket_needs_socket="yes"], AC_MSG_ERROR(cannot find socket)))
477 AM_CONDITIONAL(BUILD_WITH_LIBSOCKET, test "x$socket_needs_socket" = "xyes")
478
479 nanosleep_needs_rt="no"
480 AC_CHECK_FUNCS(nanosleep, [], AC_CHECK_LIB(rt, nanosleep, [nanosleep_needs_rt="yes"], AC_MSG_ERROR(cannot find nanosleep)))
481 AM_CONDITIONAL(BUILD_WITH_LIBRT, test "x$nanosleep_needs_rt" = "xyes")
482
483 AC_CHECK_FUNCS(sysctl, [have_sysctl="yes"], [have_sysctl="no"])
484 AC_CHECK_FUNCS(sysctlbyname, [have_sysctlbyname="yes"], [have_sysctlbyname="no"])
485 AC_CHECK_FUNCS(host_statistics, [have_host_statistics="yes"], [have_host_statistics="no"])
486 AC_CHECK_FUNCS(processor_info, [have_processor_info="yes"], [have_processor_info="no"])
487 AC_CHECK_FUNCS(thread_info, [have_thread_info="yes"], [have_thread_info="no"])
488 AC_CHECK_FUNCS(statfs, [have_statfs="yes"], [have_statfs="no"])
489 AC_CHECK_FUNCS(statvfs, [have_statvfs="yes"], [have_statvfs="no"])
490 AC_CHECK_FUNCS(getifaddrs, [have_getifaddrs="yes"], [have_getifaddrs="no"])
491 AC_CHECK_FUNCS(syslog, [have_syslog="yes"], [have_syslog="no"])
492 AC_CHECK_FUNCS(getutent, [have_getutent="yes"], [have_getutent="no"])
493 AC_CHECK_FUNCS(getutxent, [have_getutxent="yes"], [have_getutxent="no"])
494 AC_CHECK_FUNCS(swapctl, [have_swapctl="yes"], [have_swapctl="no"])
495
496 # For load module
497 AC_CHECK_FUNCS(getloadavg, [have_getloadavg="yes"], [have_getloadavg="no"])
498
499 # Check for NAN
500 AC_ARG_WITH(nan-emulation, [AS_HELP_STRING([--with-nan-emulation], [use emulated NAN. For crosscompiling only.])],
501 [
502  if test "x$withval" = "xno"; then
503          nan_type="none"
504  else if test "x$withval" = "xyes"; then
505          nan_type="zero"
506  else
507          nan_type="$withval"
508  fi; fi
509 ],
510 [nan_type="none"])
511 if test "x$nan_type" = "xnone"; then
512   AC_CACHE_CHECK([whether NAN is defined by default],
513     [have_nan_default],
514     AC_COMPILE_IFELSE(
515       AC_LANG_PROGRAM(
516       [[
517 #include <stdlib.h>
518 #include <math.h>
519 static float foo = NAN;
520       ]],
521       [[
522        if (isnan (foo))
523         return 0;
524        else
525         return 1;
526       ]]),
527       [have_nan_default="yes"],
528       [have_nan_default="no"]
529     )
530   )
531   if test "x$have_nan_default" = "xyes"
532   then
533     nan_type="default"
534   fi
535 fi
536 if test "x$nan_type" = "xnone"; then
537   AC_CACHE_CHECK([whether NAN is defined by __USE_ISOC99],
538     [have_nan_isoc],
539     AC_COMPILE_IFELSE(
540       AC_LANG_PROGRAM(
541       [[
542 #include <stdlib.h>
543 #define __USE_ISOC99 1
544 #include <math.h>
545 static float foo = NAN;
546       ]],
547       [[
548        if (isnan (foo))
549         return 0;
550        else
551         return 1;
552       ]]),
553       [have_nan_isoc="yes"],
554       [have_nan_isoc="no"]
555     )
556   )
557   if test "x$have_nan_isoc" = "xyes"
558   then
559     nan_type="isoc99"
560   fi
561 fi
562 if test "x$nan_type" = "xnone"; then
563   AC_CACHE_CHECK([whether NAN can be defined by 0/0],
564     [have_nan_zero],
565     AC_RUN_IFELSE(
566       AC_LANG_PROGRAM(
567       [[
568 #include <stdlib.h>
569 #include <math.h>
570 #ifdef NAN
571 # undef NAN
572 #endif
573 #define NAN (0.0 / 0.0)
574 #ifndef isnan
575 # define isnan(f) ((f) != (f))
576 #endif
577 static float foo = NAN;
578       ]],
579       [[
580        if (isnan (foo))
581         return 0;
582        else
583         return 1;
584       ]]),
585       [have_nan_zero="yes"],
586       [have_nan_zero="no"]
587     )
588   )
589   if test "x$have_nan_zero" = "xyes"
590   then
591     nan_type="zero"
592   fi
593 fi
594
595 if test "x$nan_type" = "xdefault"; then
596   AC_DEFINE(NAN_STATIC_DEFAULT, 1,
597     [Define if NAN is defined by default and can initialize static variables.])
598 else if test "x$nan_type" = "xisoc99"; then
599   AC_DEFINE(NAN_STATIC_ISOC, 1,
600     [Define if NAN is defined by __USE_ISOC99 and can initialize static variables.])
601 else if test "x$nan_type" = "xzero"; then
602   AC_DEFINE(NAN_ZERO_ZERO, 1,
603     [Define if NAN can be defined as (0.0 / 0.0)])
604 else
605   AC_MSG_ERROR([Didn't find out how to statically initialize variables to NAN. Sorry.])
606 fi; fi; fi
607
608 AC_ARG_WITH(fp-layout, [AS_HELP_STRING([--with-fp-layout], [set the memory layout of doubles. For crosscompiling only.])],
609 [
610  if test "x$withval" = "xnothing"; then
611         fp_layout_type="nothing"
612  else if test "x$withval" = "xendianflip"; then
613         fp_layout_type="endianflip"
614  else if test "x$withval" = "xintswap"; then
615         fp_layout_type="intswap"
616  else
617         AC_MSG_ERROR([Invalid argument for --with-fp-layout. Valid arguments are: nothing, endianflip, intswap]);
618 fi; fi; fi
619 ],
620 [fp_layout_type="unknown"])
621
622 if test "x$fp_layout_type" = "xunknown"; then
623   AC_CACHE_CHECK([if doubles are stored in x86 representation],
624     [fp_layout_need_nothing],
625     AC_RUN_IFELSE(
626       AC_LANG_PROGRAM(
627       [[[[
628 #include <stdlib.h>
629 #include <stdio.h>
630 #include <string.h>
631 #if HAVE_STDINT_H
632 # include <stdint.h>
633 #endif
634 #if HAVE_STDBOOL_H
635 # include <stdbool.h>
636 #endif
637       ]]]],
638       [[[[
639         uint64_t i0;
640         uint64_t i1;
641         uint8_t c[8];
642         double d;
643
644         d = 8.642135e130; 
645         memcpy ((void *) &i0, (void *) &d, 8);
646
647         i1 = i0;
648         memcpy ((void *) c, (void *) &i1, 8);
649
650         if ((c[0] == 0x2f) && (c[1] == 0x25)
651                         && (c[2] == 0xc0) && (c[3] == 0xc7)
652                         && (c[4] == 0x43) && (c[5] == 0x2b)
653                         && (c[6] == 0x1f) && (c[7] == 0x5b))
654                 return (0);
655         else
656                 return (1);
657       ]]]]),
658       [fp_layout_need_nothing="yes"],
659       [fp_layout_need_nothing="no"]
660     )
661   )
662   if test "x$fp_layout_need_nothing" = "xyes"; then
663     fp_layout_type="nothing"
664   fi
665 fi
666 if test "x$fp_layout_type" = "xunknown"; then
667   AC_CACHE_CHECK([if endianflip converts to x86 representation],
668     [fp_layout_need_endianflip],
669     AC_RUN_IFELSE(
670       AC_LANG_PROGRAM(
671       [[[[
672 #include <stdlib.h>
673 #include <stdio.h>
674 #include <string.h>
675 #if HAVE_STDINT_H
676 # include <stdint.h>
677 #endif
678 #if HAVE_STDBOOL_H
679 # include <stdbool.h>
680 #endif
681 #define endianflip(A) ((((uint64_t)(A) & 0xff00000000000000LL) >> 56) | \
682                        (((uint64_t)(A) & 0x00ff000000000000LL) >> 40) | \
683                        (((uint64_t)(A) & 0x0000ff0000000000LL) >> 24) | \
684                        (((uint64_t)(A) & 0x000000ff00000000LL) >> 8)  | \
685                        (((uint64_t)(A) & 0x00000000ff000000LL) << 8)  | \
686                        (((uint64_t)(A) & 0x0000000000ff0000LL) << 24) | \
687                        (((uint64_t)(A) & 0x000000000000ff00LL) << 40) | \
688                        (((uint64_t)(A) & 0x00000000000000ffLL) << 56))
689       ]]]],
690       [[[[
691         uint64_t i0;
692         uint64_t i1;
693         uint8_t c[8];
694         double d;
695
696         d = 8.642135e130; 
697         memcpy ((void *) &i0, (void *) &d, 8);
698
699         i1 = endianflip (i0);
700         memcpy ((void *) c, (void *) &i1, 8);
701
702         if ((c[0] == 0x2f) && (c[1] == 0x25)
703                         && (c[2] == 0xc0) && (c[3] == 0xc7)
704                         && (c[4] == 0x43) && (c[5] == 0x2b)
705                         && (c[6] == 0x1f) && (c[7] == 0x5b))
706                 return (0);
707         else
708                 return (1);
709       ]]]]),
710       [fp_layout_need_endianflip="yes"],
711       [fp_layout_need_endianflip="no"]
712     )
713   )
714   if test "x$fp_layout_need_endianflip" = "xyes"; then
715     fp_layout_type="endianflip"
716   fi
717 fi
718 if test "x$fp_layout_type" = "xunknown"; then
719   AC_CACHE_CHECK([if intswap converts to x86 representation],
720     [fp_layout_need_intswap],
721     AC_RUN_IFELSE(
722       AC_LANG_PROGRAM(
723       [[[[
724 #include <stdlib.h>
725 #include <stdio.h>
726 #include <string.h>
727 #if HAVE_STDINT_H
728 # include <stdint.h>
729 #endif
730 #if HAVE_STDBOOL_H
731 # include <stdbool.h>
732 #endif
733 #define intswap(A)    ((((uint64_t)(A) & 0xffffffff00000000LL) >> 32) | \
734                        (((uint64_t)(A) & 0x00000000ffffffffLL) << 32))
735       ]]]],
736       [[[[
737         uint64_t i0;
738         uint64_t i1;
739         uint8_t c[8];
740         double d;
741
742         d = 8.642135e130; 
743         memcpy ((void *) &i0, (void *) &d, 8);
744
745         i1 = intswap (i0);
746         memcpy ((void *) c, (void *) &i1, 8);
747
748         if ((c[0] == 0x2f) && (c[1] == 0x25)
749                         && (c[2] == 0xc0) && (c[3] == 0xc7)
750                         && (c[4] == 0x43) && (c[5] == 0x2b)
751                         && (c[6] == 0x1f) && (c[7] == 0x5b))
752                 return (0);
753         else
754                 return (1);
755       ]]]]),
756       [fp_layout_need_intswap="yes"],
757       [fp_layout_need_intswap="no"]
758     )
759   )
760   if test "x$fp_layout_need_intswap" = "xyes"; then
761     fp_layout_type="intswap"
762   fi
763 fi
764
765 if test "x$fp_layout_type" = "xnothing"; then
766   AC_DEFINE(FP_LAYOUT_NEED_NOTHING, 1,
767   [Define if doubles are stored in x86 representation.])
768 else if test "x$fp_layout_type" = "xendianflip"; then
769   AC_DEFINE(FP_LAYOUT_NEED_ENDIANFLIP, 1,
770   [Define if endianflip is needed to convert to x86 representation.])
771 else if test "x$fp_layout_type" = "xintswap"; then
772   AC_DEFINE(FP_LAYOUT_NEED_INTSWAP, 1,
773   [Define if intswap is needed to convert to x86 representation.])
774 else
775   AC_MSG_ERROR([Didn't find out how doubles are stored in memory. Sorry.])
776 fi; fi; fi
777
778 have_getfsstat="no"
779 AC_CHECK_FUNCS(getfsstat, [have_getfsstat="yes"])
780 have_getvfsstat="no"
781 AC_CHECK_FUNCS(getvfsstat, [have_getvfsstat="yes"])
782 have_listmntent="no"
783 AC_CHECK_FUNCS(listmntent, [have_listmntent="yes"])
784
785 have_getmntent="no"
786 AC_CHECK_FUNCS(getmntent, [have_getmntent="c"])
787 if test "x$have_getmntent" = "xno"; then
788         AC_CHECK_LIB(sun, getmntent, [have_getmntent="sun"])
789 fi
790 if test "x$have_getmntent" = "xno"; then
791         AC_CHECK_LIB(seq, getmntent, [have_getmntent="seq"])
792 fi
793 if test "x$have_getmntent" = "xno"; then
794         AC_CHECK_LIB(gen, getmntent, [have_getmntent="gen"])
795 fi
796
797 if test "x$have_getmntent" = "xc"; then
798         AC_CACHE_CHECK([whether getmntent takes one argument],
799                 [have_one_getmntent],
800                 AC_COMPILE_IFELSE(
801                         AC_LANG_PROGRAM([[AC_INCLUDES_DEFAULT
802 #include <mntent.h>
803 #include "$srcdir/src/utils_mount.h"]],
804                                 [[
805                                  FILE *fh;
806                                  struct mntent *me;
807                                  fh = setmntent ("/etc/mtab", "r");
808                                  me = getmntent (fh);
809                                 ]]
810                         ),
811                         [have_one_getmntent="yes"],
812                         [have_one_getmntent="no"]
813                 )
814         )
815         AC_CACHE_CHECK([whether getmntent takes two arguments],
816                 [have_two_getmntent],
817                 AC_COMPILE_IFELSE(
818                         AC_LANG_PROGRAM([[AC_INCLUDES_DEFAULT
819 #include <sys/mnttab.h>
820 #include "$srcdir/src/utils_mount.h"]],
821                                 [[
822                                  FILE *fh;
823                                  struct mnttab mt;
824                                  int status;
825                                  fh = fopen ("/etc/mnttab", "r");
826                                  status = getmntent (fh, &mt);
827                                 ]]
828                         ),
829                         [have_two_getmntent="yes"],
830                         [have_two_getmntent="no"]
831                 )
832         )
833 fi
834
835 # Check for different versions of `getmntent' here..
836
837 if test "x$have_getmntent" = "xc"; then
838         if test "x$have_one_getmntent" = "xyes"; then
839                 AC_DEFINE(HAVE_ONE_GETMNTENT, 1,
840                           [Define if the function getmntent exists and takes one argument.])
841         fi
842         if test "x$have_two_getmntent" = "xyes"; then
843                 AC_DEFINE(HAVE_TWO_GETMNTENT, 1,
844                           [Define if the function getmntent exists and takes two arguments.])
845         fi
846 fi
847 if test "x$have_getmntent" = "xsun"; then
848         AC_DEFINE(HAVE_SUN_GETMNTENT, 1,
849                   [Define if the function getmntent exists. It's the version from libsun.])
850 fi
851 if test "x$have_getmntent" = "xseq"; then
852         AC_DEFINE(HAVE_SEQ_GETMNTENT, 1,
853                   [Define if the function getmntent exists. It's the version from libseq.])
854 fi
855 if test "x$have_getmntent" = "xgen"; then
856         AC_DEFINE(HAVE_GEN_GETMNTENT, 1,
857                   [Define if the function getmntent exists. It's the version from libgen.])
858 fi
859
860 # Check for structures
861 AC_CHECK_MEMBERS([struct if_data.ifi_ibytes, struct if_data.ifi_opackets, struct if_data.ifi_ierrors],
862         [AC_DEFINE(HAVE_STRUCT_IF_DATA, 1, [Define if struct if_data exists and is usable.])],
863         [],
864         [
865         #include <sys/types.h>
866         #include <sys/socket.h>
867         #include <net/if.h>
868         ])
869 AC_CHECK_MEMBERS([struct net_device_stats.rx_bytes, struct net_device_stats.tx_packets, struct net_device_stats.rx_errors],
870         [AC_DEFINE(HAVE_STRUCT_NET_DEVICE_STATS, 1, [Define if struct net_device_stats exists and is usable.])],
871         [],
872         [
873         #include <sys/types.h>
874         #include <sys/socket.h>
875         #include <linux/if.h>
876         #include <linux/netdevice.h>
877         ])
878
879 AC_CHECK_MEMBERS([struct udphdr.uh_dport, struct udphdr.uh_sport], [], [],
880 [#if HAVE_STDINT_H
881 # include <stdint.h>
882 #endif
883 #if HAVE_SYS_TYPES_H
884 # include <sys/types.h>
885 #endif
886 #if HAVE_NETINET_IN_SYSTM_H
887 # include <netinet/in_systm.h>
888 #endif
889 #if HAVE_NETINET_IN_H
890 # include <netinet/in.h>
891 #endif
892 #if HAVE_NETINET_IP_H
893 # include <netinet/ip.h>
894 #endif
895 #if HAVE_NETINET_UDP_H
896 # include <netinet/udp.h>
897 #endif
898 ])
899 AC_CHECK_MEMBERS([struct udphdr.dest, struct udphdr.source], [], [],
900 [#if HAVE_STDINT_H
901 # include <stdint.h>
902 #endif
903 #if HAVE_SYS_TYPES_H
904 # include <sys/types.h>
905 #endif
906 #if HAVE_NETINET_IN_SYSTM_H
907 # include <netinet/in_systm.h>
908 #endif
909 #if HAVE_NETINET_IN_H
910 # include <netinet/in.h>
911 #endif
912 #if HAVE_NETINET_IP_H
913 # include <netinet/ip.h>
914 #endif
915 #if HAVE_NETINET_UDP_H
916 # include <netinet/udp.h>
917 #endif
918 ])
919
920 AC_CHECK_MEMBERS([kstat_io_t.nwritten, kstat_io_t.writes, kstat_io_t.nwrites, kstat_io_t.wtime],
921         [],
922         [],
923         [
924 #if HAVE_KSTAT_H
925 # include <kstat.h>
926 #endif
927         ])
928
929 #
930 # Checks for libraries begin here
931 #
932 with_libresolv="yes"
933 AC_CHECK_LIB(resolv, res_search,
934 [
935         AC_DEFINE(HAVE_LIBRESOLV, 1, [Define to 1 if you have the 'resolv' library (-lresolv).])
936 ],
937 [with_libresolv="no"])
938 AM_CONDITIONAL(BUILD_WITH_LIBRESOLV, test "x$with_libresolv" = "xyes")
939
940 dnl Check for HAL (hardware abstraction library)
941 with_libhal="yes"
942 AC_CHECK_LIB(hal,libhal_device_property_exists,
943              [AC_DEFINE(HAVE_LIBHAL, 1, [Define to 1 if you have 'hal' library])],
944              [with_libhal="no"])
945 if test "x$with_libhal" = "xyes"; then
946         if test "x$PKG_CONFIG" != "x"; then
947                 BUILD_WITH_LIBHAL_CFLAGS="`pkg-config --cflags hal`"
948                 BUILD_WITH_LIBHAL_LIBS="`pkg-config --libs hal`"
949                 AC_SUBST(BUILD_WITH_LIBHAL_CFLAGS)
950                 AC_SUBST(BUILD_WITH_LIBHAL_LIBS)
951         fi
952 fi
953
954 m4_divert_once([HELP_WITH], [
955 collectd additional packages:])
956
957 if test "x$ac_system" = "xSolaris"
958 then
959         with_kstat="yes"
960         with_devinfo="yes"
961 else
962         with_kstat="no (Solaris only)"
963         with_devinfo="no (Solaris only)"
964 fi
965
966 if test "x$with_kstat" = "xyes"
967 then
968         AC_CHECK_LIB(kstat, kstat_open, [with_kstat="yes"], [with_kstat="no (libkstat not found)"], [])
969 fi
970 if test "x$with_kstat" = "xyes"
971 then
972         AC_CHECK_LIB(devinfo, di_init, [with_devinfo="yes"], [with_devinfo="no (not found)"], [])
973         AC_CHECK_HEADERS(kstat.h,, [with_kstat="no (kstat.h not found)"])
974 fi
975 if test "x$with_kstat" = "xyes"
976 then
977         AC_DEFINE(HAVE_LIBKSTAT, 1,
978                   [Define to 1 if you have the 'kstat' library (-lkstat)])
979 fi
980 AM_CONDITIONAL(BUILD_WITH_LIBKSTAT, test "x$with_kstat" = "xyes")
981 AM_CONDITIONAL(BUILD_WITH_LIBDEVINFO, test "x$with_devinfo" = "xyes")
982
983 with_libiokit="no"
984 AC_CHECK_LIB(IOKit, IOServiceGetMatchingServices,
985 [
986         with_libiokit="yes"
987 ], 
988 [
989         with_libiokit="no"
990 ])
991 AM_CONDITIONAL(BUILD_WITH_LIBIOKIT, test "x$with_libiokit" = "xyes")
992
993 with_libkvm="no"
994 AC_CHECK_LIB(kvm, kvm_getprocs, [with_kvm_getprocs="yes"], [with_kvm_getprocs="no"])
995 if test "x$with_kvm_getprocs" = "xyes"
996 then
997         AC_DEFINE(HAVE_LIBKVM_GETPROCS, 1,
998                   [Define to 1 if you have the 'kvm' library with the 'kvm_getprocs' symbol (-lkvm)])
999         with_libkvm="yes"
1000 fi
1001 AM_CONDITIONAL(BUILD_WITH_LIBKVM_GETPROCS, test "x$with_kvm_getprocs" = "xyes")
1002
1003 AC_CHECK_LIB(kvm, kvm_getswapinfo, [with_kvm_getswapinfo="yes"], [with_kvm_getswapinfo="no"])
1004 if test "x$with_kvm_getswapinfo" = "xyes"
1005 then
1006         AC_DEFINE(HAVE_LIBKVM_GETSWAPINFO, 1,
1007                   [Define to 1 if you have the 'kvm' library with the 'kvm_getswapinfo' symbol (-lkvm)])
1008         with_libkvm="yes"
1009 fi
1010 AM_CONDITIONAL(BUILD_WITH_LIBKVM_GETSWAPINFO, test "x$with_kvm_getswapinfo" = "xyes")
1011
1012 AC_CHECK_LIB(kvm, kvm_nlist, [with_kvm_nlist="yes"], [with_kvm_nlist="no"])
1013 if test "x$with_kvm_nlist" = "xyes"
1014 then
1015         AC_DEFINE(HAVE_LIBKVM_NLIST, 1,
1016                   [Define to 1 if you have the 'kvm' library with the 'kvm_nlist' symbol (-lkvm)])
1017         with_libkvm="yes"
1018 fi
1019 AM_CONDITIONAL(BUILD_WITH_LIBKVM_NLIST, test "x$with_kvm_nlist" = "xyes")
1020
1021 AC_CHECK_LIB(kvm, kvm_openfiles, [with_kvm_openfiles="yes"], [with_kvm_openfiles="no"])
1022 if test "x$with_kvm_openfiles" = "xyes"
1023 then
1024         AC_DEFINE(HAVE_LIBKVM_NLIST, 1,
1025                   [Define to 1 if you have the 'kvm' library with the 'kvm_openfiles' symbol (-lkvm)])
1026         with_libkvm="yes"
1027 fi
1028 AM_CONDITIONAL(BUILD_WITH_LIBKVM_OPENFILES, test "x$with_kvm_openfiles" = "xyes")
1029
1030 # --with-libcurl {{{
1031 with_curl_config="curl-config"
1032 with_curl_cflags=""
1033 with_curl_libs=""
1034 AC_ARG_WITH(libcurl, [AS_HELP_STRING([--with-libcurl@<:@=PREFIX@:>@], [Path to libcurl.])],
1035 [
1036         if test "x$withval" = "xno"
1037         then
1038                 with_libcurl="no"
1039         else if test "x$withval" = "xyes"
1040         then
1041                 with_libcurl="yes"
1042         else
1043                 if test -f "$withval" && test -x "$withval"
1044                 then
1045                         with_curl_config="$withval"
1046                         with_libcurl="yes"
1047                 else if test -x "$withval/bin/curl-config"
1048                 then
1049                         with_curl_config="$withval/bin/curl-config"
1050                         with_libcurl="yes"
1051                 fi; fi
1052                 with_libcurl="yes"
1053         fi; fi
1054 ],
1055 [
1056         with_libcurl="yes"
1057 ])
1058 if test "x$with_libcurl" = "xyes"
1059 then
1060         with_curl_cflags=`$with_curl_config --cflags 2>/dev/null`
1061         curl_config_status=$?
1062
1063         if test $curl_config_status -ne 0
1064         then
1065                 with_libcurl="no ($with_curl_config failed)"
1066         else
1067                 SAVE_CPPFLAGS="$CPPFLAGS"
1068                 CPPFLAGS="$CPPFLAGS $with_curl_cflags"
1069
1070                 AC_CHECK_HEADERS(curl/curl.h, [], [with_libcurl="no (curl/curl.h not found)"], [])
1071
1072                 CPPFLAGS="$SAVE_CPPFLAGS"
1073         fi
1074 fi
1075 if test "x$with_libcurl" = "xyes"
1076 then
1077         with_curl_libs=`$with_curl_config --libs 2>/dev/null`
1078         curl_config_status=$?
1079
1080         if test $curl_config_status -ne 0
1081         then
1082                 with_libcurl="no ($with_curl_config failed)"
1083         else
1084                 AC_CHECK_LIB(curl, curl_easy_init,
1085                  [with_libcurl="yes"],
1086                  [with_libcurl="no (symbol 'curl_easy_init' not found)"],
1087                  [$with_curl_libs])
1088         fi
1089 fi
1090 if test "x$with_libcurl" = "xyes"
1091 then
1092         BUILD_WITH_LIBCURL_CFLAGS="$with_curl_cflags"
1093         BUILD_WITH_LIBCURL_LIBS="$with_curl_libs"
1094         AC_SUBST(BUILD_WITH_LIBCURL_CFLAGS)
1095         AC_SUBST(BUILD_WITH_LIBCURL_LIBS)
1096 fi
1097 AM_CONDITIONAL(BUILD_WITH_LIBCURL, test "x$with_libcurl" = "xyes")
1098 # }}}
1099
1100 # --with-libdbi {{{
1101 with_libdbi_cppflags=""
1102 with_libdbi_ldflags=""
1103 AC_ARG_WITH(libdbi, [AS_HELP_STRING([--with-libdbi@<:@=PREFIX@:>@], [Path to libdbi.])],
1104 [
1105         if test "x$withval" != "xno" && test "x$withval" != "xyes"
1106         then
1107                 with_libdbi_cppflags="-I$withval/include"
1108                 with_libdbi_ldflags="-L$withval/lib"
1109                 with_libdbi="yes"
1110         else
1111                 with_libdbi="$withval"
1112         fi
1113 ],
1114 [
1115         with_libdbi="yes"
1116 ])
1117 if test "x$with_libdbi" = "xyes"
1118 then
1119         SAVE_CPPFLAGS="$CPPFLAGS"
1120         CPPFLAGS="$CPPFLAGS $with_libdbi_cppflags"
1121
1122         AC_CHECK_HEADERS(dbi/dbi.h, [with_libdbi="yes"], [with_libdbi="no (dbi/dbi.h not found)"])
1123
1124         CPPFLAGS="$SAVE_CPPFLAGS"
1125 fi
1126 if test "x$with_libdbi" = "xyes"
1127 then
1128         SAVE_CPPFLAGS="$CPPFLAGS"
1129         SAVE_LDFLAGS="$LDFLAGS"
1130         CPPFLAGS="$CPPFLAGS $with_libdbi_cppflags"
1131         LDFLAGS="$LDFLAGS $with_libdbi_ldflags"
1132
1133         AC_CHECK_LIB(dbi, dbi_initialize, [with_libdbi="yes"], [with_libdbi="no (Symbol 'dbi_initialize' not found)"])
1134
1135         CPPFLAGS="$SAVE_CPPFLAGS"
1136         LDFLAGS="$SAVE_LDFLAGS"
1137 fi
1138 if test "x$with_libdbi" = "xyes"
1139 then
1140         BUILD_WITH_LIBDBI_CPPFLAGS="$with_libdbi_cppflags"
1141         BUILD_WITH_LIBDBI_LDFLAGS="$with_libdbi_ldflags"
1142         BUILD_WITH_LIBDBI_LIBS="-ldbi"
1143         AC_SUBST(BUILD_WITH_LIBDBI_CPPFLAGS)
1144         AC_SUBST(BUILD_WITH_LIBDBI_LDFLAGS)
1145         AC_SUBST(BUILD_WITH_LIBDBI_LIBS)
1146 fi
1147 AM_CONDITIONAL(BUILD_WITH_LIBDBI, test "x$with_libdbi" = "xyes")
1148 # }}}
1149
1150 # --with-libesmtp {{{
1151 AC_ARG_WITH(libesmtp, [AS_HELP_STRING([--with-libesmtp@<:@=PREFIX@:>@], [Path to libesmtp.])],
1152 [
1153         if test "x$withval" != "xno" && test "x$withval" != "xyes"
1154         then
1155                 LDFLAGS="$LDFLAGS -L$withval/lib"
1156                 CPPFLAGS="$CPPFLAGS -I$withval/include -D_THREAD_SAFE"
1157                 with_libesmtp="yes"
1158         else
1159                 with_libesmtp="$withval"
1160         fi
1161 ],
1162 [
1163         with_libesmtp="yes"
1164 ])
1165 if test "x$with_libesmtp" = "xyes"
1166 then
1167         AC_CHECK_LIB(esmtp, smtp_create_session,
1168         [
1169                 AC_DEFINE(HAVE_LIBESMTP, 1, [Define to 1 if you have the esmtp library (-lesmtp).])
1170         ], [with_libesmtp="no (libesmtp not found)"])
1171 fi
1172 if test "x$with_libesmtp" = "xyes"
1173 then
1174         AC_CHECK_HEADERS(libesmtp.h,
1175         [
1176                 AC_DEFINE(HAVE_LIBESMTP_H, 1, [Define to 1 if you have the <libesmtp.h> header file.])
1177         ], [with_libesmtp="no (libesmtp.h not found)"])
1178 fi
1179 if test "x$with_libesmtp" = "xyes"
1180 then
1181         collect_libesmtp=1
1182 else
1183         collect_libesmtp=0
1184 fi
1185 AC_DEFINE_UNQUOTED(COLLECT_LIBESMTP, [$collect_libesmtp],
1186         [Wether or not to use the esmtp library])
1187 AM_CONDITIONAL(BUILD_WITH_LIBESMTP, test "x$with_libesmtp" = "xyes")
1188 # }}}
1189
1190 # --with-libiptc {{{
1191 with_own_libiptc="no"
1192 AC_ARG_WITH(libiptc, [AS_HELP_STRING([--with-libiptc@<:@=PREFIX@:>@], [Path to libiptc.])],
1193 [
1194         if test "x$withval" != "xno" && test "x$withval" != "xyes"
1195         then
1196                 LDFLAGS="$LDFLAGS -L$withval/lib"
1197                 CPPFLAGS="$CPPFLAGS -I$withval/include"
1198                 with_libiptc="yes"
1199         else
1200                 with_libiptc="$withval"
1201         fi
1202 ],
1203 [
1204         if test "x$ac_system" = "xLinux"
1205         then
1206                 with_libiptc="yes"
1207         else
1208                 with_libiptc="no (Linux only)"
1209         fi
1210 ])
1211 if test "x$with_libiptc" = "xyes"
1212 then
1213         AC_CHECK_LIB(iptc, iptc_init,
1214         [
1215                 AC_DEFINE(HAVE_LIBIPTC, 1, [Define to 1 if you have the iptc library (-liptc).])
1216         ],
1217         [
1218                 with_libiptc="yes"
1219                 with_own_libiptc="yes"
1220         ])
1221 fi
1222 if test "x$with_libiptc" = "xyes" -a "x$with_own_libiptc" != "xyes"
1223 then
1224         AC_CHECK_HEADERS(libiptc/libiptc.h,
1225         [
1226                 AC_DEFINE(HAVE_LIBIPTC_LIBIPTC_H, 1, [Define to 1 if you have the <libiptc/libiptc.h> header file.])
1227         ],
1228         [
1229                 with_libiptc="yes"
1230                 with_own_libiptc="yes"
1231         ])
1232 fi
1233 if test "x$with_libiptc" = "xyes"
1234 then
1235         SAVE_CFLAGS=$CFLAGS
1236         CFLAGS="$CFLAGS $KERNEL_CFLAGS"
1237
1238         AC_CHECK_HEADERS(linux/netfilter_ipv4/ip_tables.h linux/netfilter_ipv6/ip6_tables.h, [],
1239         [
1240                 with_libiptc="no (Linux iptables headers not found - check KERNEL_DIR)"
1241                 with_own_libiptc="no"
1242         ],
1243         [
1244 #include "$srcdir/src/libiptc/ipt_kernel_headers.h"
1245         ])
1246
1247         CFLAGS=$SAVE_CFLAGS
1248 fi
1249 AM_CONDITIONAL(BUILD_WITH_LIBIPTC, test "x$with_libiptc" = "xyes")
1250 AM_CONDITIONAL(BUILD_WITH_OWN_LIBIPTC, test "x$with_own_libiptc" = "xyes")
1251 if test "x$with_own_libiptc" = "xyes"
1252 then
1253         AC_DEFINE(OWN_LIBIPTC, 1, [Define to 1 if we use the shipped iptc library.])
1254 fi
1255 # }}}
1256
1257 # --with-java {{{
1258 with_java_home="$JAVA_HOME"
1259 with_java_vmtype="client"
1260 with_java_cflags=""
1261 with_java_libs=""
1262 AC_ARG_WITH(java, [AS_HELP_STRING([--with-java@<:@=PREFIX@:>@], [Path to Java home.])],
1263 [
1264         if test "x$withval" = "xno"
1265         then
1266                 with_java="no"
1267         else if test "x$withval" = "xyes"
1268         then
1269                 with_java="yes"
1270         else
1271                 with_java_home="$withval"
1272                 with_java="yes"
1273         fi; fi
1274 ],
1275 [with_java="yes"])
1276 if test "x$with_java" = "xyes"
1277 then
1278         if test -d "$with_java_home"
1279         then
1280                 if test -d "$with_java_home/include"
1281                 then
1282                         JAVA_CPPFLAGS="$JAVA_CPPFLAGS -I$with_java_home/include"
1283                 else
1284                         JAVA_CPPFLAGS="$JAVA_CPPFLAGS -I$with_java_home"
1285                 fi
1286                 
1287                 if test -d "$with_java_home/lib"
1288                 then
1289                         JAVA_LDFLAGS="$JAVA_LDFLAGS -L$with_java_home/lib"
1290                 else
1291                         JAVA_LDFLAGS="$JAVA_LDFLAGS -L$with_java_home"
1292                 fi
1293         else if test "x$with_java_home" != "x"
1294         then
1295                 AC_MSG_WARN([JAVA_HOME: No such directory: $with_java_home])
1296         fi; fi
1297 fi
1298
1299 if test "x$JAVA_CPPFLAGS" != "x"
1300 then
1301         AC_MSG_NOTICE([Building with JAVA_CPPFLAGS set to: $JAVA_CPPFLAGS])
1302 fi
1303 if test "x$JAVA_CFLAGS" != "x"
1304 then
1305         AC_MSG_NOTICE([Building with JAVA_CFLAGS set to: $JAVA_CFLAGS])
1306 fi
1307 if test "x$JAVA_LDFLAGS" != "x"
1308 then
1309         AC_MSG_NOTICE([Building with JAVA_LDFLAGS set to: $JAVA_LDFLAGS])
1310 fi
1311
1312 SAVE_CPPFLAGS="$CPPFLAGS"
1313 SAVE_CFLAGS="$CFLAGS"
1314 SAVE_LDFLAGS="$LDFLAGS"
1315 CPPFLAGS="$CPPFLAGS $JAVA_CPPFLAGS"
1316 CFLAGS="$CFLAGS $JAVA_CFLAGS"
1317 LDFLAGS="$LDFLAGS $JAVA_LDFLAGS"
1318
1319 if test "x$with_java" = "xyes"
1320 then
1321         AC_CHECK_HEADERS(jni.h, [], [with_java="no (jni.h not found)"])
1322 fi
1323 if test "x$with_java" = "xyes"
1324 then
1325         AC_CHECK_LIB(jvm, JNI_CreateJavaVM,
1326         [with_java="yes"],
1327         [with_java="no (libjvm not found)"],
1328         [$JAVA_LIBS])
1329 fi
1330 if test "x$with_java" = "xyes"
1331 then
1332         JAVA_LIBS="$JAVA_LIBS -ljvm"
1333         AC_MSG_NOTICE([Building with JAVA_LIBS set to: $JAVA_LIBS])
1334 fi
1335
1336 CPPFLAGS="$SAVE_CPPFLAGS"
1337 CFLAGS="$SAVE_CFLAGS"
1338 LDFLAGS="$SAVE_LDFLAGS"
1339
1340 AC_SUBST(JAVA_CPPFLAGS)
1341 AC_SUBST(JAVA_CFLAGS)
1342 AC_SUBST(JAVA_LDFLAGS)
1343 AC_SUBST(JAVA_LIBS)
1344 AM_CONDITIONAL(BUILD_WITH_JAVA, test "x$with_java" = "xyes")
1345 # }}}
1346
1347 # --with-libmysql {{{
1348 with_mysql_config="mysql_config"
1349 with_mysql_cflags=""
1350 with_mysql_libs=""
1351 AC_ARG_WITH(libmysql, [AS_HELP_STRING([--with-libmysql@<:@=PREFIX@:>@], [Path to libmysql.])],
1352 [
1353         if test "x$withval" = "xno"
1354         then
1355                 with_libmysql="no"
1356         else if test "x$withval" = "xyes"
1357         then
1358                 with_libmysql="yes"
1359         else
1360                 if test -f "$withval" && test -x "$withval";
1361                 then
1362                         with_mysql_config="$withval"
1363                 else if test -x "$withval/bin/mysql_config"
1364                 then
1365                         with_mysql_config="$withval/bin/mysql_config"
1366                 fi; fi
1367                 with_libmysql="yes"
1368         fi; fi
1369 ],
1370 [
1371         with_libmysql="yes"
1372 ])
1373 if test "x$with_libmysql" = "xyes"
1374 then
1375         with_mysql_cflags=`$with_mysql_config --cflags 2>/dev/null`
1376         mysql_config_status=$?
1377
1378         if test $mysql_config_status -ne 0
1379         then
1380                 with_libmysql="no ($with_mysql_config failed)"
1381         else
1382                 SAVE_CPPFLAGS="$CPPFLAGS"
1383                 CPPFLAGS="$CPPFLAGS $with_mysql_cflags"
1384
1385                 have_mysql_h="no"
1386                 have_mysql_mysql_h="no"
1387                 AC_CHECK_HEADERS(mysql.h, [have_mysql_h="yes"])
1388
1389                 if test "x$have_mysql_h" = "xno"
1390                 then
1391                         AC_CHECK_HEADERS(mysql/mysql.h, [have_mysql_mysql_h="yes"])
1392                 fi
1393
1394                 if test "x$have_mysql_h$have_mysql_mysql_h" = "xnono"
1395                 then
1396                         with_libmysql="no (mysql.h not found)"
1397                 fi
1398
1399                 CPPFLAGS="$SAVE_CPPFLAGS"
1400         fi
1401 fi
1402 if test "x$with_libmysql" = "xyes"
1403 then
1404         with_mysql_libs=`$with_mysql_config --libs 2>/dev/null`
1405         mysql_config_status=$?
1406
1407         if test $mysql_config_status -ne 0
1408         then
1409                 with_libmysql="no ($with_mysql_config failed)"
1410         else
1411                 AC_CHECK_LIB(mysqlclient, mysql_init,
1412                  [with_libmysql="yes"],
1413                  [with_libmysql="no (symbol 'mysql_init' not found)"],
1414                  [$with_mysql_libs])
1415         fi
1416 fi
1417 if test "x$with_libmysql" = "xyes"
1418 then
1419         BUILD_WITH_LIBMYSQL_CFLAGS="$with_mysql_cflags"
1420         BUILD_WITH_LIBMYSQL_LIBS="$with_mysql_libs"
1421         AC_SUBST(BUILD_WITH_LIBMYSQL_CFLAGS)
1422         AC_SUBST(BUILD_WITH_LIBMYSQL_LIBS)
1423 fi
1424 AM_CONDITIONAL(BUILD_WITH_LIBMYSQL, test "x$with_libmysql" = "xyes")
1425 # }}}
1426
1427 # --with-libnetlink {{{
1428 with_libnetlink_cflags=""
1429 with_libnetlink_libs="-lnetlink"
1430 AC_ARG_WITH(libnetlink, [AS_HELP_STRING([--with-libnetlink@<:@=PREFIX@:>@], [Path to libnetlink.])],
1431 [
1432  echo "libnetlink: withval = $withval"
1433  if test "x$withval" = "xyes"
1434  then
1435          with_libnetlink="yes"
1436  else if test "x$withval" = "xno"
1437  then
1438          with_libnetlink="no"
1439  else
1440          if test -d "$withval/include"
1441          then
1442                  with_libnetlink_cflags="-I$withval/include"
1443                  with_libnetlink_libs="-L$withval/lib -lnetlink"
1444                  with_libnetlink="yes"
1445          else
1446                  AC_MSG_ERROR("no such directory: $withval/include")
1447          fi
1448  fi; fi
1449 ],
1450 [
1451  if test "x$ac_system" = "xLinux"
1452  then
1453          with_libnetlink="yes"
1454  else
1455          with_libnetlink="no (Linux only library)"
1456  fi
1457 ])
1458 if test "x$with_libnetlink" = "xyes"
1459 then
1460         SAVE_CFLAGS=$CFLAGS
1461         CFLAGS="$CFLAGS $with_libnetlink_cflags"
1462
1463         with_libnetlink="no (libnetlink.h not found)"
1464
1465         AC_CHECK_HEADERS(libnetlink.h iproute/libnetlink.h linux/libnetlink.h,
1466         [
1467          with_libnetlink="yes"
1468          break
1469         ], [],
1470 [#include <stdio.h>
1471 #include <sys/types.h>
1472 #include <asm/types.h>
1473 #include <sys/socket.h>
1474 #include <linux/netlink.h>
1475 #include <linux/rtnetlink.h>])
1476         AC_CHECK_HEADERS(linux/gen_stats.h linux/pkt_sched.h, [], [],
1477 [#include <stdio.h>
1478 #include <sys/types.h>
1479 #include <asm/types.h>
1480 #include <sys/socket.h>])
1481
1482         AC_COMPILE_IFELSE(
1483 [#include <stdio.h>
1484 #include <sys/types.h>
1485 #include <asm/types.h>
1486 #include <sys/socket.h>
1487 #include <linux/netlink.h>
1488 #include <linux/rtnetlink.h>
1489
1490 int main (void)
1491 {
1492         int retval = TCA_STATS2;
1493         return (retval);
1494 }],
1495         [AC_DEFINE([HAVE_TCA_STATS2], 1, [True if the enum-member TCA_STATS2 exists])]
1496         []);
1497
1498         AC_COMPILE_IFELSE(
1499 [#include <stdio.h>
1500 #include <sys/types.h>
1501 #include <asm/types.h>
1502 #include <sys/socket.h>
1503 #include <linux/netlink.h>
1504 #include <linux/rtnetlink.h>
1505
1506 int main (void)
1507 {
1508         int retval = TCA_STATS;
1509         return (retval);
1510 }],
1511         [AC_DEFINE([HAVE_TCA_STATS], 1, [True if the enum-member TCA_STATS exists])]
1512         []);
1513
1514         CFLAGS="$SAVE_CFLAGS"
1515 fi
1516 if test "x$with_libnetlink" = "xyes"
1517 then
1518         AC_CHECK_LIB(netlink, rtnl_open,
1519                      [with_libnetlink="yes"],
1520                      [with_libnetlink="no (symbol 'rtnl_open' not found)"],
1521                      [$with_libnetlink_libs])
1522 fi
1523 if test "x$with_libnetlink" = "xyes"
1524 then
1525         BUILD_WITH_LIBNETLINK_CFLAGS="$with_libnetlink_cflags"
1526         BUILD_WITH_LIBNETLINK_LIBS="$with_libnetlink_libs"
1527         AC_SUBST(BUILD_WITH_LIBNETLINK_CFLAGS)
1528         AC_SUBST(BUILD_WITH_LIBNETLINK_LIBS)
1529 fi
1530 AM_CONDITIONAL(BUILD_WITH_LIBNETLINK, test "x$with_libnetlink" = "xyes")
1531 # }}}
1532
1533 # --with-libnetsnmp {{{
1534 with_snmp_config="net-snmp-config"
1535 with_snmp_cflags=""
1536 with_snmp_libs=""
1537 AC_ARG_WITH(libnetsnmp, [AS_HELP_STRING([--with-libnetsnmp@<:@=PREFIX@:>@], [Path to the Net-SNMPD library.])],
1538 [
1539         if test "x$withval" = "xno"
1540         then
1541                 with_libnetsnmp="no"
1542         else if test "x$withval" = "xyes"
1543         then
1544                 with_libnetsnmp="yes"
1545         else
1546                 if test -x "$withval"
1547                 then
1548                         with_snmp_config="$withval"
1549                         with_libnetsnmp="yes"
1550                 else
1551                         with_snmp_config="$withval/bin/net-snmp-config"
1552                         with_libnetsnmp="yes"
1553                 fi
1554         fi; fi
1555 ],
1556 [with_libnetsnmp="yes"])
1557 if test "x$with_libnetsnmp" = "xyes"
1558 then
1559         with_snmp_cflags=`$with_snmp_config --cflags 2>/dev/null`
1560         snmp_config_status=$?
1561
1562         if test $snmp_config_status -ne 0
1563         then
1564                 with_libnetsnmp="no ($with_snmp_config failed)"
1565         else
1566                 SAVE_CPPFLAGS="$CPPFLAGS"
1567                 CPPFLAGS="$CPPFLAGS $with_snmp_cflags"
1568                 
1569                 AC_CHECK_HEADERS(net-snmp/net-snmp-config.h, [], [with_libnetsnmp="no (net-snmp/net-snmp-config.h not found)"])
1570
1571                 CPPFLAGS="$SAVE_CPPFLAGS"
1572         fi
1573 fi
1574 if test "x$with_libnetsnmp" = "xyes"
1575 then
1576         with_snmp_libs=`$with_snmp_config --libs 2>/dev/null`
1577         snmp_config_status=$?
1578
1579         if test $snmp_config_status -ne 0
1580         then
1581                 with_libnetsnmp="no ($with_snmp_config failed)"
1582         else
1583                 AC_CHECK_LIB(netsnmp, init_snmp,
1584                 [with_libnetsnmp="yes"],
1585                 [with_libnetsnmp="no (libnetsnmp not found)"],
1586                 [$with_snmp_libs])
1587         fi
1588 fi
1589 if test "x$with_libnetsnmp" = "xyes"
1590 then
1591         BUILD_WITH_LIBSNMP_CFLAGS="$with_snmp_cflags"
1592         BUILD_WITH_LIBSNMP_LIBS="$with_snmp_libs"
1593         AC_SUBST(BUILD_WITH_LIBSNMP_CFLAGS)
1594         AC_SUBST(BUILD_WITH_LIBSNMP_LIBS)
1595 fi
1596 AM_CONDITIONAL(BUILD_WITH_LIBNETSNMP, test "x$with_libnetsnmp" = "xyes")
1597 # }}}
1598
1599 # --with-liboconfig {{{
1600 with_own_liboconfig="no"
1601 liboconfig_LDFLAGS="$LDFLAGS"
1602 liboconfig_CPPFLAGS="$CPPFLAGS"
1603 AC_ARG_WITH(liboconfig, [AS_HELP_STRING([--with-liboconfig@<:@=PREFIX@:>@], [Path to liboconfig.])],
1604 [
1605         if test "x$withval" != "xno" && test "x$withval" != "xyes"
1606         then
1607                 if test -d "$withval/lib"
1608                 then
1609                         liboconfig_LDFLAGS="$LDFLAGS -L$withval/lib"
1610                 fi
1611                 if test -d "$withval/include"
1612                 then
1613                         liboconfig_CPPFLAGS="$CPPFLAGS -I$withval/include"
1614                 fi
1615         fi
1616         if test "x$withval" = "xno"
1617         then
1618                 AC_MSG_ERROR("liboconfig is required")
1619         fi
1620 ],
1621 [
1622         with_liboconfig="yes"
1623 ])
1624
1625 save_LDFLAGS="$LDFLAGS"
1626 save_CPPFLAGS="$CPPFLAGS"
1627 LDFLAGS="$liboconfig_LDFLAGS"
1628 CPPFLAGS="$liboconfig_CPPFLAGS"
1629 AC_CHECK_LIB(oconfig, oconfig_parse_fh,
1630 [
1631         with_liboconfig="yes"
1632         with_own_liboconfig="no"
1633 ],
1634 [
1635         with_liboconfig="yes"
1636         with_own_liboconfig="yes"
1637         LDFLAGS="$save_LDFLAGS"
1638         CPPFLAGS="$save_CPPFLAGS"
1639 ])
1640
1641 AM_CONDITIONAL(BUILD_WITH_OWN_LIBOCONFIG, test "x$with_own_liboconfig" = "xyes")
1642 if test "x$with_own_liboconfig" = "xyes"
1643 then
1644         with_liboconfig="yes (shipped version)"
1645 fi
1646 # }}}
1647
1648 # --with-liboping {{{
1649 with_own_liboping="no"
1650 liboping_LDFLAGS="$LDFLAGS"
1651 liboping_CPPFLAGS="$CPPFLAGS"
1652 AC_ARG_WITH(liboping, [AS_HELP_STRING([--with-liboping@<:@=PREFIX@:>@], [Path to liboping.])],
1653 [
1654         if test "x$withval" != "xno" && test "x$withval" != "xyes"
1655         then
1656                 if test -d "$withval/lib"
1657                 then
1658                         liboping_LDFLAGS="$LDFLAGS -L$withval/lib"
1659                 fi
1660                 if test -d "$withval/include"
1661                 then
1662                         liboping_CPPFLAGS="$CPPFLAGS -I$withval/include"
1663                 fi
1664         fi
1665         if test "x$withval" = "xno"
1666         then
1667                 with_liboping="no"
1668                 with_own_liboping="no"
1669         else if test "x$withval" = "xyes"
1670         then
1671                 with_liboping="yes"
1672         fi; fi
1673 ],
1674 [
1675         with_liboping="yes"
1676 ])
1677
1678 if test "x$with_liboping" = "xyes"
1679 then
1680         save_LDFLAGS="$LDFLAGS"
1681         save_CPPFLAGS="$CPPFLAGS"
1682         LDFLAGS="$liboping_LDFLAGS"
1683         CPPFLAGS="$liboping_CPPFLAGS"
1684         AC_CHECK_LIB(oping, ping_construct,
1685         [
1686                 with_liboping="yes"
1687                 with_own_liboping="no"
1688         ],
1689         [
1690                 with_liboping="yes"
1691                 with_own_liboping="yes"
1692                 LDFLAGS="$save_LDFLAGS"
1693                 CPPFLAGS="$save_CPPFLAGS"
1694         ])
1695 fi
1696 AM_CONDITIONAL(BUILD_WITH_LIBOPING, test "x$with_liboping" = "xyes")
1697 AM_CONDITIONAL(BUILD_WITH_OWN_LIBOPING, test "x$with_own_liboping" = "xyes")
1698 # }}}
1699
1700 # --with-oracle {{{
1701 with_oracle_cppflags=""
1702 with_oracle_libs=""
1703 AC_ARG_WITH(oracle, [AS_HELP_STRING([--with-oracle@<:@=ORACLE_HOME@:>@], [Path to Oracle.])],
1704 [
1705         if test "x$withval" = "xyes"
1706         then
1707                 if test "x$ORACLE_HOME" = "x"
1708                 then
1709                         AC_MSG_WARN([Use of the Oracle library has been forced, but the environment variable ORACLE_HOME is not set.])
1710                 fi
1711                 with_oracle="yes"
1712         else if test "x$withval" = "xno"
1713         then
1714                 with_oracle="no"
1715         else
1716                 with_oracle="yes"
1717                 ORACLE_HOME="$withval"
1718         fi; fi
1719 ],
1720 [
1721         if test "x$ORACLE_HOME" = "x"
1722         then
1723                 with_oracle="no (ORACLE_HOME is not set)"
1724         else
1725                 with_oracle="yes"
1726         fi
1727 ])
1728 if test "x$ORACLE_HOME" != "x"
1729 then
1730         with_oracle_cppflags="-I$ORACLE_HOME/rdbms/public"
1731
1732         if test -e "$ORACLE_HOME/lib/ldflags"
1733         then
1734                 with_oracle_libs=`cat "$ORACLE_HOME/lib/ldflags"`
1735         fi
1736         #with_oracle_libs="-L$ORACLE_HOME/lib $with_oracle_libs -lclntsh"
1737         with_oracle_libs="-L$ORACLE_HOME/lib -lclntsh"
1738 fi
1739 if test "x$with_oracle" = "xyes"
1740 then
1741         SAVE_CPPFLAGS="$CPPFLAGS"
1742         CPPFLAGS="$CPPFLAGS $with_oracle_cppflags"
1743
1744         AC_CHECK_HEADERS(oci.h, [with_oracle="yes"], [with_oracle="no (oci.h not found)"])
1745
1746         CPPFLAGS="$SAVE_CPPFLAGS"
1747 fi
1748 if test "x$with_oracle" = "xyes"
1749 then
1750         SAVE_CPPFLAGS="$CPPFLAGS"
1751         SAVE_LDFLAGS="$LDFLAGS"
1752         CPPFLAGS="$CPPFLAGS $with_oracle_cppflags"
1753         LDFLAGS="$LDFLAGS $with_oracle_libs"
1754
1755         AC_CHECK_FUNC(OCIEnvCreate, [with_oracle="yes"], [with_oracle="no (Symbol 'OCIEnvCreate' not found)"])
1756
1757         CPPFLAGS="$SAVE_CPPFLAGS"
1758         LDFLAGS="$SAVE_LDFLAGS"
1759 fi
1760 if test "x$with_oracle" = "xyes"
1761 then
1762         BUILD_WITH_ORACLE_CFLAGS="$with_oracle_cppflags"
1763         BUILD_WITH_ORACLE_LIBS="$with_oracle_libs"
1764         AC_SUBST(BUILD_WITH_ORACLE_CFLAGS)
1765         AC_SUBST(BUILD_WITH_ORACLE_LIBS)
1766 fi
1767 # }}}
1768
1769 # --with-libowcapi {{{
1770 with_libowcapi_cppflags=""
1771 with_libowcapi_libs="-lowcapi"
1772 AC_ARG_WITH(libowcapi, [AS_HELP_STRING([--with-libowcapi@<:@=PREFIX@:>@], [Path to libowcapi.])],
1773 [
1774         if test "x$withval" != "xno" && test "x$withval" != "xyes"
1775         then
1776                 with_libowcapi_cppflags="-I$withval/include"
1777                 with_libowcapi_libs="-L$withval/lib -lowcapi"
1778                 with_libowcapi="yes"
1779         else
1780                 with_libowcapi="$withval"
1781         fi
1782 ],
1783 [
1784         with_libowcapi="yes"
1785 ])
1786 if test "x$with_libowcapi" = "xyes"
1787 then
1788         SAVE_CPPFLAGS="$CPPFLAGS"
1789         CPPFLAGS="$with_libowcapi_cppflags"
1790         
1791         AC_CHECK_HEADERS(owcapi.h, [with_libowcapi="yes"], [with_libowcapi="no (owcapi.h not found)"])
1792
1793         CPPFLAGS="$SAVE_CPPFLAGS"
1794 fi
1795 if test "x$with_libowcapi" = "xyes"
1796 then
1797         SAVE_LDFLAGS="$LDFLAGS"
1798         SAVE_CPPFLAGS="$CPPFLAGS"
1799         LDFLAGS="$with_libowcapi_libs"
1800         CPPFLAGS="$with_libowcapi_cppflags"
1801         
1802         AC_CHECK_LIB(owcapi, OW_get, [with_libowcapi="yes"], [with_libowcapi="no (libowcapi not found)"])
1803
1804         LDFLAGS="$SAVE_LDFLAGS"
1805         CPPFLAGS="$SAVE_CPPFLAGS"
1806 fi
1807 if test "x$with_libowcapi" = "xyes"
1808 then
1809         BUILD_WITH_LIBOWCAPI_CPPFLAGS="$with_libowcapi_cppflags"
1810         BUILD_WITH_LIBOWCAPI_LIBS="$with_libowcapi_libs"
1811         AC_SUBST(BUILD_WITH_LIBOWCAPI_CPPFLAGS)
1812         AC_SUBST(BUILD_WITH_LIBOWCAPI_LIBS)
1813 fi
1814 # }}}
1815
1816 # --with-libpcap {{{
1817 AC_ARG_WITH(libpcap, [AS_HELP_STRING([--with-libpcap@<:@=PREFIX@:>@], [Path to libpcap.])],
1818 [
1819         if test "x$withval" != "xno" && test "x$withval" != "xyes"
1820         then
1821                 LDFLAGS="$LDFLAGS -L$withval/lib"
1822                 CPPFLAGS="$CPPFLAGS -I$withval/include"
1823                 with_libpcap="yes"
1824         else
1825                 with_libpcap="$withval"
1826         fi
1827 ],
1828 [
1829         with_libpcap="yes"
1830 ])
1831 if test "x$with_libpcap" = "xyes"
1832 then
1833         AC_CHECK_LIB(pcap, pcap_open_live,
1834         [
1835                 AC_DEFINE(HAVE_LIBPCAP, 1, [Define to 1 if you have the pcap library (-lpcap).])
1836         ], [with_libpcap="no (libpcap not found)"])
1837 fi
1838 if test "x$with_libpcap" = "xyes"
1839 then
1840         AC_CHECK_HEADERS(pcap.h,
1841         [
1842                 AC_DEFINE(HAVE_PCAP_H, 1, [Define to 1 if you have the <pcap.h> header file.])
1843         ], [with_libpcap="no (pcap.h not found)"])
1844 fi
1845 if test "x$with_libpcap" = "xyes"
1846 then
1847         collect_libpcap=1
1848 else
1849         collect_libpcap=0
1850 fi
1851 AC_DEFINE_UNQUOTED(COLLECT_LIBPCAP, [$collect_libpcap],
1852         [Wether or not to use the pcap library])
1853 AM_CONDITIONAL(BUILD_WITH_LIBPCAP, test "x$with_libpcap" = "xyes")
1854 # }}}
1855
1856 # --with-libpcre {{{
1857 with_pcre_config="pcre-config"
1858 with_pcre_cflags=""
1859 with_pcre_libs=""
1860 AC_ARG_WITH(libpcre, [AS_HELP_STRING([--with-libpcre@<:@=PREFIX@:>@],
1861         [Path to libpcre.])],
1862         [
1863                 if test "x$withval" = "xno"
1864                 then
1865                         with_libpcre="no"
1866                 else if test "x$withval" = "xyes"
1867                 then
1868                         with_libpcre="yes"
1869                 else
1870                         if test -f "$withval" && test -x "$withval"
1871                         then
1872                                 with_pcre_config="$withval"
1873                         else if test -x "$withval/bin/pcre-config"
1874                         then
1875                                 with_pcre_config="$withval/bin/pcre-config"
1876                         fi; fi
1877                         with_libpcre="yes"
1878                 fi; fi
1879         ],
1880         [
1881                 with_libpcre="yes"
1882         ])
1883
1884 if test "x$with_libpcre" = "xyes"
1885 then
1886         with_pcre_cflags=`$with_pcre_config --cflags 2>/dev/null`
1887         pcre_config_status=$?
1888
1889         if test $pcre_config_status -ne 0
1890         then
1891                 with_libpcre="no ($with_pcre_config failed)"
1892         else
1893                 SAVE_CPPFLAGS="$CPPFLAGS"
1894                 CPPFLAGS="$CPPFLAGS $with_pcre_cflags"
1895
1896                 AC_CHECK_HEADERS(pcre.h, [], [with_libpcre="no (pcre.h not found)"], [])
1897
1898                 CPPFLAGS="$SAVE_CPPFLAGS"
1899         fi
1900 fi
1901
1902 if test "x$with_libpcre" = "xyes"
1903 then
1904         with_pcre_libs=`$with_pcre_config --libs 2>/dev/null`
1905         pcre_config_status=$?
1906
1907         if test $pcre_config_status -ne 0
1908         then
1909                 with_libpcre="no ($with_pcre_config failed)"
1910         else
1911                 AC_CHECK_LIB(pcre, pcre_compile,
1912                         [with_libpcre="yes"],
1913                         [with_libpcre="no (symbol 'pcre_compile' not found)"],
1914                         [$with_pcre_libs])
1915         fi
1916 fi
1917
1918 if test "x$with_libpcre" = "xyes"
1919 then
1920         BUILD_WITH_LIBPCRE_CFLAGS="$with_pcre_cflags"
1921         BUILD_WITH_LIBPCRE_LIBS="$with_pcre_libs"
1922         AC_SUBST(BUILD_WITH_LIBPCRE_CFLAGS)
1923         AC_SUBST(BUILD_WITH_LIBPCRE_LIBS)
1924 fi
1925 AM_CONDITIONAL(BUILD_WITH_LIBPCRE, test "x$with_libpcre" = "xyes")
1926 # }}}
1927
1928 # --with-libperl {{{
1929 perl_interpreter="perl"
1930 AC_ARG_WITH(libperl, [AS_HELP_STRING([--with-libperl@<:@=PREFIX@:>@], [Path to libperl.])],
1931 [
1932         if test -x "$withval"
1933         then
1934                 perl_interpreter="$withval"
1935                 with_libperl="yes"
1936         else if test "x$withval" != "xno" && test "x$withval" != "xyes"
1937         then
1938                 LDFLAGS="$LDFLAGS -L$withval/lib"
1939                 CPPFLAGS="$CPPFLAGS -I$withval/include"
1940                 perl_interpreter="$withval/bin/perl"
1941                 with_libperl="yes"
1942         else
1943                 with_libperl="$withval"
1944         fi; fi
1945 ],
1946 [
1947         with_libperl="yes"
1948 ])
1949
1950 AC_MSG_CHECKING([for perl])
1951 perl_interpreter=`which "$perl_interpreter" 2> /dev/null`
1952 if test -x "$perl_interpreter"
1953 then
1954         AC_MSG_RESULT([yes ($perl_interpreter)])
1955 else
1956         perl_interpreter=""
1957         AC_MSG_RESULT([no])
1958 fi
1959
1960 AC_SUBST(PERL, "$perl_interpreter")
1961
1962 if test "x$with_libperl" = "xyes" \
1963         && test -n "$perl_interpreter"
1964 then
1965   SAVE_CFLAGS=$CFLAGS
1966   SAVE_LDFLAGS=$LDFLAGS
1967   PERL_CFLAGS=`$perl_interpreter -MExtUtils::Embed -e ccopts`
1968   PERL_LDFLAGS=`$perl_interpreter -MExtUtils::Embed -e ldopts`
1969   CFLAGS="$CFLAGS $PERL_CFLAGS"
1970   LDFLAGS="$LDFLAGS $PERL_LDFLAGS"
1971
1972   AC_CACHE_CHECK([for libperl],
1973     [have_libperl],
1974     AC_LINK_IFELSE(
1975       AC_LANG_PROGRAM(
1976       [[
1977 #define PERL_NO_GET_CONTEXT
1978 #include <EXTERN.h>
1979 #include <perl.h>
1980 #include <XSUB.h>
1981       ]],
1982       [[
1983        dTHX;
1984        load_module (PERL_LOADMOD_NOIMPORT,
1985                          newSVpv ("Collectd::Plugin::FooBar", 24),
1986                          Nullsv);
1987       ]]),
1988       [have_libperl="yes"],
1989       [have_libperl="no"]
1990     )
1991   )
1992
1993   if test "x$have_libperl" = "xyes"
1994   then
1995           AC_DEFINE(HAVE_LIBPERL, 1, [Define if libperl is present and usable.])
1996           AC_SUBST(PERL_CFLAGS)
1997           AC_SUBST(PERL_LDFLAGS)
1998   else
1999           with_libperl="no"
2000   fi
2001
2002   CFLAGS=$SAVE_CFLAGS
2003   LDFLAGS=$SAVE_LDFLAGS
2004 else if test -z "$perl_interpreter"; then
2005   with_libperl="no (no perl interpreter found)"
2006   have_libperl="no"
2007 fi; fi
2008 AM_CONDITIONAL(BUILD_WITH_LIBPERL, test "x$with_libperl" = "xyes")
2009
2010 if test "x$with_libperl" = "xyes"
2011 then
2012         SAVE_CFLAGS=$CFLAGS
2013         SAVE_LDFLAGS=$LDFLAGS
2014         CFLAGS="$CFLAGS $PERL_CFLAGS"
2015         LDFLAGS="$LDFLAGS $PERL_LDFLAGS"
2016
2017         AC_CACHE_CHECK([if perl supports ithreads],
2018                 [have_perl_ithreads],
2019                 AC_LINK_IFELSE(
2020                         AC_LANG_PROGRAM(
2021                         [[
2022 #include <EXTERN.h>
2023 #include <perl.h>
2024 #include <XSUB.h>
2025
2026 #if !defined(USE_ITHREADS)
2027 # error "Perl does not support ithreads!"
2028 #endif /* !defined(USE_ITHREADS) */
2029                         ]],
2030                         [[ ]]),
2031                         [have_perl_ithreads="yes"],
2032                         [have_perl_ithreads="no"]
2033                 )
2034         )
2035
2036         if test "x$have_perl_ithreads" = "xyes"
2037         then
2038                 AC_DEFINE(HAVE_PERL_ITHREADS, 1, [Define if Perl supports ithreads.])
2039         fi
2040
2041         CFLAGS=$SAVE_CFLAGS
2042         LDFLAGS=$SAVE_LDFLAGS
2043 fi
2044
2045 have_broken_perl_load_module="no"
2046 if test "x$with_libperl" = "xyes"
2047 then
2048         SAVE_CFLAGS=$CFLAGS
2049         SAVE_LDFLAGS=$LDFLAGS
2050         # trigger an error if Perl_load_module*() uses __attribute__nonnull__(3)
2051         # (see issues #41 and #42)
2052         CFLAGS="$CFLAGS $PERL_CFLAGS -Wall -Werror"
2053         LDFLAGS="$LDFLAGS $PERL_LDFLAGS"
2054
2055         AC_CACHE_CHECK([for broken Perl_load_module()],
2056                 [have_broken_perl_load_module],
2057                 AC_LINK_IFELSE(
2058                         AC_LANG_PROGRAM(
2059                         [[
2060 #define PERL_NO_GET_CONTEXT
2061 #include <EXTERN.h>
2062 #include <perl.h>
2063 #include <XSUB.h>
2064                         ]],
2065                         [[
2066                          dTHX;
2067                          load_module (PERL_LOADMOD_NOIMPORT,
2068                              newSVpv ("Collectd::Plugin::FooBar", 24),
2069                              Nullsv);
2070                         ]]),
2071                         [have_broken_perl_load_module="no"],
2072                         [have_broken_perl_load_module="yes"]
2073                 )
2074         )
2075
2076         CFLAGS=$SAVE_CFLAGS
2077         LDFLAGS=$SAVE_LDFLAGS
2078 fi
2079 AM_CONDITIONAL(HAVE_BROKEN_PERL_LOAD_MODULE,
2080                 test "x$have_broken_perl_load_module" = "xyes")
2081
2082 if test "x$with_libperl" = "xyes"
2083 then
2084         SAVE_CFLAGS=$CFLAGS
2085         SAVE_LDFLAGS=$LDFLAGS
2086         CFLAGS="$CFLAGS $PERL_CFLAGS"
2087         LDFLAGS="$LDFLAGS $PERL_LDFLAGS"
2088
2089         AC_CHECK_MEMBER(
2090                 [struct mgvtbl.svt_local],
2091                 [have_struct_mgvtbl_svt_local="yes"],
2092                 [have_struct_mgvtbl_svt_local="no"],
2093                 [
2094 #include <EXTERN.h>
2095 #include <perl.h>
2096 #include <XSUB.h>
2097                 ])
2098
2099         if test "x$have_struct_mgvtbl_svt_local" = "xyes"
2100         then
2101                 AC_DEFINE(HAVE_PERL_STRUCT_MGVTBL_SVT_LOCAL, 1,
2102                                   [Define if Perl's struct mgvtbl has member svt_local.])
2103         fi
2104
2105         CFLAGS=$SAVE_CFLAGS
2106         LDFLAGS=$SAVE_LDFLAGS
2107 fi
2108 # }}}
2109
2110 # --with-libpq {{{
2111 with_pg_config="pg_config"
2112 with_libpq_includedir=""
2113 with_libpq_libdir=""
2114 with_libpq_cppflags=""
2115 with_libpq_ldflags=""
2116 AC_ARG_WITH(libpq, [AS_HELP_STRING([--with-libpq@<:@=PREFIX@:>@],
2117         [Path to libpq.])],
2118 [
2119         if test "x$withval" = "xno"
2120         then
2121                 with_libpq="no"
2122         else if test "x$withval" = "xyes"
2123         then
2124                 with_libpq="yes"
2125         else
2126                 if test -f "$withval" && test -x "$withval";
2127                 then
2128                         with_pg_config="$withval"
2129                 else if test -x "$withval/bin/pg_config"
2130                 then
2131                         with_pg_config="$withval/bin/pg_config"
2132                 fi; fi
2133                 with_libpq="yes"
2134         fi; fi
2135 ],
2136 [
2137         with_libpq="yes"
2138 ])
2139 if test "x$with_libpq" = "xyes"
2140 then
2141         with_libpq_includedir=`$with_pg_config --includedir 2> /dev/null`
2142         pg_config_status=$?
2143
2144         if test $pg_config_status -eq 0
2145         then
2146                 if test -n "$with_libpq_includedir"; then
2147                         for dir in $with_libpq_includedir; do
2148                                 with_libpq_cppflags="$with_libpq_cppflags -I$dir"
2149                         done
2150                 fi
2151         else
2152                 AC_MSG_WARN([$with_pg_config returned with status $pg_config_status])
2153         fi
2154
2155         SAVE_CPPFLAGS="$CPPFLAGS"
2156         CPPFLAGS="$CPPFLAGS $with_libpq_cppflags"
2157
2158         AC_CHECK_HEADERS(libpq-fe.h, [],
2159                 [with_libpq="no (libpq-fe.h not found)"], [])
2160
2161         CPPFLAGS="$SAVE_CPPFLAGS"
2162 fi
2163 if test "x$with_libpq" = "xyes"
2164 then
2165         with_libpq_libdir=`$with_pg_config --libdir 2> /dev/null`
2166         pg_config_status=$?
2167
2168         if test $pg_config_status -eq 0
2169         then
2170                 if test -n "$with_libpq_libdir"; then
2171                         for dir in $with_libpq_libdir; do
2172                                 with_libpq_ldflags="$with_libpq_ldflags -L$dir"
2173                         done
2174                 fi
2175         else
2176                 AC_MSG_WARN([$with_pg_config returned with status $pg_config_status])
2177         fi
2178
2179         SAVE_LDFLAGS="$LDFLAGS"
2180         LDFLAGS="$LDFLAGS $with_libpq_ldflags"
2181
2182         AC_CHECK_LIB(pq, PQconnectdb,
2183                 [with_libpq="yes"],
2184                 [with_libpq="no (symbol 'PQconnectdb' not found)"])
2185
2186         LDFLAGS="$SAVE_LDFLAGS"
2187 fi
2188 if test "x$with_libpq" = "xyes"
2189 then
2190         BUILD_WITH_LIBPQ_CPPFLAGS="$with_libpq_cppflags"
2191         BUILD_WITH_LIBPQ_LDFLAGS="$with_libpq_ldflags"
2192         AC_SUBST(BUILD_WITH_LIBPQ_CPPFLAGS)
2193         AC_SUBST(BUILD_WITH_LIBPQ_LDFLAGS)
2194 fi
2195 AM_CONDITIONAL(BUILD_WITH_LIBPQ, test "x$with_libpq" = "xyes")
2196 # }}}
2197
2198 # --with-libpthread {{{
2199 AC_ARG_WITH(libpthread, [AS_HELP_STRING([--with-libpthread=@<:@=PREFIX@:>@], [Path to libpthread.])],
2200 [       if test "x$withval" != "xno" \
2201                 && test "x$withval" != "xyes"
2202         then
2203                 LDFLAGS="$LDFLAGS -L$withval/lib"
2204                 CPPFLAGS="$CPPFLAGS -I$withval/include"
2205                 with_libpthread="yes"
2206         else
2207                 if test "x$withval" = "xno"
2208                 then
2209                         with_libpthread="no (disabled)"
2210                 fi
2211         fi
2212 ], [with_libpthread="yes"])
2213 if test "x$with_libpthread" = "xyes"
2214 then
2215         AC_CHECK_LIB(pthread, pthread_create, [with_libpthread="yes"], [with_libpthread="no (libpthread not found)"], [])
2216 fi
2217
2218 if test "x$with_libpthread" = "xyes"
2219 then
2220         AC_CHECK_HEADERS(pthread.h,, [with_libpthread="no (pthread.h not found)"])
2221 fi
2222 if test "x$with_libpthread" = "xyes"
2223 then
2224         collect_pthread=1
2225 else
2226         collect_pthread=0
2227 fi
2228 AC_DEFINE_UNQUOTED(HAVE_LIBPTHREAD, [$collect_pthread],
2229         [Wether or not to use pthread (POSIX threads) library])
2230 AM_CONDITIONAL(BUILD_WITH_LIBPTHREAD, test "x$with_libpthread" = "xyes")
2231 # }}}
2232
2233 # --with-librrd {{{
2234 # AC_ARG_WITH (package, help-string, [action-if-given], [action-if-not-given])
2235 librrd_cflags=""
2236 librrd_ldflags=""
2237 librrd_threadsafe="yes"
2238 librrd_rrdc_update="no"
2239 AC_ARG_WITH(librrd, [AS_HELP_STRING([--with-librrd@<:@=PREFIX@:>@], [Path to rrdtool.])],
2240 [       if test "x$withval" != "xno" && test "x$withval" != "xyes"
2241         then
2242                 librrd_cflags="-I$withval/include"
2243                 librrd_ldflags="-L$withval/lib"
2244                 with_librrd="yes"
2245         else
2246                 with_librrd="$withval"
2247         fi
2248 ], [with_librrd="yes"])
2249 if test "x$with_librrd" = "xyes"
2250 then
2251         SAVE_CPPFLAGS="$CPPFLAGS"
2252         SAVE_LDFLAGS="$LDFLAGS"
2253
2254         CPPFLAGS="$CPPFLAGS $librrd_cflags"
2255         LDFLAGS="$LDFLAGS $librrd_ldflags"
2256
2257         AC_CHECK_HEADERS(rrd.h,, [with_librrd="no (rrd.h not found)"])
2258
2259         CPPFLAGS="$SAVE_CPPFLAGS"
2260         LDFLAGS="$SAVE_LDFLAGS"
2261 fi
2262 if test "x$with_librrd" = "xyes"
2263 then
2264         SAVE_CPPFLAGS="$CPPFLAGS"
2265         SAVE_LDFLAGS="$LDFLAGS"
2266
2267         CPPFLAGS="$CPPFLAGS $librrd_cflags"
2268         LDFLAGS="$LDFLAGS $librrd_ldflags"
2269
2270         AC_CHECK_LIB(rrd_th, rrd_update_r,
2271         [with_librrd="yes"
2272          librrd_ldflags="$librrd_ldflags -lrrd_th -lm"
2273         ],
2274         [librrd_threadsafe="no"
2275          AC_CHECK_LIB(rrd, rrd_update,
2276          [with_librrd="yes"
2277           librrd_ldflags="$librrd_ldflags -lrrd -lm"
2278          ],
2279          [with_librrd="no (symbol 'rrd_update' not found)"],
2280          [-lm])
2281         ],
2282         [-lm])
2283
2284         if test "x$librrd_threadsafe" = "xyes"
2285         then
2286                 AC_CHECK_LIB(rrd_th, rrdc_update, [librrd_rrdc_update="yes"], [librrd_rrdc_update="no"])
2287         else
2288                 AC_CHECK_LIB(rrd, rrdc_update, [librrd_rrdc_update="yes"], [librrd_rrdc_update="no"])
2289         fi
2290
2291         CPPFLAGS="$SAVE_CPPFLAGS"
2292         LDFLAGS="$SAVE_LDFLAGS"
2293 fi
2294 if test "x$with_librrd" = "xyes"
2295 then
2296         BUILD_WITH_LIBRRD_CFLAGS="$librrd_cflags"
2297         BUILD_WITH_LIBRRD_LDFLAGS="$librrd_ldflags"
2298         AC_SUBST(BUILD_WITH_LIBRRD_CFLAGS)
2299         AC_SUBST(BUILD_WITH_LIBRRD_LDFLAGS)
2300 fi
2301 if test "x$librrd_threadsafe" = "xyes"
2302 then
2303         AC_DEFINE(HAVE_THREADSAFE_LIBRRD, 1, [Define to 1 if you have the threadsafe rrd library (-lrrd_th).])
2304 fi
2305 # }}}
2306
2307 # --with-libsensors {{{
2308 with_sensors_cflags=""
2309 with_sensors_ldflags=""
2310 AC_ARG_WITH(libsensors, [AS_HELP_STRING([--with-libsensors@<:@=PREFIX@:>@], [Path to lm_sensors.])],
2311 [
2312         if test "x$withval" = "xno"
2313         then
2314                 with_libsensors="no"
2315         else
2316                 with_libsensors="yes"
2317                 if test "x$withval" != "xyes"
2318                 then
2319                         with_sensors_cflags="-I$withval/include"
2320                         with_sensors_ldflags="-L$withval/lib"
2321                         with_libsensors="yes"
2322                 fi
2323         fi
2324 ],
2325 [
2326         if test "x$ac_system" = "xLinux"
2327         then
2328                 with_libsensors="yes"
2329         else
2330                 with_libsensors="no (Linux only library)"
2331         fi
2332 ])
2333 if test "x$with_libsensors" = "xyes"
2334 then
2335         SAVE_CPPFLAGS="$CPPFLAGS"
2336         CPPFLAGS="$CPPFLAGS $with_sensors_cflags"
2337
2338 #       AC_CHECK_HEADERS(sensors/sensors.h,
2339 #       [
2340 #               AC_DEFINE(HAVE_SENSORS_SENSORS_H, 1, [Define to 1 if you have the <sensors/sensors.h> header file.])
2341 #       ],
2342 #       [with_libsensors="no (sensors/sensors.h not found)"])
2343         AC_CHECK_HEADERS(sensors/sensors.h, [], [with_libsensors="no (sensors/sensors.h not found)"])
2344
2345         CPPFLAGS="$SAVE_CPPFLAGS"
2346 fi
2347 if test "x$with_libsensors" = "xyes"
2348 then
2349         SAVE_CPPFLAGS="$CPPFLAGS"
2350         SAVE_LDFLAGS="$LDFLAGS"
2351         CPPFLAGS="$CPPFLAGS $with_sensors_cflags"
2352         LDFLAGS="$LDFLAGS $with_sensors_ldflags"
2353
2354         AC_CHECK_LIB(sensors, sensors_init,
2355         [
2356                 AC_DEFINE(HAVE_LIBSENSORS, 1, [Define to 1 if you have the sensors library (-lsensors).])
2357         ],
2358         [with_libsensors="no (libsensors not found)"])
2359
2360         CPPFLAGS="$SAVE_CPPFLAGS"
2361         LDFLAGS="$SAVE_LDFLAGS"
2362 fi
2363 if test "x$with_libsensors" = "xyes"
2364 then
2365         BUILD_WITH_LIBSENSORS_CFLAGS="$with_sensors_cflags"
2366         BUILD_WITH_LIBSENSORS_LDFLAGS="$with_sensors_ldflags"
2367         AC_SUBST(BUILD_WITH_LIBSENSORS_CFLAGS)
2368         AC_SUBST(BUILD_WITH_LIBSENSORS_LDFLAGS)
2369 fi
2370 AM_CONDITIONAL(BUILD_WITH_LM_SENSORS, test "x$with_libsensors" = "xyes")
2371 # }}}
2372
2373 # --with-libstatgrab {{{
2374 with_libstatgrab_cflags=""
2375 with_libstatgrab_ldflags=""
2376 AC_ARG_WITH(libstatgrab, [AS_HELP_STRING([--with-libstatgrab@<:@=PREFIX@:>@], [Path to libstatgrab.])],
2377 [
2378  if test "x$withval" != "xno" \
2379    && test "x$withval" != "xyes"
2380  then
2381    with_libstatgrab_cflags="-I$withval/include"
2382    with_libstatgrab_ldflags="-L$withval/lib -lstatgrab"
2383    with_libstatgrab="yes"
2384    with_libstatgrab_pkg_config="no"
2385  else
2386    with_libstatgrab="$withval"
2387    with_libstatgrab_pkg_config="yes"
2388  fi
2389  ],
2390 [
2391  with_libstatgrab="yes"
2392  with_libstatgrab_pkg_config="yes"
2393 ])
2394
2395 if test "x$with_libstatgrab" = "xyes" \
2396   && test "x$with_libstatgrab_pkg_config" = "xyes"
2397 then
2398   if test "x$PKG_CONFIG" != "x"
2399   then
2400     AC_MSG_CHECKING([pkg-config for libstatgrab])
2401     temp_result="found"
2402     $PKG_CONFIG --exists libstatgrab 2>/dev/null
2403     if test "$?" != "0"
2404     then
2405       with_libstatgrab_pkg_config="no"
2406       with_libstatgrab="no ($PKG_CONFIG doesn't know libstatgrab)"
2407       temp_result="not found"
2408     fi
2409     AC_MSG_RESULT([$temp_result])
2410   else
2411     AC_MSG_NOTICE([pkg-config not available, trying to guess flags for the statgrab library.])
2412     with_libstatgrab_pkg_config="no"
2413     with_libstatgrab_ldflags="$with_libstatgrab_ldflags -lstatgrab"
2414   fi
2415 fi
2416
2417 if test "x$with_libstatgrab" = "xyes" \
2418   && test "x$with_libstatgrab_pkg_config" = "xyes" \
2419   && test "x$with_libstatgrab_cflags" = "x"
2420 then
2421   AC_MSG_CHECKING([for libstatgrab CFLAGS])
2422   temp_result="`$PKG_CONFIG --cflags libstatgrab`"
2423   if test "$?" = "0"
2424   then
2425     with_libstatgrab_cflags="$temp_result"
2426   else
2427     with_libstatgrab="no ($PKG_CONFIG --cflags libstatgrab failed)"
2428     temp_result="$PKG_CONFIG --cflags libstatgrab failed"
2429   fi
2430   AC_MSG_RESULT([$temp_result])
2431 fi
2432
2433 if test "x$with_libstatgrab" = "xyes" \
2434   && test "x$with_libstatgrab_pkg_config" = "xyes" \
2435   && test "x$with_libstatgrab_ldflags" = "x"
2436 then
2437   AC_MSG_CHECKING([for libstatgrab LDFLAGS])
2438   temp_result="`$PKG_CONFIG --libs libstatgrab`"
2439   if test "$?" = "0"
2440   then
2441     with_libstatgrab_ldflags="$temp_result"
2442   else
2443     with_libstatgrab="no ($PKG_CONFIG --libs libstatgrab failed)"
2444     temp_result="$PKG_CONFIG --libs libstatgrab failed"
2445   fi
2446   AC_MSG_RESULT([$temp_result])
2447 fi
2448
2449 if test "x$with_libstatgrab" = "xyes"
2450 then
2451   SAVE_CPPFLAGS="$CPPFLAGS"
2452   CPPFLAGS="$CPPFLAGS $with_libstatgrab_cflags"
2453
2454   AC_CHECK_HEADERS(statgrab.h,
2455                    [with_libstatgrab="yes"],
2456                    [with_libstatgrab="no (statgrab.h not found)"])
2457
2458   CPPFLAGS="$SAVE_CPPFLAGS"
2459 fi
2460
2461 if test "x$with_libstatgrab" = "xyes"
2462 then
2463   SAVE_CFLAGS="$CFLAGS"
2464   SAVE_LDFLAGS="$LDFLAGS"
2465
2466   CFLAGS="$CFLAGS $with_libstatgrab_cflags"
2467   LDFLAGS="$LDFLAGS $with_libstatgrab_ldflags"
2468
2469   AC_CHECK_LIB(statgrab, sg_init,
2470                [with_libstatgrab="yes"],
2471                [with_libstatgrab="no (symbol sg_init not found)"])
2472
2473   CFLAGS="$SAVE_CFLAGS"
2474   LDFLAGS="$SAVE_LDFLAGS"
2475 fi
2476
2477 AM_CONDITIONAL(BUILD_WITH_LIBSTATGRAB, test "x$with_libstatgrab" = "xyes")
2478 if test "x$with_libstatgrab" = "xyes"
2479 then
2480   AC_DEFINE(HAVE_LIBSTATGRAB, 1, [Define to 1 if you have the 'statgrab' library (-lstatgrab)])
2481   BUILD_WITH_LIBSTATGRAB_CFLAGS="$with_libstatgrab_cflags"
2482   BUILD_WITH_LIBSTATGRAB_LDFLAGS="$with_libstatgrab_ldflags"
2483   AC_SUBST(BUILD_WITH_LIBSTATGRAB_CFLAGS)
2484   AC_SUBST(BUILD_WITH_LIBSTATGRAB_LDFLAGS)
2485 fi
2486 # }}}
2487
2488 # --with-libupsclient {{{
2489 with_libupsclient_config=""
2490 with_libupsclient_cflags=""
2491 with_libupsclient_libs=""
2492 AC_ARG_WITH(libupsclient, [AS_HELP_STRING([--with-libupsclient@<:@=PREFIX@:>@], [Path to the Net-SNMPD library.])],
2493 [
2494         if test "x$withval" = "xno"
2495         then
2496                 with_libupsclient="no"
2497         else if test "x$withval" = "xyes"
2498         then
2499                 with_libupsclient="use_pkgconfig"
2500         else
2501                 if test -x "$withval"
2502                 then
2503                         with_libupsclient_config="$withval"
2504                         with_libupsclient="use_libupsclient_config"
2505                 else if test -x "$withval/bin/libupsclient-config"
2506                 then
2507                         with_libupsclient_config="$withval/bin/net-snmp-config"
2508                         with_libupsclient="use_libupsclient_config"
2509                 else
2510                         AC_MSG_NOTICE([Not checking for libupsclient: Manually configured])
2511                         with_libupsclient_cflags="-I$withval/include"
2512                         with_libupsclient_libs="-L$withval/lib -lupsclient"
2513                         with_libupsclient="yes"
2514                 fi; fi
2515         fi; fi
2516 ],
2517 [with_libupsclient="use_pkgconfig"])
2518
2519 # configure using libupsclient-config
2520 if test "x$with_libupsclient" = "xuse_libupsclient_config"
2521 then
2522         AC_MSG_NOTICE([Checking for libupsclient using $with_libupsclient_config])
2523         with_libupsclient_cflags="`$with_libupsclient_config --cflags`"
2524         if test $? -ne 0
2525         then
2526                 with_libupsclient="no ($with_libupsclient_config failed)"
2527         fi
2528         with_libupsclient_libs="`$with_libupsclient_config --libs`"
2529         if test $? -ne 0
2530         then
2531                 with_libupsclient="no ($with_libupsclient_config failed)"
2532         fi
2533 fi
2534 if test "x$with_libupsclient" = "xuse_libupsclient_config"
2535 then
2536         with_libupsclient="yes"
2537 fi
2538
2539 # configure using pkg-config
2540 if test "x$with_libupsclient" = "xuse_pkgconfig"
2541 then
2542         if test "x$PKG_CONFIG" = "x"
2543         then
2544                 with_libupsclient="no (Don't have pkg-config)"
2545         fi
2546 fi
2547 if test "x$with_libupsclient" = "xuse_pkgconfig"
2548 then
2549         AC_MSG_NOTICE([Checking for libupsclient using $PKG_CONFIG])
2550         $PKG_CONFIG --exists 'libupsclient' 2>/dev/null
2551         if test $? -ne 0
2552         then
2553                 with_libupsclient="no (pkg-config doesn't know library)"
2554         fi
2555 fi
2556 if test "x$with_libupsclient" = "xuse_pkgconfig"
2557 then
2558         with_libupsclient_cflags="`$PKG_CONFIG --cflags 'libupsclient'`"
2559         if test $? -ne 0
2560         then
2561                 with_libupsclient="no ($PKG_CONFIG failed)"
2562         fi
2563         with_libupsclient_libs="`$PKG_CONFIG --libs 'libupsclient'`"
2564         if test $? -ne 0
2565         then
2566                 with_libupsclient="no ($PKG_CONFIG failed)"
2567         fi
2568 fi
2569 if test "x$with_libupsclient" = "xuse_pkgconfig"
2570 then
2571         with_libupsclient="yes"
2572 fi
2573
2574 # with_libupsclient_cflags and with_libupsclient_libs are set up now, let's do
2575 # the actual checks.
2576 if test "x$with_libupsclient" = "xyes"
2577 then
2578         SAVE_CPPFLAGS="$CPPFLAGS"
2579         CPPFLAGS="$CPPFLAGS $with_libupsclient_cflags"
2580
2581         AC_CHECK_HEADERS(upsclient.h, [], [with_libupsclient="no (upsclient.h not found)"])
2582
2583         CPPFLAGS="$SAVE_CPPFLAGS"
2584 fi
2585 if test "x$with_libupsclient" = "xyes"
2586 then
2587         SAVE_CPPFLAGS="$CPPFLAGS"
2588         SAVE_LDFLAGS="$LDFLAGS"
2589
2590         CPPFLAGS="$CPPFLAGS $with_libupsclient_cflags"
2591         LDFLAGS="$LDFLAGS $with_libupsclient_libs"
2592
2593         AC_CHECK_LIB(upsclient, upscli_connect,
2594                      [with_libupsclient="yes"],
2595                      [with_libupsclient="no (symbol upscli_connect not found)"])
2596
2597         CPPFLAGS="$SAVE_CPPFLAGS"
2598         LDFLAGS="$SAVE_LDFLAGS"
2599 fi
2600 if test "x$with_libupsclient" = "xyes"
2601 then
2602         SAVE_CPPFLAGS="$CPPFLAGS"
2603         CPPFLAGS="$CPPFLAGS $with_libupsclient_cflags"
2604
2605         AC_CHECK_TYPES([UPSCONN_t, UPSCONN], [], [],
2606 [#include <stdlib.h>
2607 #include <stdio.h>
2608 #include <upsclient.h>])
2609
2610         CPPFLAGS="$SAVE_CPPFLAGS"
2611 fi
2612 if test "x$with_libupsclient" = "xyes"
2613 then
2614         BUILD_WITH_LIBUPSCLIENT_CFLAGS="$with_libupsclient_cflags"
2615         BUILD_WITH_LIBUPSCLIENT_LIBS="$with_libupsclient_libs"
2616         AC_SUBST(BUILD_WITH_LIBUPSCLIENT_CFLAGS)
2617         AC_SUBST(BUILD_WITH_LIBUPSCLIENT_LIBS)
2618 fi
2619 # }}}
2620
2621 # --with-libxmms {{{
2622 with_xmms_config="xmms-config"
2623 with_xmms_cflags=""
2624 with_xmms_libs=""
2625 AC_ARG_WITH(libxmms, [AS_HELP_STRING([--with-libxmms@<:@=PREFIX@:>@], [Path to libxmms.])],
2626 [
2627         if test "x$withval" != "xno" \
2628                 && test "x$withval" != "xyes"
2629         then
2630                 if test -f "$withval" && test -x "$withval";
2631                 then
2632                         with_xmms_config="$withval"
2633                 else if test -x "$withval/bin/xmms-config"
2634                 then
2635                         with_xmms_config="$withval/bin/xmms-config"
2636                 fi; fi
2637                 with_libxmms="yes"
2638         else if test "x$withval" = "xno"
2639         then
2640                 with_libxmms="no"
2641         else
2642                 with_libxmms="yes"
2643         fi; fi
2644 ],
2645 [
2646         with_libxmms="yes"
2647 ])
2648 if test "x$with_libxmms" = "xyes"
2649 then
2650         with_xmms_cflags=`$with_xmms_config --cflags 2>/dev/null`
2651         xmms_config_status=$?
2652
2653         if test $xmms_config_status -ne 0
2654         then
2655                 with_libxmms="no"
2656         fi
2657 fi
2658 if test "x$with_libxmms" = "xyes"
2659 then
2660         with_xmms_libs=`$with_xmms_config --libs 2>/dev/null`
2661         xmms_config_status=$?
2662
2663         if test $xmms_config_status -ne 0
2664         then
2665                 with_libxmms="no"
2666         fi
2667 fi
2668 if test "x$with_libxmms" = "xyes"
2669 then
2670         AC_CHECK_LIB(xmms, xmms_remote_get_info,
2671         [
2672                 BUILD_WITH_LIBXMMS_CFLAGS="$with_xmms_cflags"
2673                 BUILD_WITH_LIBXMMS_LIBS="$with_xmms_libs"
2674                 AC_SUBST(BUILD_WITH_LIBXMMS_CFLAGS)
2675                 AC_SUBST(BUILD_WITH_LIBXMMS_LIBS)
2676         ],
2677         [
2678                 with_libxmms="no"
2679         ],
2680         [$with_xmms_libs])
2681 fi
2682 with_libxmms_numeric=0
2683 if test "x$with_libxmms" = "xyes"
2684 then
2685         with_libxmms_numeric=1
2686 fi
2687 AC_DEFINE_UNQUOTED(HAVE_LIBXMMS, [$with_libxmms_numeric], [Define to 1 if you have the 'xmms' library (-lxmms).])
2688 AM_CONDITIONAL(BUILD_WITH_LIBXMMS, test "x$with_libxmms" = "xyes")
2689 # }}}
2690
2691 # pkg-config --exists 'libxml-2.0'; pkg-config --exists libvirt {{{
2692 with_libxml2="no (pkg-config isn't available)"
2693 with_libxml2_cflags=""
2694 with_libxml2_ldflags=""
2695 with_libvirt="no (pkg-config isn't available)"
2696 with_libvirt_cflags=""
2697 with_libvirt_ldflags=""
2698 if test "x$PKG_CONFIG" != "x"
2699 then
2700         pkg-config --exists 'libxml-2.0' 2>/dev/null
2701         if test "$?" = "0"
2702         then
2703                 with_libxml2="yes"
2704         else
2705                 with_libxml2="no (pkg-config doesn't know library)"
2706         fi
2707
2708         pkg-config --exists libvirt 2>/dev/null
2709         if test "$?" = "0"
2710         then
2711                 with_libvirt="yes"
2712         else
2713                 with_libvirt="no (pkg-config doesn't know library)"
2714         fi
2715 fi
2716 if test "x$with_libxml2" = "xyes"
2717 then
2718         with_libxml2_cflags="`pkg-config --cflags libxml-2.0`"
2719         if test $? -ne 0
2720         then
2721                 with_libxml2="no"
2722         fi
2723         with_libxml2_ldflags="`pkg-config --libs libxml-2.0`"
2724         if test $? -ne 0
2725         then
2726                 with_libxml2="no"
2727         fi
2728 fi
2729 if test "x$with_libxml2" = "xyes"
2730 then
2731         SAVE_CPPFLAGS="$CPPFLAGS"
2732         CPPFLAGS="$CPPFLAGS $with_libxml2_cflags"
2733
2734         AC_CHECK_HEADERS(libxml/parser.h, [],
2735                       [with_libxml2="no (libxml/parser.h not found)"])
2736
2737         CPPFLAGS="$SAVE_CPPFLAGS"
2738 fi
2739 if test "x$with_libxml2" = "xyes"
2740 then
2741         SAVE_CFLAGS="$CFLAGS"
2742         SAVE_LDFLAGS="$LDFLAGS"
2743
2744         CFLAGS="$CFLAGS $with_libxml2_cflags"
2745         LDFLAGS="$LDFLAGS $with_libxml2_ldflags"
2746
2747         AC_CHECK_LIB(xml2, xmlXPathEval,
2748                      [with_libxml2="yes"],
2749                      [with_libxml2="no (symbol xmlXPathEval not found)"])
2750
2751         CFLAGS="$SAVE_CFLAGS"
2752         LDFLAGS="$SAVE_LDFLAGS"
2753 fi
2754 dnl Add the right compiler flags and libraries.
2755 if test "x$with_libxml2" = "xyes"; then
2756         BUILD_WITH_LIBXML2_CFLAGS="$with_libxml2_cflags"
2757         BUILD_WITH_LIBXML2_LIBS="$with_libxml2_ldflags"
2758         AC_SUBST(BUILD_WITH_LIBXML2_CFLAGS)
2759         AC_SUBST(BUILD_WITH_LIBXML2_LIBS)
2760 fi
2761 if test "x$with_libvirt" = "xyes"
2762 then
2763         with_libvirt_cflags="`pkg-config --cflags libvirt`"
2764         if test $? -ne 0
2765         then
2766                 with_libvirt="no"
2767         fi
2768         with_libvirt_ldflags="`pkg-config --libs libvirt`"
2769         if test $? -ne 0
2770         then
2771                 with_libvirt="no"
2772         fi
2773 fi
2774 if test "x$with_libvirt" = "xyes"
2775 then
2776         SAVE_CPPFLAGS="$CPPFLAGS"
2777         CPPFLAGS="$CPPFLAGS $with_libvirt_cflags"
2778
2779         AC_CHECK_HEADERS(libvirt/libvirt.h, [],
2780                       [with_libvirt="no (libvirt/libvirt.h not found)"])
2781
2782         CPPFLAGS="$SAVE_CPPFLAGS"
2783 fi
2784 if test "x$with_libvirt" = "xyes"
2785 then
2786         SAVE_CFLAGS="$CFLAGS"
2787         SAVE_LDFLAGS="$LDFLAGS"
2788
2789         CFLAGS="$CFLAGS $with_libvirt_cflags"
2790         LDFLAGS="$LDFLAGS $with_libvirt_ldflags"
2791
2792         AC_CHECK_LIB(virt, virDomainBlockStats,
2793                      [with_libvirt="yes"],
2794                      [with_libvirt="no (symbol virDomainBlockStats not found)"])
2795
2796         CFLAGS="$SAVE_CFLAGS"
2797         LDFLAGS="$SAVE_LDFLAGS"
2798 fi
2799 dnl Add the right compiler flags and libraries.
2800 if test "x$with_libvirt" = "xyes"; then
2801         BUILD_WITH_LIBVIRT_CFLAGS="$with_libvirt_cflags"
2802         BUILD_WITH_LIBVIRT_LIBS="$with_libvirt_ldflags"
2803         AC_SUBST(BUILD_WITH_LIBVIRT_CFLAGS)
2804         AC_SUBST(BUILD_WITH_LIBVIRT_LIBS)
2805 fi
2806 # }}}
2807
2808 # $PKG_CONFIG --exists OpenIPMIpthread {{{
2809 with_libopenipmipthread="yes"
2810 with_libopenipmipthread_cflags=""
2811 with_libopenipmipthread_libs=""
2812
2813 AC_MSG_CHECKING([for pkg-config])
2814 temp_result="no"
2815 if test "x$PKG_CONFIG" = "x"
2816 then
2817         with_libopenipmipthread="no"
2818         temp_result="no"
2819 else
2820         temp_result="$PKG_CONFIG"
2821 fi
2822 AC_MSG_RESULT([$temp_result])
2823
2824 if test "x$with_libopenipmipthread" = "xyes"
2825 then
2826         AC_MSG_CHECKING([for libOpenIPMIpthread])
2827         $PKG_CONFIG --exists OpenIPMIpthread 2>/dev/null
2828         if test "$?" != "0"
2829         then
2830                 with_libopenipmipthread="no ($PKG_CONFIG doesn't know OpenIPMIpthread)"
2831         fi
2832         AC_MSG_RESULT([$with_libopenipmipthread])
2833 fi
2834
2835 if test "x$with_libopenipmipthread" = "xyes"
2836 then
2837         AC_MSG_CHECKING([for libOpenIPMIpthread CFLAGS])
2838         temp_result="`$PKG_CONFIG --cflags OpenIPMIpthread`"
2839         if test "$?" = "0"
2840         then
2841                 with_libopenipmipthread_cflags="$temp_result"
2842         else
2843                 with_libopenipmipthread="no ($PKG_CONFIG --cflags OpenIPMIpthread failed)"
2844                 temp_result="$PKG_CONFIG --cflags OpenIPMIpthread failed"
2845         fi
2846         AC_MSG_RESULT([$temp_result])
2847 fi
2848
2849 if test "x$with_libopenipmipthread" = "xyes"
2850 then
2851         AC_MSG_CHECKING([for libOpenIPMIpthread LDFLAGS])
2852         temp_result="`$PKG_CONFIG --libs OpenIPMIpthread`"
2853         if test "$?" = "0"
2854         then
2855                 with_libopenipmipthread_ldflags="$temp_result"
2856         else
2857                 with_libopenipmipthread="no ($PKG_CONFIG --libs OpenIPMIpthread failed)"
2858                 temp_result="$PKG_CONFIG --libs OpenIPMIpthread failed"
2859         fi
2860         AC_MSG_RESULT([$temp_result])
2861 fi
2862
2863 if test "x$with_libopenipmipthread" = "xyes"
2864 then
2865         SAVE_CPPFLAGS="$CPPFLAGS"
2866         CPPFLAGS="$CPPFLAGS $with_libopenipmipthread_cflags"
2867
2868         AC_CHECK_HEADERS(OpenIPMI/ipmi_smi.h,
2869                          [with_libopenipmipthread="yes"],
2870                          [with_libopenipmipthread="no (OpenIPMI/ipmi_smi.h not found)"],
2871 [#include <OpenIPMI/ipmiif.h>
2872 #include <OpenIPMI/ipmi_err.h>
2873 #include <OpenIPMI/ipmi_posix.h>
2874 #include <OpenIPMI/ipmi_conn.h>
2875 ])
2876
2877         CPPFLAGS="$SAVE_CPPFLAGS"
2878 fi
2879
2880 if test "x$with_libopenipmipthread" = "xyes"
2881 then
2882         BUILD_WITH_OPENIPMI_CFLAGS="$with_libopenipmipthread_cflags"
2883         BUILD_WITH_OPENIPMI_LIBS="$with_libopenipmipthread_ldflags"
2884         AC_SUBST(BUILD_WITH_OPENIPMI_CFLAGS)
2885         AC_SUBST(BUILD_WITH_OPENIPMI_LIBS)
2886 fi
2887 # }}}
2888
2889 PKG_CHECK_MODULES([LIBNOTIFY], [libnotify],
2890                 [with_libnotify="yes"],
2891                 [with_libnotify="no ($LIBNOTIFY_PKG_ERRORS)"])
2892
2893 # Check for enabled/disabled features
2894 #
2895
2896 # AC_COLLECTD(name, enable/disable, info-text, feature/module)
2897 # ------------------------------------------------------------
2898 dnl
2899 m4_define([my_toupper], [m4_translit([$1], m4_defn([m4_cr_letters]), m4_defn([m4_cr_LETTERS]))])
2900 dnl
2901 AC_DEFUN(
2902         [AC_COLLECTD],
2903         [
2904         m4_if([$1], [], [AC_FATAL([AC_COLLECTD([$1], [$2], [$3], [$4]): 1st argument must not be empty])])dnl
2905         m4_if(
2906                 [$2],
2907                 [enable],
2908                 [dnl
2909                 m4_define([EnDis],[disabled])dnl
2910                 m4_define([YesNo],[no])dnl
2911                 ],dnl
2912                 [m4_if(
2913                         [$2],
2914                         [disable],
2915                         [dnl
2916                         m4_define([EnDis],[enabled])dnl
2917                         m4_define([YesNo],[yes])dnl
2918                         ],
2919                         [dnl
2920                         AC_FATAL([AC_COLLECTD([$1], [$2], [$3], [$4]): 2nd argument must be either enable or disable])dnl
2921                         ]dnl
2922                 )]dnl
2923         )dnl
2924         m4_if([$3], [feature], [],
2925                 [m4_if(
2926                         [$3], [module], [],
2927                         [dnl
2928                         AC_FATAL([AC_COLLECTD([$1], [$2], [$3], [$4]): 3rd argument must be either feature or disable])dnl
2929                         ]dnl
2930                 )]dnl
2931         )dnl
2932         AC_ARG_ENABLE(
2933                 [$1],
2934                 AS_HELP_STRING([--$2-$1], [$2 $4 (EnDis by def)]),
2935                 [],
2936                 enable_$1='[YesNo]'dnl
2937         )# AC_ARG_ENABLE
2938 if test "x$enable_$1" = "xno"
2939 then
2940         collectd_$1=0
2941 else
2942         if test "x$enable_$1" = "xyes"
2943         then
2944                 collectd_$1=1
2945         else
2946                 AC_MSG_NOTICE([please specify either --enable-$1 or --disable-$1; enabling $1.])
2947                 collectd_$1=1
2948                 enable_$1='yes'
2949         fi
2950 fi
2951         AC_DEFINE_UNQUOTED([COLLECT_]my_toupper([$1]), [$collectd_$1], [wether or not to enable $3 $4])
2952         AM_CONDITIONAL([BUILD_]my_toupper([$3])[_]my_toupper([$1]), [test "x$enable_$1" = "xyes"])dnl
2953         ]dnl
2954 )# AC_COLLECTD(name, enable/disable, info-text, feature/module)
2955
2956 # AC_PLUGIN(name, default, info)
2957 # ------------------------------------------------------------
2958 dnl
2959 AC_DEFUN(
2960   [AC_PLUGIN],
2961   [
2962     enable_plugin="no"
2963     AC_ARG_ENABLE([$1], AC_HELP_STRING([--enable-$1], [$3]),
2964     [
2965      if test "x$enableval" = "xyes"
2966      then
2967              enable_plugin="yes"
2968      else
2969              enable_plugin="no"
2970      fi
2971     ],
2972     [
2973      if test "x$2" = "xyes"
2974      then
2975              enable_plugin="yes"
2976      else
2977              enable_plugin="no"
2978      fi
2979     ])
2980     if test "x$enable_plugin" = "xyes"
2981     then
2982             if test "x$2" = "xyes"
2983             then
2984                     AC_DEFINE([HAVE_PLUGIN_]my_toupper([$1]), 1, [Define to 1 if the $1 plugin is enabled.])
2985             else # User passed "yes" but dependency checking yielded "no" => Dependency problem.
2986                     dependency_error="yes"
2987                     enable_plugin="no (dependency error)"
2988             fi
2989     fi
2990     AM_CONDITIONAL([BUILD_PLUGIN_]my_toupper([$1]), test "x$enable_plugin" = "xyes")
2991     enable_$1="$enable_plugin"
2992   ]
2993 )# AC_PLUGIN(name, default, info)
2994
2995 m4_divert_once([HELP_ENABLE], [
2996 collectd features:])
2997 # FIXME: Remove these calls to `AC_COLLECTD' and then remove that macro.
2998 AC_COLLECTD([debug],     [enable],  [feature], [debugging])
2999 AC_COLLECTD([daemon],    [disable], [feature], [daemon mode])
3000 AC_COLLECTD([getifaddrs],[enable],  [feature], [getifaddrs under Linux])
3001
3002 dependency_error="no"
3003 plugin_ascent="no"
3004 plugin_battery="no"
3005 plugin_bind="no"
3006 plugin_cpu="no"
3007 plugin_cpufreq="no"
3008 plugin_df="no"
3009 plugin_disk="no"
3010 plugin_entropy="no"
3011 plugin_interface="no"
3012 plugin_ipmi="no"
3013 plugin_ipvs="no"
3014 plugin_irq="no"
3015 plugin_libvirt="no"
3016 plugin_load="no"
3017 plugin_memory="no"
3018 plugin_multimeter="no"
3019 plugin_nfs="no"
3020 plugin_perl="no"
3021 plugin_processes="no"
3022 plugin_serial="no"
3023 plugin_swap="no"
3024 plugin_tape="no"
3025 plugin_tcpconns="no"
3026 plugin_thermal="no"
3027 plugin_users="no"
3028 plugin_vmem="no"
3029 plugin_vserver="no"
3030 plugin_wireless="no"
3031
3032 # Linux
3033 if test "x$ac_system" = "xLinux"
3034 then
3035         plugin_battery="yes"
3036         plugin_cpu="yes"
3037         plugin_cpufreq="yes"
3038         plugin_disk="yes"
3039         plugin_entropy="yes"
3040         plugin_interface="yes"
3041         plugin_irq="yes"
3042         plugin_load="yes"
3043         plugin_memory="yes"
3044         plugin_nfs="yes"
3045         plugin_processes="yes"
3046         plugin_serial="yes"
3047         plugin_swap="yes"
3048         plugin_tcpconns="yes"
3049         plugin_thermal="yes"
3050         plugin_vmem="yes"
3051         plugin_vserver="yes"
3052         plugin_wireless="yes"
3053
3054         if test "x$have_net_ip_vs_h" = "xyes" -o "x$have_ip_vs_h" = "xyes"
3055         then
3056                 plugin_ipvs="yes"
3057         fi
3058 fi
3059
3060 if test "x$ac_system" = "xOpenBSD"
3061 then
3062         plugin_tcpconns="yes"
3063 fi
3064
3065 # Mac OS X devices
3066 if test "x$with_libiokit" = "xyes"
3067 then
3068         plugin_battery="yes"
3069         plugin_disk="yes"
3070 fi
3071
3072 # Solaris
3073 if test "x$with_devinfo$with_kstat" = "xyesyes"
3074 then
3075         plugin_cpu="yes"
3076         plugin_disk="yes"
3077         plugin_interface="yes"
3078         plugin_memory="yes"
3079         plugin_tape="yes"
3080 fi
3081
3082 if test "x$have_sys_swap_h$with_kstat$ac_system" = "xyesyesSolaris"
3083 then
3084         plugin_swap="yes"
3085 fi
3086
3087 # libstatgrab
3088 if test "x$with_libstatgrab" = "xyes"
3089 then
3090         plugin_cpu="yes"
3091         plugin_disk="yes"
3092         plugin_interface="yes"
3093         plugin_load="yes"
3094         plugin_memory="yes"
3095         plugin_swap="yes"
3096         plugin_users="yes"
3097 fi
3098
3099 if test "x$with_libcurl" = "xyes" && test "x$with_libxml2" = "xyes"
3100 then
3101         plugin_ascent="yes"
3102         plugin_bind="yes"
3103 fi
3104
3105 if test "x$with_libopenipmipthread" = "xyes"
3106 then
3107         plugin_ipmi="yes"
3108 fi
3109
3110 if test "x$have_processor_info" = "xyes"
3111 then
3112         plugin_cpu="yes"
3113 fi
3114 if test "x$have_sysctl" = "xyes"
3115 then
3116         plugin_cpu="yes"
3117         plugin_swap="yes"
3118 fi
3119 if test "x$have_sysctlbyname" = "xyes"
3120 then
3121         plugin_cpu="yes"
3122         plugin_memory="yes"
3123         plugin_tcpconns="yes"
3124 fi
3125
3126 if test "x$have_statfs" = "xyes"
3127 then
3128         plugin_df="yes"
3129 fi
3130 if test "x$have_statvfs" = "xyes"
3131 then
3132         plugin_df="yes"
3133 fi
3134
3135 if test "x$have_getifaddrs" = "xyes"
3136 then
3137         plugin_interface="yes"
3138 fi
3139
3140 if test "x$with_libxml2" = "xyes" && test "x$with_libvirt" = "xyes"
3141 then
3142         plugin_libvirt="yes"
3143 fi
3144
3145 if test "x$have_getloadavg" = "xyes"
3146 then
3147         plugin_load="yes"
3148 fi
3149
3150 if test "x$have_libperl$have_perl_ithreads" = "xyesyes"
3151 then
3152         plugin_perl="yes"
3153 fi
3154
3155 # Mac OS X memory interface
3156 if test "x$have_host_statistics" = "xyes"
3157 then
3158         plugin_memory="yes"
3159 fi
3160
3161 if test "x$have_termios_h" = "xyes"
3162 then
3163         plugin_multimeter="yes"
3164 fi
3165
3166 if test "x$have_thread_info" = "xyes"
3167 then
3168         plugin_processes="yes"
3169 fi
3170
3171 if test "x$with_kvm_getprocs" = "xyes"
3172 then
3173         plugin_processes="yes"
3174 fi
3175
3176 if test "x$with_kvm_getswapinfo" = "xyes"
3177 then
3178         plugin_swap="yes"
3179 fi
3180
3181 if test "x$have_swapctl" = "xyes"
3182 then
3183         plugin_swap="yes"
3184 fi
3185
3186 if test "x$with_kvm_openfiles$with_kvm_nlist" = "xyesyes"
3187 then
3188         plugin_tcpconns="yes"
3189 fi
3190
3191 if test "x$have_getutent" = "xyes"
3192 then
3193         plugin_users="yes"
3194 fi
3195 if test "x$have_getutxent" = "xyes"
3196 then
3197         plugin_users="yes"
3198 fi
3199
3200 m4_divert_once([HELP_ENABLE], [
3201 collectd plugins:])
3202
3203 AC_PLUGIN([apache],      [$with_libcurl],      [Apache httpd statistics])
3204 AC_PLUGIN([apcups],      [yes],                [Statistics of UPSes by APC])
3205 AC_PLUGIN([apple_sensors], [$with_libiokit],   [Apple's hardware sensors])
3206 AC_PLUGIN([ascent],      [$plugin_ascent],     [AscentEmu player statistics])
3207 AC_PLUGIN([battery],     [$plugin_battery],    [Battery statistics])
3208 AC_PLUGIN([bind],        [$plugin_bind],       [ISC Bind nameserver statistics])
3209 AC_PLUGIN([cpufreq],     [$plugin_cpufreq],    [CPU frequency statistics])
3210 AC_PLUGIN([cpu],         [$plugin_cpu],        [CPU usage statistics])
3211 AC_PLUGIN([csv],         [yes],                [CSV output plugin])
3212 AC_PLUGIN([curl],        [$with_libcurl],      [CURL generic web statistics])
3213 AC_PLUGIN([dbi],         [$with_libdbi],       [General database statistics])
3214 AC_PLUGIN([df],          [$plugin_df],         [Filesystem usage statistics])
3215 AC_PLUGIN([disk],        [$plugin_disk],       [Disk usage statistics])
3216 AC_PLUGIN([dns],         [$with_libpcap],      [DNS traffic analysis])
3217 AC_PLUGIN([email],       [yes],                [EMail statistics])
3218 AC_PLUGIN([entropy],     [$plugin_entropy],    [Entropy statistics])
3219 AC_PLUGIN([exec],        [yes],                [Execution of external programs])
3220 AC_PLUGIN([filecount],   [yes],                [Count files in directories])
3221 AC_PLUGIN([hddtemp],     [yes],                [Query hddtempd])
3222 AC_PLUGIN([interface],   [$plugin_interface],  [Interface traffic statistics])
3223 AC_PLUGIN([ipmi],        [$plugin_ipmi],       [IPMI sensor statistics])
3224 AC_PLUGIN([iptables],    [$with_libiptc],      [IPTables rule counters])
3225 AC_PLUGIN([ipvs],        [$plugin_ipvs],       [IPVS connection statistics])
3226 AC_PLUGIN([irq],         [$plugin_irq],        [IRQ statistics])
3227 AC_PLUGIN([java],        [$with_java],         [Embed the Java Virtual Machine])
3228 AC_PLUGIN([libvirt],     [$plugin_libvirt],    [Virtual machine statistics])
3229 AC_PLUGIN([load],        [$plugin_load],       [System load])
3230 AC_PLUGIN([logfile],     [yes],                [File logging plugin])
3231 AC_PLUGIN([match_regex], [yes],                [The regex match])
3232 AC_PLUGIN([match_timediff], [yes],             [The timediff match])
3233 AC_PLUGIN([match_value], [yes],                [The value match])
3234 AC_PLUGIN([mbmon],       [yes],                [Query mbmond])
3235 AC_PLUGIN([memcached],   [yes],                [memcached statistics])
3236 AC_PLUGIN([memory],      [$plugin_memory],     [Memory usage])
3237 AC_PLUGIN([multimeter],  [$plugin_multimeter], [Read multimeter values])
3238 AC_PLUGIN([mysql],       [$with_libmysql],     [MySQL statistics])
3239 AC_PLUGIN([netlink],     [$with_libnetlink],   [Enhanced Linux network statistics])
3240 AC_PLUGIN([network],     [yes],                [Network communication plugin])
3241 AC_PLUGIN([nfs],         [$plugin_nfs],        [NFS statistics])
3242 AC_PLUGIN([nginx],       [$with_libcurl],      [nginx statistics])
3243 AC_PLUGIN([notify_desktop], [$with_libnotify], [Desktop notifications])
3244 AC_PLUGIN([notify_email], [$with_libesmtp],    [Email notifier])
3245 AC_PLUGIN([ntpd],        [yes],                [NTPd statistics])
3246 AC_PLUGIN([nut],         [$with_libupsclient], [Network UPS tools statistics])
3247 AC_PLUGIN([onewire],     [$with_libowcapi],    [OneWire sensor statistics])
3248 AC_PLUGIN([openvpn],     [yes],                [OpenVPN client statistics])
3249 AC_PLUGIN([oracle],      [$with_oracle],       [Oracle plugin])
3250 AC_PLUGIN([perl],        [$plugin_perl],       [Embed a Perl interpreter])
3251 AC_PLUGIN([ping],        [$with_liboping],     [Network latency statistics])
3252 AC_PLUGIN([postgresql],  [$with_libpq],        [PostgreSQL database statistics])
3253 AC_PLUGIN([powerdns],    [yes],                [PowerDNS statistics])
3254 AC_PLUGIN([processes],   [$plugin_processes],  [Process statistics])
3255 AC_PLUGIN([rrdcached],   [$librrd_rrdc_update], [RRDTool output plugin])
3256 AC_PLUGIN([rrdtool],     [$with_librrd],       [RRDTool output plugin])
3257 AC_PLUGIN([sensors],     [$with_libsensors],   [lm_sensors statistics])
3258 AC_PLUGIN([serial],      [$plugin_serial],     [serial port traffic])
3259 AC_PLUGIN([snmp],        [$with_libnetsnmp],   [SNMP querying plugin])
3260 AC_PLUGIN([swap],        [$plugin_swap],       [Swap usage statistics])
3261 AC_PLUGIN([syslog],      [$have_syslog],       [Syslog logging plugin])
3262 AC_PLUGIN([tail],        [yes],                [Parsing of logfiles])
3263 AC_PLUGIN([tape],        [$plugin_tape],       [Tape drive statistics])
3264 AC_PLUGIN([target_notification], [yes],        [The notification target])
3265 AC_PLUGIN([target_replace], [yes],             [The replace target])
3266 AC_PLUGIN([target_set],  [yes],                [The set target])
3267 AC_PLUGIN([tcpconns],    [$plugin_tcpconns],   [TCP connection statistics])
3268 AC_PLUGIN([teamspeak2],  [yes],                [TeamSpeak2 server statistics])
3269 AC_PLUGIN([thermal],     [$plugin_thermal],    [Linux ACPI thermal zone statistics])
3270 AC_PLUGIN([unixsock],    [yes],                [Unixsock communication plugin])
3271 AC_PLUGIN([users],       [$plugin_users],      [User statistics])
3272 AC_PLUGIN([uuid],        [yes],                [UUID as hostname plugin])
3273 AC_PLUGIN([vmem],        [$plugin_vmem],       [Virtual memory statistics])
3274 AC_PLUGIN([vserver],     [$plugin_vserver],    [Linux VServer statistics])
3275 AC_PLUGIN([wireless],    [$plugin_wireless],   [Wireless statistics])
3276 AC_PLUGIN([xmms],        [$with_libxmms],      [XMMS statistics])
3277
3278 dnl ip_vs.h
3279 if test "x$ac_system" = "xLinux" \
3280         && test "x$have_net_ip_vs_h$have_ip_vs_h" = "xnono"
3281 then
3282         enable_ipvs="$enable_ipvs (ip_vs.h not found)"
3283 fi
3284
3285 dnl Perl bindings
3286 AC_ARG_WITH(perl-bindings, [AS_HELP_STRING([--with-perl-bindings@<:@=OPTIONS@:>@], [Options passed to "perl Makefile.PL".])],
3287 [
3288         if test "x$withval" != "xno" && test "x$withval" != "xyes"
3289         then
3290                 PERL_BINDINGS_OPTIONS="$withval"
3291                 with_perl_bindings="yes"
3292         else
3293                 PERL_BINDINGS_OPTIONS=""
3294                 with_perl_bindings="$withval"
3295         fi
3296 ],
3297 [
3298         PERL_BINDINGS_OPTIONS=""
3299         if test -n "$perl_interpreter"
3300         then
3301                 with_perl_bindings="yes"
3302         else
3303                 with_perl_bindings="no (no perl interpreter found)"
3304         fi
3305 ])
3306 if test "x$with_perl_bindings" = "xyes"
3307 then
3308         PERL_BINDINGS="perl"
3309 else
3310         PERL_BINDINGS=""
3311 fi
3312 AC_SUBST(PERL_BINDINGS)
3313 AC_SUBST(PERL_BINDINGS_OPTIONS)
3314
3315 dnl libcollectdclient
3316 LCC_VERSION_MAJOR=`echo $PACKAGE_VERSION | cut -d'.' -f1`
3317 LCC_VERSION_MINOR=`echo $PACKAGE_VERSION | cut -d'.' -f2`
3318 LCC_VERSION_PATCH=`echo $PACKAGE_VERSION | cut -d'.' -f3`
3319
3320 LCC_VERSION_EXTRA=`echo $PACKAGE_VERSION | cut -d'.' -f4-`
3321
3322 LCC_VERSION_STRING="$LCC_VERSION_MAJOR.$LCC_VERSION_MINOR.$LCC_VERSION_PATCH"
3323
3324 AC_SUBST(LCC_VERSION_MAJOR)
3325 AC_SUBST(LCC_VERSION_MINOR)
3326 AC_SUBST(LCC_VERSION_PATCH)
3327 AC_SUBST(LCC_VERSION_EXTRA)
3328 AC_SUBST(LCC_VERSION_STRING)
3329
3330 AC_CONFIG_FILES(src/libcollectdclient/lcc_features.h)
3331
3332 AC_OUTPUT(Makefile src/Makefile src/collectd.conf src/libiptc/Makefile src/libcollectdclient/Makefile src/libcollectdclient/libcollectdclient.pc src/liboconfig/Makefile src/liboping/Makefile bindings/Makefile)
3333
3334 if test "x$with_librrd" = "xyes" \
3335         && test "x$librrd_threadsafe" != "xyes"
3336 then
3337         with_librrd="yes (warning: librrd is not thread-safe)"
3338 fi
3339
3340 if test "x$with_liboping" = "xyes" \
3341         && test "x$with_own_liboping" = "xyes"
3342 then
3343         with_liboping="yes (shipped version)"
3344 fi
3345
3346 if test "x$with_libiptc" = "xyes" -a "x$with_own_libiptc" = "xyes"
3347 then
3348         with_libiptc="yes (shipped version)"
3349 fi
3350
3351 if test "x$with_libperl" = "xyes"
3352 then
3353         with_libperl="yes (version `$perl_interpreter -MConfig -e 'print $Config{version};'`)"
3354 else
3355         enable_perl="no (needs libperl)"
3356 fi
3357
3358 if test "x$with_perl_bindings" = "xyes" \
3359         && test "x$PERL_BINDINGS_OPTIONS" != "x"
3360 then
3361         with_perl_bindings="yes ($PERL_BINDINGS_OPTIONS)"
3362 fi
3363
3364 cat <<EOF;
3365
3366 Configuration:
3367   Libraries:
3368     libcurl . . . . . . . $with_libcurl
3369     libdbi  . . . . . . . $with_libdbi
3370     libesmtp  . . . . . . $with_libesmtp
3371     libiokit  . . . . . . $with_libiokit
3372     libiptc . . . . . . . $with_libiptc
3373     libjvm  . . . . . . . $with_java
3374     libkstat  . . . . . . $with_kstat
3375     libkvm  . . . . . . . $with_libkvm
3376     libmysql  . . . . . . $with_libmysql
3377     libnetlink  . . . . . $with_libnetlink
3378     libnetsnmp  . . . . . $with_libnetsnmp
3379     libnotify . . . . . . $with_libnotify
3380     liboconfig  . . . . . $with_liboconfig
3381     libopenipmi . . . . . $with_libopenipmipthread
3382     liboping  . . . . . . $with_liboping
3383     libpcap . . . . . . . $with_libpcap
3384     libpcre . . . . . . . $with_libpcre
3385     libperl . . . . . . . $with_libperl
3386     libpq . . . . . . . . $with_libpq
3387     libpthread  . . . . . $with_libpthread
3388     librrd  . . . . . . . $with_librrd
3389     libsensors  . . . . . $with_libsensors
3390     libstatgrab . . . . . $with_libstatgrab
3391     libupsclient  . . . . $with_libupsclient
3392     libvirt . . . . . . . $with_libvirt
3393     libxml2 . . . . . . . $with_libxml2
3394     libxmms . . . . . . . $with_libxmms
3395     oracle  . . . . . . . $with_oracle
3396
3397   Features:
3398     daemon mode . . . . . $enable_daemon
3399     debug . . . . . . . . $enable_debug
3400
3401   Bindings:
3402     perl  . . . . . . . . $with_perl_bindings
3403
3404   Modules:
3405     apache  . . . . . . . $enable_apache
3406     apcups  . . . . . . . $enable_apcups
3407     apple_sensors . . . . $enable_apple_sensors
3408     ascent  . . . . . . . $enable_ascent
3409     battery . . . . . . . $enable_battery
3410     bind  . . . . . . . . $enable_bind
3411     cpu . . . . . . . . . $enable_cpu
3412     cpufreq . . . . . . . $enable_cpufreq
3413     csv . . . . . . . . . $enable_csv
3414     curl  . . . . . . . . $enable_curl
3415     dbi . . . . . . . . . $enable_dbi
3416     df  . . . . . . . . . $enable_df
3417     disk  . . . . . . . . $enable_disk
3418     dns . . . . . . . . . $enable_dns
3419     email . . . . . . . . $enable_email
3420     entropy . . . . . . . $enable_entropy
3421     exec  . . . . . . . . $enable_exec
3422     filecount . . . . . . $enable_filecount
3423     hddtemp . . . . . . . $enable_hddtemp
3424     interface . . . . . . $enable_interface
3425     ipmi  . . . . . . . . $enable_ipmi
3426     iptables  . . . . . . $enable_iptables
3427     ipvs  . . . . . . . . $enable_ipvs
3428     irq . . . . . . . . . $enable_irq
3429     java  . . . . . . . . $enable_java
3430     libvirt . . . . . . . $enable_libvirt
3431     load  . . . . . . . . $enable_load
3432     logfile . . . . . . . $enable_logfile
3433     match_regex . . . . . $enable_match_regex
3434     match_timediff  . . . $enable_match_timediff
3435     match_value . . . . . $enable_match_value
3436     mbmon . . . . . . . . $enable_mbmon
3437     memcached . . . . . . $enable_memcached
3438     memory  . . . . . . . $enable_memory
3439     multimeter  . . . . . $enable_multimeter
3440     mysql . . . . . . . . $enable_mysql
3441     netlink . . . . . . . $enable_netlink
3442     network . . . . . . . $enable_network
3443     nfs . . . . . . . . . $enable_nfs
3444     nginx . . . . . . . . $enable_nginx
3445     notify_desktop  . . . $enable_notify_desktop
3446     notify_email  . . . . $enable_notify_email
3447     ntpd  . . . . . . . . $enable_ntpd
3448     nut . . . . . . . . . $enable_nut
3449     onewire . . . . . . . $enable_onewire
3450     openvpn . . . . . . . $enable_openvpn
3451     oracle  . . . . . . . $enable_oracle
3452     perl  . . . . . . . . $enable_perl
3453     ping  . . . . . . . . $enable_ping
3454     postgresql  . . . . . $enable_postgresql
3455     powerdns  . . . . . . $enable_powerdns
3456     processes . . . . . . $enable_processes
3457     rrdcached . . . . . . $enable_rrdcached
3458     rrdtool . . . . . . . $enable_rrdtool
3459     sensors . . . . . . . $enable_sensors
3460     serial  . . . . . . . $enable_serial
3461     snmp  . . . . . . . . $enable_snmp
3462     swap  . . . . . . . . $enable_swap
3463     syslog  . . . . . . . $enable_syslog
3464     tail  . . . . . . . . $enable_tail
3465     tape  . . . . . . . . $enable_tape
3466     target_notification . $enable_target_notification
3467     target_replace  . . . $enable_target_replace
3468     target_set  . . . . . $enable_target_set
3469     tcpconns  . . . . . . $enable_tcpconns
3470     teamspeak2  . . . . . $enable_teamspeak2
3471     thermal . . . . . . . $enable_thermal
3472     unixsock  . . . . . . $enable_unixsock
3473     users . . . . . . . . $enable_users
3474     uuid  . . . . . . . . $enable_uuid
3475     vmem  . . . . . . . . $enable_vmem
3476     vserver . . . . . . . $enable_vserver
3477     wireless  . . . . . . $enable_wireless
3478     xmms  . . . . . . . . $enable_xmms
3479
3480 EOF
3481
3482 if test "x$dependency_error" = "xyes"; then
3483         AC_MSG_ERROR("Some plugins are missing dependencies - see above summary for details")
3484 fi
3485
3486 # vim: set fdm=marker :