Merge pull request #1844 from rubenk/sigrok
authorRuben Kerkhof <ruben@rubenkerkhof.com>
Sun, 7 Aug 2016 09:45:05 +0000 (11:45 +0200)
committerGitHub <noreply@github.com>
Sun, 7 Aug 2016 09:45:05 +0000 (11:45 +0200)
sigrok: use pkg-config to find library

1  2 
configure.ac
src/Makefile.am

diff --combined configure.ac
@@@ -1,5 -1,4 +1,5 @@@
  dnl Process this file with autoconf to produce a configure script.
 +AC_PREREQ([2.60])
  AC_INIT([collectd],[m4_esyscmd(./version-gen.sh)])
  AC_CONFIG_SRCDIR(src/target_set.c)
  AC_CONFIG_HEADERS(src/config.h)
@@@ -748,23 -747,6 +748,23 @@@ AC_CHECK_HEADERS(net/pfvar.h
  have_termios_h="no"
  AC_CHECK_HEADERS(termios.h, [have_termios_h="yes"])
  
 +# For cpusleep plugin
 +AC_CACHE_CHECK([whether clock_boottime and clock_monotonic are supported],
 +                     [c_cv_have_clock_boottime_monotonic],
 +                     AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
 +[[
 +#include <time.h>
 +]],
 +[[
 + struct timespec b, m;
 + clock_gettime(CLOCK_BOOTTIME, &b );
 + clock_gettime(CLOCK_MONOTONIC, &m );
 +]]
 +                     )],
 +                     [c_cv_have_clock_boottime_monotonic="yes"],
 +                     [c_cv_have_clock_boottime_monotonic="no"]))
 +
 +
  # For the turbostat plugin
  have_asm_msrindex_h="no"
  AC_CHECK_HEADERS(asm/msr-index.h, [have_asm_msrindex_h="yes"])
@@@ -804,7 -786,7 +804,7 @@@ AC_HEADER_TIM
  #
  # Checks for library functions.
  #
 -AC_CHECK_FUNCS(gettimeofday select strdup strtol getaddrinfo getnameinfo strchr memcpy strstr strcmp strncmp strncpy strlen strncasecmp strcasecmp openlog closelog sysconf setenv if_indextoname setlocale)
 +AC_CHECK_FUNCS(gettimeofday select strdup strtol getaddrinfo getnameinfo strchr memcpy strstr strcmp strncmp strncpy strlen strncasecmp strcasecmp openlog closelog sysconf setenv if_indextoname setlocale asprintf)
  
  AC_FUNC_STRERROR_R
  
@@@ -1461,15 -1443,15 +1461,15 @@@ if test "x$have_getmntent" = "xc"; the
  fi
  if test "x$have_getmntent" = "xsun"; then
        AC_DEFINE(HAVE_SUN_GETMNTENT, 1,
 -                [Define if the function getmntent exists. It's the version from libsun.])
 +                [Define if the function getmntent exists. It is the version from libsun.])
  fi
  if test "x$have_getmntent" = "xseq"; then
        AC_DEFINE(HAVE_SEQ_GETMNTENT, 1,
 -                [Define if the function getmntent exists. It's the version from libseq.])
 +                [Define if the function getmntent exists. It is the version from libseq.])
  fi
  if test "x$have_getmntent" = "xgen"; then
        AC_DEFINE(HAVE_GEN_GETMNTENT, 1,
 -                [Define if the function getmntent exists. It's the version from libgen.])
 +                [Define if the function getmntent exists. It is the version from libgen.])
  fi
  
  # Check for htonll
@@@ -2395,6 -2377,11 +2395,6 @@@ AC_ARG_WITH(libiptc, [AS_HELP_STRING([-
        fi
  ])
  
 -if test "x$with_libiptc" = "xpkgconfig" && test "x$PKG_CONFIG" = "x"
 -then
 -      with_libiptc="no (Don't have pkg-config)"
 -fi
 -
  if test "x$with_libiptc" = "xpkgconfig"
  then
        $PKG_CONFIG --exists 'libiptc' 2>/dev/null
@@@ -2832,6 -2819,13 +2832,6 @@@ AC_ARG_WITH(libmodbus, [AS_HELP_STRING(
  # configure using pkg-config
  if test "x$with_libmodbus" = "xuse_pkgconfig"
  then
 -      if test "x$PKG_CONFIG" = "x"
 -      then
 -              with_libmodbus="no (Don't have pkg-config)"
 -      fi
 -fi
 -if test "x$with_libmodbus" = "xuse_pkgconfig"
 -then
        AC_MSG_NOTICE([Checking for libmodbus using $PKG_CONFIG])
        $PKG_CONFIG --exists 'libmodbus' 2>/dev/null
        if test $? -ne 0
@@@ -3122,6 -3116,10 +3122,6 @@@ AC_ARG_WITH(libmnl, [AS_HELP_STRING([--
         with_libmnl="no (Linux only library)"
   fi
  ])
 -if test "x$PKG_CONFIG" = "x"
 -then
 -      with_libmnl="no (Don't have pkg-config)"
 -fi
  if test "x$with_libmnl" = "xyes"
  then
        if $PKG_CONFIG --exists libmnl 2>/dev/null; then
@@@ -3657,7 -3655,7 +3657,7 @@@ the
    SAVE_CFLAGS="$CFLAGS"
    SAVE_LIBS="$LIBS"
  dnl ARCHFLAGS="" -> disable multi -arch on OSX (see Config_heavy.pl:fetch_string)
 -  PERL_CFLAGS=`ARCHFLAGS="" $perl_interpreter -MExtUtils::Embed -e ccopts`
 +  PERL_CFLAGS=`ARCHFLAGS="" $perl_interpreter -MExtUtils::Embed -e perl_inc`
    PERL_LIBS=`ARCHFLAGS="" $perl_interpreter -MExtUtils::Embed -e ldopts`
    CFLAGS="$CFLAGS $PERL_CFLAGS"
    LIBS="$LIBS $PERL_LIBS"
  AM_CONDITIONAL(BUILD_WITH_LM_SENSORS, test "x$with_libsensors" = "xyes")
  # }}}
  
- # --with-libsigrok {{{
- with_libsigrok_cflags=""
- with_libsigrok_ldflags=""
- AC_ARG_WITH(libsigrok, [AS_HELP_STRING([--with-libsigrok@<:@=PREFIX@:>@], [Path to libsigrok.])],
- [
-       if test "x$withval" = "xno"
-       then
-               with_libsigrok="no"
-       else
-               with_libsigrok="yes"
-               if test "x$withval" != "xyes"
-               then
-                       with_libsigrok_cflags="-I$withval/include"
-                       with_libsigrok_ldflags="-L$withval/lib"
-               fi
-       fi
- ],[with_libsigrok="yes"])
- # libsigrok has a glib dependency
- if test "x$with_libsigrok" = "xyes"
- then
- m4_ifdef([AM_PATH_GLIB_2_0],
-       [
-        AM_PATH_GLIB_2_0([2.28.0],
-               [with_libsigrok_cflags="$with_libsigrok_cflags $GLIB_CFLAGS"; with_libsigrok_ldflags="$with_libsigrok_ldflags $GLIB_LIBS"])
-       ],
-       [
-        with_libsigrok="no (glib not available)"
-       ]
+ # libsigrok {{{
+ AC_SUBST([LIBSIGROK_CFLAGS])
+ AC_SUBST([LIBSIGROK_LIBS])
+ PKG_CHECK_MODULES([LIBSIGROK], [libsigrok < 0.4],
+   [with_libsigrok="yes"],
+   [with_libsigrok="no (pkg-config could not find libsigrok)"]
  )
- fi
- # libsigrok headers
- if test "x$with_libsigrok" = "xyes"
- then
-       SAVE_CPPFLAGS="$CPPFLAGS"
-       CPPFLAGS="$CPPFLAGS $with_libsigrok_cflags"
-       AC_CHECK_HEADERS(libsigrok/libsigrok.h, [], [with_libsigrok="no (libsigrok/libsigrok.h not found)"])
-       CPPFLAGS="$SAVE_CPPFLAGS"
- fi
- # libsigrok library
- if test "x$with_libsigrok" = "xyes"
- then
-       SAVE_CPPFLAGS="$CPPFLAGS"
-       SAVE_LDFLAGS="$LDFLAGS"
-       CPPFLAGS="$CPPFLAGS $with_libsigrok_cflags"
-       LDFLAGS="$LDFLAGS $with_libsigrok_ldflags"
-       AC_CHECK_LIB(sigrok, sr_init,
-       [
-               AC_DEFINE(HAVE_LIBSIGROK, 1, [Define to 1 if you have the sigrok library (-lsigrok).])
-       ],
-       [with_libsigrok="no (libsigrok not found)"])
-       CPPFLAGS="$SAVE_CPPFLAGS"
-       LDFLAGS="$SAVE_LDFLAGS"
- fi
- if test "x$with_libsigrok" = "xyes"
- then
-       BUILD_WITH_LIBSIGROK_CFLAGS="$with_libsigrok_cflags"
-       BUILD_WITH_LIBSIGROK_LDFLAGS="$with_libsigrok_ldflags"
-       AC_SUBST(BUILD_WITH_LIBSIGROK_CFLAGS)
-       AC_SUBST(BUILD_WITH_LIBSIGROK_LDFLAGS)
- fi
- AM_CONDITIONAL(BUILD_WITH_LIBSIGROK, test "x$with_libsigrok" = "xyes")
  # }}}
  
  # --with-libstatgrab {{{
@@@ -4609,16 -4546,23 +4548,16 @@@ AC_ARG_WITH(libstatgrab, [AS_HELP_STRIN
  if test "x$with_libstatgrab" = "xyes" \
    && test "x$with_libstatgrab_pkg_config" = "xyes"
  then
 -  if test "x$PKG_CONFIG" != "x"
 +  AC_MSG_CHECKING([pkg-config for libstatgrab])
 +  temp_result="found"
 +  $PKG_CONFIG --exists libstatgrab 2>/dev/null
 +  if test "$?" != "0"
    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"
 -      with_libstatgrab="no (pkg-config doesn't know libstatgrab)"
 -      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"
 +    with_libstatgrab="no (pkg-config doesn't know libstatgrab)"
 +    temp_result="not found"
    fi
 +  AC_MSG_RESULT([$temp_result])
  fi
  
  if test "x$with_libstatgrab" = "xyes" \
  # configure using pkg-config
  if test "x$with_libupsclient" = "xuse_pkgconfig"
  then
 -      if test "x$PKG_CONFIG" = "x"
 -      then
 -              with_libupsclient="no (Don't have pkg-config)"
 -      fi
 -fi
 -if test "x$with_libupsclient" = "xuse_pkgconfig"
 -then
        AC_MSG_NOTICE([Checking for libupsclient using $PKG_CONFIG])
        $PKG_CONFIG --exists 'libupsclient' 2>/dev/null
        if test $? -ne 0
@@@ -5238,6 -5189,13 +5177,6 @@@ AC_ARG_WITH(libvarnish, [AS_HELP_STRING
  # configure using pkg-config
  if test "x$with_libvarnish" = "xuse_pkgconfig"
  then
 -      if test "x$PKG_CONFIG" = "x"
 -      then
 -              with_libvarnish="no (Don't have pkg-config)"
 -      fi
 -fi
 -if test "x$with_libvarnish" = "xuse_pkgconfig"
 -then
        AC_MSG_NOTICE([Checking for varnishapi using $PKG_CONFIG])
        $PKG_CONFIG --exists 'varnishapi' 2>/dev/null
        if test $? -ne 0
@@@ -5297,20 -5255,23 +5236,20 @@@ with_libxml2_ldflags="
  with_libvirt="no (pkg-config isn't available)"
  with_libvirt_cflags=""
  with_libvirt_ldflags=""
 -if test "x$PKG_CONFIG" != "x"
 +$PKG_CONFIG --exists 'libxml-2.0' 2>/dev/null
 +if test "$?" = "0"
  then
 -      $PKG_CONFIG --exists 'libxml-2.0' 2>/dev/null
 -      if test "$?" = "0"
 -      then
 -              with_libxml2="yes"
 -      else
 -              with_libxml2="no (pkg-config doesn't know libxml-2.0)"
 -      fi
 +      with_libxml2="yes"
 +else
 +      with_libxml2="no (pkg-config doesn't know libxml-2.0)"
 +fi
  
 -      $PKG_CONFIG --exists libvirt 2>/dev/null
 -      if test "$?" = "0"
 -      then
 -              with_libvirt="yes"
 -      else
 -              with_libvirt="no (pkg-config doesn't know libvirt)"
 -      fi
 +$PKG_CONFIG --exists libvirt 2>/dev/null
 +if test "$?" = "0"
 +then
 +      with_libvirt="yes"
 +else
 +      with_libvirt="no (pkg-config doesn't know libvirt)"
  fi
  if test "x$with_libxml2" = "xyes"
  then
@@@ -5409,6 -5370,17 +5348,6 @@@ with_libopenipmipthread="yes
  with_libopenipmipthread_cflags=""
  with_libopenipmipthread_libs=""
  
 -AC_MSG_CHECKING([for pkg-config])
 -temp_result="no"
 -if test "x$PKG_CONFIG" = "x"
 -then
 -      with_libopenipmipthread="no"
 -      temp_result="no"
 -else
 -      temp_result="$PKG_CONFIG"
 -fi
 -AC_MSG_RESULT([$temp_result])
 -
  if test "x$with_libopenipmipthread" = "xyes"
  then
        AC_MSG_CHECKING([for libOpenIPMIpthread])
@@@ -5676,7 -5648,6 +5615,7 @@@ plugin_conntrack="no
  plugin_contextswitch="no"
  plugin_cpu="no"
  plugin_cpufreq="no"
 +plugin_cpusleep="no"
  plugin_curl_json="no"
  plugin_curl_xml="no"
  plugin_df="no"
        then
                plugin_turbostat="yes"
        fi
 +      
 +      if test "x$c_cv_have_clock_boottime_monotonic" = "xyes"
 +      then
 +              plugin_cpusleep="yes"
 +      fi
  fi
  
  if test "x$ac_system" = "xOpenBSD"
@@@ -6109,7 -6075,6 +6048,7 @@@ AC_PLUGIN([conntrack],           [$plug
  AC_PLUGIN([contextswitch],       [$plugin_contextswitch],   [context switch statistics])
  AC_PLUGIN([cpu],                 [$plugin_cpu],             [CPU usage statistics])
  AC_PLUGIN([cpufreq],             [$plugin_cpufreq],         [CPU frequency statistics])
 +AC_PLUGIN([cpusleep],            [$plugin_cpusleep],        [CPU sleep statistics])
  AC_PLUGIN([csv],                 [yes],                     [CSV output plugin])
  AC_PLUGIN([curl],                [$with_libcurl],           [CURL generic web statistics])
  AC_PLUGIN([curl_json],           [$plugin_curl_json],       [CouchDB statistics])
@@@ -6523,7 -6488,6 +6462,7 @@@ AC_MSG_RESULT([    conntrack . . . . . 
  AC_MSG_RESULT([    contextswitch . . . . $enable_contextswitch])
  AC_MSG_RESULT([    cpu . . . . . . . . . $enable_cpu])
  AC_MSG_RESULT([    cpufreq . . . . . . . $enable_cpufreq])
 +AC_MSG_RESULT([    cpusleep  . . . . . . $enable_cpusleep])
  AC_MSG_RESULT([    csv . . . . . . . . . $enable_csv])
  AC_MSG_RESULT([    curl  . . . . . . . . $enable_curl])
  AC_MSG_RESULT([    curl_json . . . . . . $enable_curl_json])
diff --combined src/Makefile.am
@@@ -27,21 -27,6 +27,21 @@@ noinst_LTLIBRARIES 
  check_PROGRAMS =
  TESTS =
  
 +noinst_LTLIBRARIES += libformat_json.la
 +libformat_json_la_SOURCES   = utils_format_json.c utils_format_json.h
 +libformat_json_la_CPPFLAGS  = $(AM_CPPFLAGS)
 +libformat_json_la_LDFLAGS   = $(AM_LDFLAGS)
 +libformat_json_la_LIBADD    =
 +if BUILD_WITH_LIBYAJL
 +libformat_json_la_CPPFLAGS += $(BUILD_WITH_LIBYAJL_CPPFLAGS)
 +libformat_json_la_LDFLAGS  += $(BUILD_WITH_LIBYAJL_LDFLAGS)
 +libformat_json_la_LIBADD   += $(BUILD_WITH_LIBYAJL_LIBS)
 +check_PROGRAMS += test_format_json
 +TESTS += test_format_json
 +test_format_json_SOURCES = utils_format_json_test.c testing.h
 +test_format_json_LDADD = libformat_json.la daemon/libmetadata.la daemon/libplugin_mock.la -lm
 +endif
 +
  noinst_LTLIBRARIES += liblatency.la
  liblatency_la_SOURCES = utils_latency.c utils_latency.h
  check_PROGRAMS += test_utils_latency
@@@ -156,10 -141,11 +156,10 @@@ pkglib_LTLIBRARIES += amqp.l
  amqp_la_SOURCES = amqp.c \
                  utils_cmd_putval.c utils_cmd_putval.h \
                  utils_parse_option.c utils_parse_option.h \
 -                utils_format_graphite.c utils_format_graphite.h \
 -                utils_format_json.c utils_format_json.h
 +                utils_format_graphite.c utils_format_graphite.h
  amqp_la_LDFLAGS = $(PLUGIN_LDFLAGS) $(BUILD_WITH_LIBRABBITMQ_LDFLAGS)
  amqp_la_CPPFLAGS = $(AM_CPPFLAGS) $(BUILD_WITH_LIBRABBITMQ_CPPFLAGS)
 -amqp_la_LIBADD = $(BUILD_WITH_LIBRABBITMQ_LIBS)
 +amqp_la_LIBADD = $(BUILD_WITH_LIBRABBITMQ_LIBS) libformat_json.la
  endif
  
  if BUILD_PLUGIN_APACHE
@@@ -293,12 -279,6 +293,12 @@@ cpufreq_la_SOURCES = cpufreq.
  cpufreq_la_LDFLAGS = $(PLUGIN_LDFLAGS)
  endif
  
 +if BUILD_PLUGIN_CPUSLEEP
 +pkglib_LTLIBRARIES += cpusleep.la
 +cpusleep_la_SOURCES = cpusleep.c
 +cpusleep_la_LDFLAGS = $(PLUGIN_LDFLAGS)
 +endif
 +
  if BUILD_PLUGIN_CSV
  pkglib_LTLIBRARIES += csv.la
  csv_la_SOURCES = csv.c
@@@ -977,9 -957,9 +977,9 @@@ endi
  if BUILD_PLUGIN_SIGROK
  pkglib_LTLIBRARIES += sigrok.la
  sigrok_la_SOURCES = sigrok.c
- sigrok_la_CFLAGS = $(AM_CFLAGS) $(BUILD_WITH_LIBSIGROK_CFLAGS)
- sigrok_la_LDFLAGS = $(PLUGIN_LDFLAGS) $(BUILD_WITH_LIBSIGROK_LDFLAGS)
- sigrok_la_LIBADD = -lsigrok
+ sigrok_la_CFLAGS = $(AM_CFLAGS) $(LIBSIGROK_CFLAGS)
+ sigrok_la_LDFLAGS = $(PLUGIN_LDFLAGS)
+ sigrok_la_LIBADD = $(LIBSIGROK_LIBS)
  endif
  
  if BUILD_PLUGIN_SMART
@@@ -1233,29 -1213,31 +1233,29 @@@ endi
  if BUILD_PLUGIN_WRITE_GRAPHITE
  pkglib_LTLIBRARIES += write_graphite.la
  write_graphite_la_SOURCES = write_graphite.c \
 -                        utils_format_graphite.c utils_format_graphite.h \
 -                        utils_format_json.c utils_format_json.h
 +                        utils_format_graphite.c utils_format_graphite.h
  write_graphite_la_LDFLAGS = $(PLUGIN_LDFLAGS)
 +write_graphite_la_LIBADD = libformat_json.la
  endif
  
  if BUILD_PLUGIN_WRITE_HTTP
  pkglib_LTLIBRARIES += write_http.la
  write_http_la_SOURCES = write_http.c \
 -                      utils_format_json.c utils_format_json.h \
                        utils_format_kairosdb.c utils_format_kairosdb.h
 -write_http_la_CFLAGS = $(AM_CFLAGS) $(BUILD_WITH_LIBCURL_CFLAGS)
  write_http_la_LDFLAGS = $(PLUGIN_LDFLAGS)
 -write_http_la_LIBADD = $(BUILD_WITH_LIBCURL_LIBS)
 +write_http_la_CFLAGS = $(AM_CFLAGS) $(BUILD_WITH_LIBCURL_CFLAGS)
 +write_http_la_LIBADD = $(BUILD_WITH_LIBCURL_LIBS) libformat_json.la
  endif
  
  if BUILD_PLUGIN_WRITE_KAFKA
  pkglib_LTLIBRARIES += write_kafka.la
  write_kafka_la_SOURCES = write_kafka.c \
                          utils_format_graphite.c utils_format_graphite.h \
 -                        utils_format_json.c utils_format_json.h \
                          utils_cmd_putval.c utils_cmd_putval.h \
                          utils_crc32.c utils_crc32.h
  write_kafka_la_CPPFLAGS = $(AM_CPPFLAGS) $(BUILD_WITH_LIBRDKAFKA_CPPFLAGS)
  write_kafka_la_LDFLAGS = $(PLUGIN_LDFLAGS) $(BUILD_WITH_LIBRDKAFKA_LDFLAGS)
 -write_kafka_la_LIBADD = $(BUILD_WITH_LIBRDKAFKA_LIBS)
 +write_kafka_la_LIBADD = $(BUILD_WITH_LIBRDKAFKA_LIBS) libformat_json.la
  endif
  
  if BUILD_PLUGIN_WRITE_LOG