mysql_config --cflags sometimes lies to us, if it was built
authoraland <aland>
Mon, 12 May 2008 11:50:39 +0000 (11:50 +0000)
committeraland <aland>
Mon, 12 May 2008 11:50:39 +0000 (11:50 +0000)
with a different compiler than we're using now.
e.g. a binary MySQL package was installed using CC one, and
we're now trying to build the server with CC two.  In that case,
--include will work (hopefully), while --cflags will produce
compiler options for the first CC, which won't work on the
second CC.

src/modules/rlm_sql/drivers/rlm_sql_mysql/configure
src/modules/rlm_sql/drivers/rlm_sql_mysql/configure.in

index b767c3a..7030059 100755 (executable)
@@ -3447,8 +3447,8 @@ echo "$as_me: WARNING: MySQL libraries not found. Use --with-mysql-lib-dir=<path
        mysql_cflags="$(mysql_config --cflags)"
        old_CFLAGS="$CFLAGS"
        CFLAGS="$CFLAGS $mysql_cflags"
-       { echo "$as_me:$LINENO: checking for mysql.h (using mysql_config)" >&5
-echo $ECHO_N "checking for mysql.h (using mysql_config)... $ECHO_C" >&6; }
+       { echo "$as_me:$LINENO: checking for mysql.h (using mysql_config --cflags)" >&5
+echo $ECHO_N "checking for mysql.h (using mysql_config --cflags)... $ECHO_C" >&6; }
        cat >conftest.$ac_ext <<_ACEOF
 /* confdefs.h.  */
 _ACEOF
@@ -3502,7 +3502,67 @@ _ACEOF
        else
            { echo "$as_me:$LINENO: result: no" >&5
 echo "${ECHO_T}no" >&6; }
-       fi
+
+           mysql_cflags="$(mysql_config --include)"
+           CFLAGS="$old_CFLAGS $mysql_cflags"
+           { echo "$as_me:$LINENO: checking for mysql.h (using mysql_config --include)" >&5
+echo $ECHO_N "checking for mysql.h (using mysql_config --include)... $ECHO_C" >&6; }
+           cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+#include <mysql.h>
+int
+main ()
+{
+int a = 1;
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (ac_try="$ac_compile"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_compile") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && {
+        test -z "$ac_c_werror_flag" ||
+        test ! -s conftest.err
+       } && test -s conftest.$ac_objext; then
+  have_mysql_h=yes
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+
+fi
+
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+           if test "x$have_mysql_h" = "xyes"; then
+               { echo "$as_me:$LINENO: result: yes" >&5
+echo "${ECHO_T}yes" >&6; }
+
+cat >>confdefs.h <<\_ACEOF
+#define HAVE_MYSQL_H
+_ACEOF
+
+               SMART_CFLAGS="$SMART_CFLAGS $mysql_cflags"
+           else
+               { echo "$as_me:$LINENO: result: no" >&5
+echo "${ECHO_T}no" >&6; }
+           fi
+        fi
+
        CFLAGS="$old_CFLAGS"
     fi
     if test "x$have_mysql_h" != "xyes"; then
index 71581ad..c0bf6dd 100644 (file)
@@ -163,7 +163,7 @@ if test x$with_[]modname != xno; then
        mysql_cflags="$(mysql_config --cflags)"
        old_CFLAGS="$CFLAGS"
        CFLAGS="$CFLAGS $mysql_cflags"
-       AC_MSG_CHECKING([for mysql.h (using mysql_config)])
+       AC_MSG_CHECKING([for mysql.h (using mysql_config --cflags)])
        AC_TRY_COMPILE([#include <mysql.h>], [int a = 1;],
                       have_mysql_h=yes)
        if test "x$have_mysql_h" = "xyes"; then
@@ -172,7 +172,21 @@ if test x$with_[]modname != xno; then
            SMART_CFLAGS="$SMART_CFLAGS $mysql_cflags"
        else
            AC_MSG_RESULT(no)
-       fi
+
+           mysql_cflags="$(mysql_config --include)"
+           CFLAGS="$old_CFLAGS $mysql_cflags"
+           AC_MSG_CHECKING([for mysql.h (using mysql_config --include)])
+           AC_TRY_COMPILE([#include <mysql.h>], [int a = 1;],
+                          have_mysql_h=yes)
+           if test "x$have_mysql_h" = "xyes"; then
+               AC_MSG_RESULT(yes)
+               AC_DEFINE(HAVE_MYSQL_H, [], [Define if you have <mysql.h>])
+               SMART_CFLAGS="$SMART_CFLAGS $mysql_cflags"
+           else
+               AC_MSG_RESULT(no)
+           fi
+        fi
+
        CFLAGS="$old_CFLAGS"
     fi
     if test "x$have_mysql_h" != "xyes"; then