From bda91af9d315d1abee2f9d5fb6053f1befeaa30f Mon Sep 17 00:00:00 2001 From: Jonathan Xu Date: Mon, 24 Jun 2019 15:04:27 +0800 Subject: [PATCH] Make mysqlclient dependency optional. --- common/seaf-db.c | 10 ++++++++++ common/seaf-utils.c | 6 ++++++ configure.ac | 11 ++++++++--- 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/common/seaf-db.c b/common/seaf-db.c index 998d876..83a8366 100644 --- a/common/seaf-db.c +++ b/common/seaf-db.c @@ -6,7 +6,9 @@ #include "seaf-db.h" #include +#ifdef HAVE_MYSQL #include +#endif #include #include @@ -43,6 +45,8 @@ typedef struct DBOperations { static DBOperations db_ops; +#ifdef HAVE_MYSQL + /* MySQL Ops */ static SeafDB * mysql_db_new (const char *host, @@ -105,6 +109,8 @@ seaf_db_new_mysql (const char *host, return db; } +#endif + /* SQLite Ops */ static SeafDB * sqlite_db_new (const char *db_path); @@ -500,6 +506,8 @@ seaf_db_trans_foreach_selected_row (SeafDBTrans *trans, const char *sql, return ret; } +#ifdef HAVE_MYSQL + /* MySQL DB */ typedef struct MySQLDB { @@ -936,6 +944,8 @@ mysql_db_row_get_column_int64 (SeafDBRow *vrow, int idx) return ret; } +#endif /* HAVE_MYSQL */ + /* SQLite DB */ /* SQLite thread synchronization rountines. diff --git a/common/seaf-utils.c b/common/seaf-utils.c index fc6066c..ef1c750 100644 --- a/common/seaf-utils.c +++ b/common/seaf-utils.c @@ -51,6 +51,8 @@ sqlite_db_start (SeafileSession *session) return 0; } +#ifdef HAVE_MYSQL + #define MYSQL_DEFAULT_PORT 3306 static int @@ -124,6 +126,8 @@ mysql_db_start (SeafileSession *session) return 0; } +#endif + #ifdef HAVE_POSTGRESQL static int @@ -197,9 +201,11 @@ load_database_config (SeafileSession *session) if (!type || strcasecmp (type, "sqlite") == 0) { ret = sqlite_db_start (session); } +#ifdef HAVE_MYSQL else if (strcasecmp (type, "mysql") == 0) { ret = mysql_db_start (session); } +#endif #ifdef HAVE_POSTGRESQL else if (strcasecmp (type, "pgsql") == 0) { ret = pgsql_db_start (session); diff --git a/configure.ac b/configure.ac index d18c2b5..0795526 100644 --- a/configure.ac +++ b/configure.ac @@ -228,12 +228,17 @@ AC_SUBST(ZLIB_CFLAGS) AC_SUBST(ZLIB_LIBS) if test "x${MYSQL_CONFIG}" = "xdefault_mysql_config"; then - PKG_CHECK_MODULES(MYSQL, [mysqlclient]) - AC_SUBST(MYSQL_CFLAGS) - AC_SUBST(MYSQL_LIBS) + PKG_CHECK_MODULES(MYSQL, [mysqlclient], [have_mysql="yes"], [have_mysql="no"]) + if test "x${have_mysql}" = "xyes"; then + AC_SUBST(MYSQL_CFLAGS) + AC_SUBST(MYSQL_LIBS) + AC_DEFINE([HAVE_MYSQL], 1, [Define to 1 if MySQL support is enabled]) + fi else + AC_MSG_CHECKING([for MySQL]) MYSQL_CFLAGS=`${MYSQL_CONFIG} --include` MYSQL_LIBS=`${MYSQL_CONFIG} --libs` + AC_MSG_RESULT([${MYSQL_CFLAGS}]) AC_SUBST(MYSQL_CFLAGS) AC_SUBST(MYSQL_LIBS) fi