From: Florian Forster Date: Tue, 29 Apr 2008 09:34:22 +0000 (+0200) Subject: build system: Use pkg-config to determine flags for the statgrab library. X-Git-Tag: collectd-4.4.0~4^2~6^2~1 X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=4aed4a7a08b80608c532d2da7eb7fe43c2945e13;p=collectd.git build system: Use pkg-config to determine flags for the statgrab library. --- diff --git a/configure.in b/configure.in index db344978..cdd3e6cb 100644 --- a/configure.in +++ b/configure.in @@ -28,6 +28,7 @@ AC_LIBTOOL_DLOPEN AC_PROG_LIBTOOL AC_PROG_LEX AC_PROG_YACC +PKG_PROG_PKG_CONFIG AC_CONFIG_SUBDIRS(libltdl) AC_MSG_CHECKING([for kernel type ($host_os)]) @@ -810,6 +811,9 @@ AC_CHECK_MEMBERS([kstat_io_t.nwritten, kstat_io_t.writes, kstat_io_t.nwrites, ks #endif ]) +# +# Checks for libraries begin here +# with_libresolv="yes" AC_CHECK_LIB(resolv, res_search, [ @@ -1025,12 +1029,14 @@ AC_CHECK_LIB(IOKit, IOServiceGetMatchingServices, AC_DEFINE_UNQUOTED(COLLECT_LIBIOKIT, [$collect_libiokit], [Wether or not to use the IOKit library]) AM_CONDITIONAL(BUILD_WITH_LIBIOKIT, test "x$with_libiokit" = "xyes") +with_libstatgrab_cflags="" +with_libstatgrab_ldflags="" AC_ARG_WITH(libstatgrab, [AS_HELP_STRING([--with-libstatgrab@<:@=PREFIX@:>@], [Path to libstatgrab.])], [ if test "x$withval" != "xno" -a "x$withval" != "xyes" then - LDFLAGS="$LDFLAGS -L$withval/lib" - CPPFLAGS="$CPPFLAGS -I$withval/include" + with_libstatgrab_cflags="-I$withval/include" + with_libstatgrab_ldflags="-L$withval/lib" with_libstatgrab="yes" fi ], @@ -1042,28 +1048,93 @@ AC_ARG_WITH(libstatgrab, [AS_HELP_STRING([--with-libstatgrab@<:@=PREFIX@:>@], [P with_libstatgrab="no" fi ]) -if test "x$with_libstatgrab" = "xyes" +with_libstatgrab_pkg_config="yes" +if test "x$with_libstatgrab" = "xyes" \ + && test "x$PKG_CONFIG" != "x" +then + AC_MSG_CHECKING([pkg-config for libstatgrab]) + temp_result="found" + $PKG_CONFIG --exists libstatgrab 2>/dev/null + if test "$?" != "0" + then + with_libstatgrab_pkg_config="no" + temp_result="not found" + fi + AC_MSG_RESULT([$temp_result]) +else + AC_MSG_NOTICE([pkg-config not available, trying to guess flags for the statgrab library.]) + with_libstatgrab_pkg_config="no" + with_libstatgrab_ldflags="$with_libstatgrab_ldflags -lstatgrab" +fi + +if test "x$with_libstatgrab" = "xyes" \ + && test "x$with_libstatgrab_pkg_config" = "xyes" \ + && test "x$with_libstatgrab_cflags" = "x" then - AC_CHECK_LIB(statgrab, sg_init, [with_libstatgrab="yes"], [with_libstatgrab="no (libstatgrab not found)"]) + AC_MSG_CHECKING([for libstatgrab CFLAGS]) + temp_result="`$PKG_CONFIG --cflags libstatgrab`" + if test "$?" = "0" + then + with_libstatgrab_cflags="$temp_result" + else + with_libstatgrab="no ($PKG_CONFIG --cflags libstatgrab failed)" + temp_result="$PKG_CONFIG --cflags libstatgrab failed" + fi + AC_MSG_RESULT([$temp_result]) fi -if test "x$with_libstatgrab" = "xyes" + +if test "x$with_libstatgrab" = "xyes" \ + && test "x$with_libstatgrab_pkg_config" = "xyes" \ + && test "x$with_libstatgrab_ldflags" = "x" then - AC_CHECK_HEADERS(statgrab.h,, [with_libstatgrab="no (statgrab.h not found)"]) + AC_MSG_CHECKING([for libstatgrab LDFLAGS]) + temp_result="`$PKG_CONFIG --libs libstatgrab`" + if test "$?" = "0" + then + with_libstatgrab_ldflags="$temp_result" + else + with_libstatgrab="no ($PKG_CONFIG --libs libstatgrab failed)" + temp_result="$PKG_CONFIG --libs libstatgrab failed" + fi + AC_MSG_RESULT([$temp_result]) fi + if test "x$with_libstatgrab" = "xyes" then - AC_CHECK_LIB(devstat, getdevs, [with_libdevstat="yes"], [with_libdevstat="no"]) + SAVE_CPPFLAGS="$CPPFLAGS" + CPPFLAGS="$CPPFLAGS $with_libstatgrab_cflags" + + AC_CHECK_HEADERS(statgrab.h, + [with_libstatgrab="yes"], + [with_libstatgrab="no (statgrab.h not found)"]) + + CPPFLAGS="$SAVE_CPPFLAGS" fi + if test "x$with_libstatgrab" = "xyes" then - collect_libstatgrab=1 -else - collect_libstatgrab=0 + SAVE_CFLAGS="$CFLAGS" + SAVE_LDFLAGS="$LDFLAGS" + + CFLAGS="$CFLAGS $with_libstatgrab_cflags" + LDFLAGS="$LDFLAGS $with_libstatgrab_ldflags" + + AC_CHECK_LIB(statgrab, sg_init, + [with_libstatgrab="yes"], + [with_libstatgrab="no (symbol sg_init not found)"]) + + CFLAGS="$SAVE_CFLAGS" + LDFLAGS="$SAVE_LDFLAGS" fi -AC_DEFINE_UNQUOTED(COLLECT_LIBSTATGRAB, [$collect_libstatgrab], - [Wether or not to use statgrab library]) + AM_CONDITIONAL(BUILD_WITH_LIBSTATGRAB, test "x$with_libstatgrab" = "xyes") -AM_CONDITIONAL(BUILD_WITH_LIBDEVSTAT, test "x$with_libdevstat" = "xyes") +if test "x$with_libstatgrab" = "xyes" +then + BUILD_WITH_LIBSTATGRAB_CFLAGS="$with_libstatgrab_cflags" + BUILD_WITH_LIBSTATGRAB_LDFLAGS="$with_libstatgrab_ldflags" + AC_SUBST(BUILD_WITH_LIBSTATGRAB_CFLAGS) + AC_SUBST(BUILD_WITH_LIBSTATGRAB_LDFLAGS) +fi AC_CHECK_LIB(kvm, kvm_getswapinfo, [with_libkvm="yes"], [with_libkvm="no"]) if test "x$with_libkvm" = "xyes" diff --git a/src/Makefile.am b/src/Makefile.am index d305d855..974e5587 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -22,7 +22,13 @@ collectd_SOURCES = collectd.c collectd.h \ plugin.c plugin.h \ configfile.c configfile.h \ types_list.c types_list.h + collectd_CPPFLAGS = $(LTDLINCL) +collectd_CFLAGS = +collectd_LDFLAGS = -export-dynamic +collectd_LDADD = +collectd_DEPENDENCIES = + collectd_CPPFLAGS += -DPREFIX='"${prefix}"' collectd_CPPFLAGS += -DCONFIGFILE='"${sysconfdir}/${PACKAGE_NAME}.conf"' collectd_CPPFLAGS += -DLOCALSTATEDIR='"${localstatedir}"' @@ -33,44 +39,37 @@ endif collectd_CPPFLAGS += -DPLUGINDIR='"${pkglibdir}"' # Link to these libraries.. -collectd_LDFLAGS = -export-dynamic if BUILD_WITH_LIBRT -collectd_LDFLAGS += -lrt +collectd_LDADD += -lrt endif if BUILD_WITH_LIBSOCKET -collectd_LDFLAGS += -lsocket +collectd_LDADD += -lsocket endif if BUILD_WITH_LIBRESOLV -collectd_LDFLAGS += -lresolv +collectd_LDADD += -lresolv endif if BUILD_WITH_LIBPTHREAD -collectd_LDFLAGS += -lpthread +collectd_LDADD += -lpthread endif if BUILD_WITH_LIBKSTAT -collectd_LDFLAGS += -lkstat +collectd_LDADD += -lkstat endif if BUILD_WITH_LIBDEVINFO -collectd_LDFLAGS += -ldevinfo +collectd_LDADD += -ldevinfo endif +# The daemon needs to call sg_init, so we need to link it against libstatgrab, +# too. -octo if BUILD_WITH_LIBSTATGRAB -if BUILD_WITH_LIBKVM -collectd_LDFLAGS += -lkvm -endif -if BUILD_WITH_LIBDEVSTAT -collectd_LDFLAGS += -ldevstat +collectd_CFLAGS += $(BUILD_WITH_LIBSTATGRAB_CFLAGS) +collectd_LDADD += $(BUILD_WITH_LIBSTATGRAB_LDFLAGS) endif -collectd_LDFLAGS += -lstatgrab -endif - -collectd_LDADD = -collectd_DEPENDENCIES = if BUILD_WITH_OWN_LIBOCONFIG collectd_LDADD += $(LIBLTDL) liboconfig/liboconfig.la collectd_DEPENDENCIES += $(LIBLTDL) liboconfig/liboconfig.la else -collectd_LDFLAGS += -loconfig +collectd_LDADD += -loconfig endif collectd_nagios_SOURCES = collectd-nagios.c @@ -232,25 +231,23 @@ endif if BUILD_PLUGIN_INTERFACE pkglib_LTLIBRARIES += interface.la interface_la_SOURCES = interface.c +interface_la_CFLAGS = interface_la_LDFLAGS = -module -avoid-version +interface_la_LIBADD = collectd_LDADD += "-dlopen" interface.la collectd_DEPENDENCIES += interface.la +if BUILD_WITH_LIBSTATGRAB +interface_la_CFLAGS += $(BUILD_WITH_LIBSTATGRAB_CFLAGS) +interface_la_LIBADD += $(BUILD_WITH_LIBSTATGRAB_LDFLAGS) +else if BUILD_WITH_LIBKSTAT interface_la_LDFLAGS += -lkstat endif if BUILD_WITH_LIBDEVINFO interface_la_LDFLAGS += -ldevinfo -endif -if BUILD_WITH_LIBSTATGRAB -if BUILD_WITH_LIBKVM -interface_la_LDFLAGS += -lkvm -endif -if BUILD_WITH_LIBDEVSTAT -interface_la_LDFLAGS += -ldevstat -endif -interface_la_LDFLAGS += -lstatgrab -endif -endif +endif # BUILD_WITH_LIBDEVINFO +endif # !BUILD_WITH_LIBSTATGRAB +endif # BUILD_PLUGIN_INTERFACE if BUILD_PLUGIN_IPTABLES pkglib_LTLIBRARIES += iptables.la @@ -279,19 +276,16 @@ endif if BUILD_PLUGIN_LOAD pkglib_LTLIBRARIES += load.la load_la_SOURCES = load.c +load_la_CFLAGS = load_la_LDFLAGS = -module -avoid-version +load_la_LIBADD = collectd_LDADD += "-dlopen" load.la collectd_DEPENDENCIES += load.la if BUILD_WITH_LIBSTATGRAB -if BUILD_WITH_LIBKVM -load_la_LDFLAGS += -lkvm -endif -if BUILD_WITH_LIBDEVSTAT -load_la_LDFLAGS += -ldevstat -endif -load_la_LDFLAGS += -lstatgrab -endif -endif +load_la_CFLAGS += $(BUILD_WITH_LIBSTATGRAB_CFLAGS) +load_la_LIBADD += $(BUILD_WITH_LIBSTATGRAB_LDFLAGS) +endif # BUILD_WITH_LIBSTATGRAB +endif # BUILD_PLUGIN_LOAD if BUILD_PLUGIN_LOGFILE pkglib_LTLIBRARIES += logfile.la @@ -328,23 +322,20 @@ endif if BUILD_PLUGIN_MEMORY pkglib_LTLIBRARIES += memory.la memory_la_SOURCES = memory.c +memory_la_CFLAGS = memory_la_LDFLAGS = -module -avoid-version +memory_la_LIBADD = collectd_LDADD += "-dlopen" memory.la collectd_DEPENDENCIES += memory.la if BUILD_WITH_LIBKSTAT -memory_la_LDFLAGS += -lkstat +memory_la_LIBADD += -lkstat endif if BUILD_WITH_LIBDEVINFO -memory_la_LDFLAGS += -ldevinfo +memory_la_LIBADD += -ldevinfo endif if BUILD_WITH_LIBSTATGRAB -if BUILD_WITH_LIBKVM -memory_la_LDFLAGS += -lkvm -endif -if BUILD_WITH_LIBDEVSTAT -memory_la_LDFLAGS += -ldevstat -endif -memory_la_LDFLAGS += -lstatgrab +memory_la_CFLAGS += $(BUILD_WITH_LIBSTATGRAB_CFLAGS) +memory_la_LIBADD += $(BUILD_WITH_LIBSTATGRAB_LDFLAGS) endif endif @@ -518,23 +509,23 @@ endif if BUILD_PLUGIN_SWAP pkglib_LTLIBRARIES += swap.la swap_la_SOURCES = swap.c +swap_la_CFLAGS = swap_la_LDFLAGS = -module -avoid-version +swap_la_LIBADD = collectd_LDADD += "-dlopen" swap.la collectd_DEPENDENCIES += swap.la if BUILD_WITH_LIBKSTAT -swap_la_LDFLAGS += -lkstat +swap_la_LIBADD += -lkstat endif if BUILD_WITH_LIBDEVINFO -swap_la_LDFLAGS += -ldevinfo +swap_la_LIBADD += -ldevinfo endif if BUILD_WITH_LIBKVM -swap_la_LDFLAGS += -lkvm +swap_la_LIBADD += -lkvm endif if BUILD_WITH_LIBSTATGRAB -if BUILD_WITH_LIBDEVSTAT -swap_la_LDFLAGS += -ldevstat -endif -swap_la_LDFLAGS += -lstatgrab +swap_la_CFLAGS += $(BUILD_WITH_LIBSTATGRAB_CFLAGS) +swap_la_LIBADD += $(BUILD_WITH_LIBSTATGRAB_LDFLAGS) endif endif