From: Karl Fleischmann Date: Wed, 8 Jun 2022 12:12:15 +0000 (+0200) Subject: m4: Rewrite want_mysql.m4 to use pkg_config X-Git-Tag: 2.4.0~3859 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2bd324762c7d72ea0e99939b71a5a5be532bf2cc;p=thirdparty%2Fdovecot%2Fcore.git m4: Rewrite want_mysql.m4 to use pkg_config 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. --- diff --git a/configure.ac b/configure.ac index bea523e94c..34b150cfb6 100644 --- a/configure.ac +++ b/configure.ac @@ -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) diff --git a/m4/want_mysql.m4 b/m4/want_mysql.m4 index 824614fac3..4916e84644 100644 --- a/m4/want_mysql.m4 +++ b/m4/want_mysql.m4 @@ -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_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 - ]], [[ - 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_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 + ]], [[ + 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" ]) ])