]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
m4: Rewrite want_mysql.m4 to use pkg_config
authorKarl Fleischmann <karl.fleischmann@open-xchange.com>
Wed, 8 Jun 2022 12:12:15 +0000 (14:12 +0200)
committerKarl Fleischmann <karl.fleischmann@open-xchange.com>
Mon, 4 Jul 2022 09:43:26 +0000 (11:43 +0200)
Manually checking for headers/libraries requires the user to know and
pass non-default library-paths when configuring the project. Using
pkg_config simplifies the macro and automatically sets the
compiler/linker flags accordingly.

configure.ac
m4/want_mysql.m4

index bea523e94c130c55b46e88a239a86449a4ea346e..34b150cfb6ab1b132504381663e438f694995b78 100644 (file)
@@ -555,8 +555,6 @@ AC_SUBST(AUTH_CFLAGS)
 AC_SUBST(AUTH_LIBS)
 AC_SUBST(SQL_CFLAGS)
 AC_SUBST(SQL_LIBS)
-AC_SUBST(MYSQL_CFLAGS)
-AC_SUBST(MYSQL_LIBS)
 
 AC_SUBST(DICT_LIBS)
 AC_SUBST(CDB_LIBS)
index 824614fac3e5719c5d5a8e92df8a44690c656326..4916e84644875a9e59ba08a23ea7ebf97e9014fc 100644 (file)
@@ -1,89 +1,58 @@
 AC_DEFUN([DOVECOT_WANT_MYSQL], [
   have_mysql=no
-  AS_IF([test $want_mysql != no], [
-    AC_CHECK_PROG(MYSQL_CONFIG, mysql_config, mysql_config, missing)
-    AS_IF([test $MYSQL_CONFIG = missing], [
-       # based on code from PHP
-       MYSQL_LIBS="-lmysqlclient -lz -lm"
-       for i in /usr /usr/local /usr/local/mysql; do
-               for j in include include/mysql ""; do
-                       if test -r "$i/$j/mysql.h"; then
-                               MYSQL_INCLUDE="-I$i/$j"
-                       fi
-               done
-               for j in lib lib/mysql lib64 lib64/mysql ""; do
-                       if test -f "$i/$j/libmysqlclient.so" || test -f "$i/$j/libmysqlclient.a"; then
-                               MYSQL_LIBS="-L$i/$j -lmysqlclient -lz -lm"
-                       fi
-               done
-       done
-    ], [
-      MYSQL_INCLUDE="`$MYSQL_CONFIG --include`"
-      MYSQL_LIBS="`$MYSQL_CONFIG --libs`"
+
+  AS_IF([test "$want_mysql" != "no"], [
+    PKG_CHECK_MODULES([MYSQL], [mysqlclient], [have_mysql=yes], [
+      have_mysql=no
+
+      AS_IF([test "$want_mysql" = "yes"], [
+        AC_MSG_ERROR([cannot build with MySQL support: MySQL library (mysqlclient) not found])
+      ])
     ])
-  
-    old_LIBS=$LIBS
-    AS_IF([test "$MYSQL_LIBS" != ""], [
-      LIBS="$LIBS $MYSQL_LIBS"
+  ])
+
+  AS_IF([test "$have_mysql" != "no"], [
+    found_sql_drivers="$found_sql_drivers mysql"
+    AC_DEFINE(HAVE_MYSQL,, [Build with MySQL support])
+
+    AC_CHECK_LIB(mysqlclient, mysql_ssl_set, [
+      AC_DEFINE(HAVE_MYSQL_SSL,, [
+        Define if your MySQL library has SSL functions
+      ])
+    ],, $MYSQL_LIBS)
+
+    ssl_define=""
+    AS_IF([test "$have_openssl" = "yes"], [
+      ssl_define="#define HAVE_OPENSSL"
     ])
-  
-    mysql_lib=""
-    LIBS="$LIBS -lz -lm"
-    AC_CHECK_LIB(mysqlclient, mysql_init, [
-               old_CPPFLAGS=$CPPFLAGS
-               AS_IF([test "$MYSQL_INCLUDE" != ""], [
-                       CPPFLAGS="$CPPFLAGS $MYSQL_INCLUDE"
-               ])
-               AC_CHECK_HEADER(mysql.h, [
-                       AS_IF([test "$MYSQL_INCLUDE" != ""], [
-                               MYSQL_CFLAGS="$MYSQL_CFLAGS $MYSQL_INCLUDE"
-                       ])
-  
-                       AC_CHECK_LIB(mysqlclient, mysql_ssl_set, [
-                               AC_DEFINE(HAVE_MYSQL_SSL,, [Define if your MySQL library has SSL functions])
-                               AS_IF([test "$have_openssl" = "yes"], [
-                                 ssl_define="#define HAVE_OPENSSL"
-                               ], [
-                                 ssl_define=""
-                               ])
-                               AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
-                                 $ssl_define
-                                 #include <mysql.h>
-                               ]], [[
-                                 mysql_ssl_set(0, 0, 0, 0, 0, 0);
-                               ]])],[
-                                       AC_DEFINE(HAVE_MYSQL_SSL_CIPHER,, [Define if your MySQL library supports setting cipher])
-  
-                                       AC_COMPILE_IFELSE([_au_m4_changequote([,])AC_LANG_PROGRAM([[
-                                         $ssl_define
-                                         #include <mysql.h>
-                                       ]], [[
-                                         int i = MYSQL_OPT_SSL_VERIFY_SERVER_CERT;
-                                       ]])], [
-                                               AC_DEFINE(HAVE_MYSQL_SSL_VERIFY_SERVER_CERT,, [Defineif your MySQL library supports verifying the name in the SSL certificate])
-                                       ], [], [])
-                               ],[])
-                       ])
-                       
-                       have_mysql=yes
-                       AC_DEFINE(HAVE_MYSQL,, [Build with MySQL support])
-                       found_sql_drivers="$found_sql_drivers mysql"
-               ], [
-                 AS_IF([test $want_mysql = yes], [
-                   AC_MSG_ERROR(cannot build with MySQL support: mysql.h not found)
-                 ])
-               ])
-               CPPFLAGS=$old_CPPFLAGS
-    ], [
-      AS_IF([$want_mysql = yes], [
-        AC_MSG_ERROR(cannot build with MySQL support: libmysqlclient not found)
+
+    dnl add mysql-specific flags to the global CPPFLAGS to compile the
+    dnl mysql-test programs
+    tmp_CPPFLAGS="$CPPFLAGS"
+    CPPFLAGS="$MYSQL_CFLAGS"
+    AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
+      $ssl_define
+      #include <mysql.h>
+    ]], [[
+      mysql_ssl_set(0, 0, 0, 0, 0, 0);
+    ]])],[
+      AC_DEFINE(HAVE_MYSQL_SSL_CIPHER,, [
+        Define if your MySQL library supports setting cipher
       ])
     ])
-  
-    AS_IF([test $have_mysql != yes], [
-      MYSQL_LIBS=
-      MYSQL_CFLAGS=
+
+    AC_COMPILE_IFELSE([_au_m4_changequote([,])AC_LANG_PROGRAM([[
+      $ssl_define
+      #include <mysql.h>
+    ]], [[
+      int i = MYSQL_OPT_SSL_VERIFY_SERVER_CERT;
+    ]])], [
+      AC_DEFINE(HAVE_MYSQL_SSL_VERIFY_SERVER_CERT,, [
+        Define if your MySQL library supports verifying the name in the SSL certificate
+      ])
     ])
-    LIBS=$old_LIBS
+
+    dnl restore CPPFLAGS for further build
+    CPPFLAGS="$tmp_CPPFLAGS"
   ])
 ])