I tested this on Fedora Core 5 and RHEL4 (both x86_64) and it appeared to work fine with packaged version of MySQL 5.0 and 4.1. However, environments vary wildly, so it it would be good to get some feedback before going ahead with the commit.

I'm a little bit worried that --libs_r may put a bit too much into APRUTIL_LDFLAGS (e.g. on FC5 this turns out to be: "-L/usr/lib64/mysql -lmysqlclient_r -lz -lpthread -lcrypt -lnsl -lm -lpthread -L/usr/lib64 -lssl -lcrypto"). Not sure if things like that can hurt the builds...

The logic behind the patch is supposed to be: if there is mysql_config we can see, trust it to do the right thing. Otherwise, try using what we had before.

There is also a fix for -I$withval/include/mysql where $withval is "yes", which was obviously incorrect (i.e. not many people will have MySQL header files in "yes/include/mysql" directory :-).

PS. This will not work for MySQL 3.x, as it doesn't have "mysql_config --include" call, but "mysql_config --cflags" instead. However, I don't think we support MySQL that far back anyway. If that's wrong, we can test if mysql_config supports the --include option.

--
Bojan
Index: build/dbd.m4
===================================================================
--- build/dbd.m4	(revision 408512)
+++ build/dbd.m4	(working copy)
@@ -77,24 +77,40 @@
   ], [
     apu_have_mysql=0
     if test "$withval" = "yes"; then
+      AC_PATH_PROG([mysqlconfig],[mysql_config])
+      if test "x$$mysqlconfig" != "x"; then
+        CPPFLAGS="`$mysqlconfig --include`"
+        LDFLAGS="`$mysqlconfig --libs_r`"
+      fi
       AC_CHECK_HEADER(mysql.h, AC_CHECK_LIB(mysqlclient_r, mysql_init, [apu_have_mysql=1]))
       if test "$apu_have_mysql" == "0"; then
         AC_CHECK_HEADER(mysql/mysql.h, AC_CHECK_LIB(mysqlclient_r, mysql_init, [apu_have_mysql=1]))
         if test "$apu_have_mysql" != "0"; then
-          APR_ADDTO(APRUTIL_INCLUDES, [-I$withval/include/mysql])
+          APR_ADDTO(APRUTIL_INCLUDES, [-I/usr/include/mysql])
         fi
+      else
+        if test "x$$mysqlconfig" != "x"; then
+          APR_ADDTO(APRUTIL_INCLUDES, [$CPPFLAGS])
+          APR_ADDTO(APRUTIL_LDFLAGS, [$LDFLAGS])
+        fi
       fi
     elif test "$withval" = "no"; then
       apu_have_mysql=0
     else
-      CPPFLAGS="-I$withval/include"
-      LDFLAGS="-L$withval/lib "
+      AC_PATH_PROG([mysqlconfig],[mysql_config],,[$withval/bin])
+      if test "x$$mysqlconfig" != "x"; then
+        CPPFLAGS="`$mysqlconfig --include`"
+        LDFLAGS="`$mysqlconfig --libs_r`"
+      else
+        CPPFLAGS="-I$withval/include"
+        LDFLAGS="-L$withval/lib "
+      fi
 
       AC_MSG_NOTICE(checking for mysql in $withval)
       AC_CHECK_HEADER(mysql.h, AC_CHECK_LIB(mysqlclient_r, mysql_init, [apu_have_mysql=1]))
       if test "$apu_have_mysql" != "0"; then
-        APR_ADDTO(APRUTIL_LDFLAGS, [-L$withval/lib])
-        APR_ADDTO(APRUTIL_INCLUDES, [-I$withval/include])
+        APR_ADDTO(APRUTIL_INCLUDES, [$CPPFLAGS])
+        APR_ADDTO(APRUTIL_LDFLAGS, [$LDFLAGS])
       fi
 
       if test "$apu_have_mysql" != "1"; then
@@ -107,7 +123,18 @@
     fi
   ], [
     apu_have_mysql=0
+    AC_PATH_PROG([mysqlconfig],[mysql_config])
+    if test "x$$mysqlconfig" != "x"; then
+      CPPFLAGS="`$mysqlconfig --include`"
+      LDFLAGS="`$mysqlconfig --libs_r`"
+    fi
     AC_CHECK_HEADER(mysql.h, AC_CHECK_LIB(mysqlclient_r, mysql_init, [apu_have_mysql=1]))
+    if test "$apu_have_mysql" != "0"; then
+      if test "x$$mysqlconfig" != "x"; then
+        APR_ADDTO(APRUTIL_INCLUDES, [$CPPFLAGS])
+        APR_ADDTO(APRUTIL_LDFLAGS, [$LDFLAGS])
+      fi
+    fi
   ])
 
   AC_SUBST(apu_have_mysql)

Reply via email to