np_mysqlclient.m4 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. # np_mysqlclient.m4
  2. dnl Copyright (C) 2007-2014 Nagios Plugins Team
  3. dnl This file is free software; the Nagios Plugin Team
  4. dnl gives unlimited permission to copy and/or distribute it,
  5. dnl with or without modifications, as long as this notice is preserved.
  6. dnl Test for mysql availability using mysql_config
  7. dnl Uses --with-mysql= yes(autodetection - default) | no | path
  8. dnl Sets 4 variables:
  9. dnl with_mysql = path/to/mysql_config (if found and can compile mysqlclient) or "no"
  10. dnl np_mysql_include = flags for include, from mysql_config --include (will be guessed as $with_mysql/include if --include not found)
  11. dnl np_mysql_libs = flags for libs, from mysql_config --libs
  12. dnl np_mysql_cflags = flags for cflags, from mysql_config --cflags
  13. dnl Also sets in config.h:
  14. dnl HAVE_MYSQLCLIENT
  15. dnl Copile your code with:
  16. dnl $(CC) $(np_mysql_include) code.c $(np_mysql_libs)
  17. AC_DEFUN([np_mysqlclient],
  18. [
  19. AC_ARG_WITH(mysql,
  20. AS_HELP_STRING([--with-mysql=DIR],
  21. [Locates mysql libraries. Expects DIR/bin/mysql_config. Default to search for mysql_config in PATH]),
  22. with_mysql=$withval,
  23. with_mysql=yes)
  24. if test "x$with_mysql" != "xno" ; then
  25. if test "x$with_mysql" = "xyes" ; then
  26. AC_PATH_PROG(np_mysql_config, mysql_config)
  27. else
  28. if test -x $with_mysql/bin/mysql_config ; then
  29. np_mysql_config="$with_mysql/bin/mysql_config"
  30. fi
  31. fi
  32. if test -z "$np_mysql_config"; then
  33. with_mysql="no"
  34. else
  35. np_mysql_include="`$np_mysql_config --include`"
  36. # Mysql 3 does not support --include. --cflags should be sufficient
  37. if test $? -ne 0; then
  38. np_mysql_include="-I$with_mysql/include" # Guessed location
  39. fi
  40. np_mysql_libs="`$np_mysql_config --libs`"
  41. np_mysql_cflags="`$np_mysql_config --cflags`"
  42. # On Solaris, cflags may contain -xstrconst, which is not acceptable to the
  43. # gcc compiler. In this case, use the include flags as the cflags
  44. echo $np_mysql_cflags | grep -- -xstrconst > /dev/null 2> /dev/null
  45. if test $? -eq 0 -a "$CC" = "gcc" ; then
  46. np_mysql_cflags="`$np_mysql_config --include`"
  47. fi
  48. dnl Test a mysql_init. Some systems have mysql_config, but no headers
  49. _savedcppflags="$CPPFLAGS"
  50. CPPFLAGS="$CPPFLAGS $np_mysql_include"
  51. dnl Putting $np_mysql_libs as other libraries ensures that all mysql dependencies are linked in
  52. dnl Although -lmysqlclient is duplicated, it is not a problem
  53. AC_CHECK_LIB([mysqlclient], [mysql_init], [
  54. with_mysql=$np_mysql_config
  55. AC_DEFINE(HAVE_MYSQLCLIENT, 1, [Defined if mysqlclient is found and can compile])
  56. ], [with_mysql=no], [$np_mysql_libs])
  57. CPPFLAGS=$_savedcppflags
  58. fi
  59. fi
  60. ])
  61. dnl Will take $1, find last occurrence of -LDIR and add DIR to LD_RUN_PATH
  62. AC_DEFUN([np_add_to_runpath],
  63. [
  64. dnl Need [[ ]] so autoconf gives us just one set
  65. np_libdir=`echo "$1" | sed -e 's/.*-L\([[^ ]]*\) .*/\1/'`
  66. if test "x$np_libdir" != x ; then
  67. LD_RUN_PATH="${np_libdir}${LD_RUN_PATH:+:}${LD_RUN_PATH}"
  68. fi
  69. ])