Code

build system: Use `mysql_config' to find the appropriate flags for MySQL.
authorFlorian Forster <octo@huhu.verplant.org>
Fri, 24 Aug 2007 10:12:23 +0000 (12:12 +0200)
committerFlorian Forster <octo@huhu.verplant.org>
Fri, 24 Aug 2007 10:12:23 +0000 (12:12 +0200)
configure.in
src/Makefile.am

index 41bb7097b519be3c61862720be1071edb1880c66..14595b39f91512b7d150ad16979daddfb3156ea6 100644 (file)
@@ -1009,12 +1009,24 @@ AC_DEFINE_UNQUOTED(COLLECT_LM_SENSORS, [$collect_lm_sensors],
        [Wether or not to use sensors library])
 AM_CONDITIONAL(BUILD_WITH_LM_SENSORS, test "x$with_lm_sensors" = "xyes")
 
+with_mysql_config="mysql_config"
+with_mysql_prefix=0
+with_mysql_cflags=""
+with_mysql_libs=""
 AC_ARG_WITH(libmysql, [AS_HELP_STRING([--with-libmysql@<:@=PREFIX@:>@], [Path to libmysql.])],
 [
        if test "x$withval" != "xno" && test "x$withval" != "xyes"
        then
-               LDFLAGS="$LDFLAGS -L$withval/lib"
-               CPPFLAGS="$CPPFLAGS -I$withval/include"
+               if test -x "$withval/bin/mysql_config"
+               then
+                       with_mysql_config="$withval/bin/mysql_config"
+                       with_mysql_prefix=1
+               fi
+       fi
+       if test "x$withval" = "xno"
+       then
+               with_libmysql="no"
+       else
                with_libmysql="yes"
        fi
 ],
@@ -1023,26 +1035,37 @@ AC_ARG_WITH(libmysql, [AS_HELP_STRING([--with-libmysql@<:@=PREFIX@:>@], [Path to
 ])
 if test "x$with_libmysql" = "xyes"
 then
-       AC_CHECK_LIB(mysqlclient, mysql_init,
-       [
-               AC_DEFINE(HAVE_LIBMYSQLCLIENT, 1, [Define to 1 if you have the mysqlclient library (-lmysqlclient).])
-       ], [with_libmysql="no (libmysql not found)"])
+       with_mysql_cflags=`$with_mysql_config --cflags 2>/dev/null`
+       mysql_config_status=$?
+
+       if test $mysql_config_status -ne 0
+       then
+               with_libmysql="no"
+       else
+               SAVE_CFLAGS=$CFLAGS
+               CFLAGS="$CFLAGS $with_mysql_cflags"
+
+               AC_CHECK_HEADERS(mysql/mysql.h, [], [with_libmysql="no (mysql/mysql.h not found)"], [])
+
+               CFLAGS="$SAVE_CFLAGS"
+       fi
 fi
 if test "x$with_libmysql" = "xyes"
 then
-       AC_CHECK_HEADERS(mysql/mysql.h,
+       with_mysql_libs=`$with_mysql_config --libs 2>/dev/null`
+       AC_CHECK_LIB(mysqlclient, mysql_init,
        [
-               AC_DEFINE(HAVE_MYSQL_MYSQL_H, 1, [Define to 1 if you have the <mysql/mysql.h> header file.])
-       ], [with_libmysql="no (mysql/mysql.h not found)"])
+               AC_DEFINE(HAVE_LIBMYSQLCLIENT, 1,
+                         [Define to 1 if you have the mysqlclient library (-lmysqlclient).])
+       ], [with_libmysql="no (libmysql not found)"])
 fi
 if test "x$with_libmysql" = "xyes"
 then
-       collect_libmysql=1
-else
-       collect_libmysql=0
+       BUILD_WITH_LIBMYSQL_CFLAGS="$with_mysql_cflags"
+       BUILD_WITH_LIBMYSQL_LIBS="$with_mysql_libs"
+       AC_SUBST(BUILD_WITH_LIBMYSQL_CFLAGS)
+       AC_SUBST(BUILD_WITH_LIBMYSQL_LIBS)
 fi
-AC_DEFINE_UNQUOTED(COLLECT_LIBMYSQL, [$collect_libmysql],
-       [Wether or not to use mysql library])
 AM_CONDITIONAL(BUILD_WITH_LIBMYSQL, test "x$with_libmysql" = "xyes")
 
 with_own_liboconfig="no"
index f3f259b6379e5982bc59d22a8f21fd0b50662ab6..a75a178598d36a05a080ff7362bbf2cb541a5719 100644 (file)
@@ -352,10 +352,13 @@ if BUILD_MODULE_MYSQL
 pkglib_LTLIBRARIES += mysql.la
 mysql_la_SOURCES = mysql.c
 mysql_la_LDFLAGS = -module -avoid-version
+mysql_la_CFLAGS =
+mysql_la_LIBADD =
+collectd_LDADD += "-dlopen" mysql.la
 if BUILD_WITH_LIBMYSQL
-mysql_la_LDFLAGS += -lmysqlclient
+mysql_la_CFLAGS += $(BUILD_WITH_LIBMYSQL_CFLAGS)
+mysql_la_LIBADD += $(BUILD_WITH_LIBMYSQL_LIBS)
 endif
-collectd_LDADD += "-dlopen" mysql.la
 collectd_DEPENDENCIES += mysql.la
 endif