http://trac.xbmc.org/ticket/11775

make mysql/mythtv support optional

--- a/Makefile.in
+++ b/Makefile.in
@@ -127,13 +127,17 @@ endif
 LIB_DIRS=\
 	lib/cximage-6.0 \
 	lib/libexif \
-	lib/cmyth \
 	lib/libhdhomerun \
 	lib/libid3tag \
 	lib/libapetag \
 	lib/cpluff \
 	lib/xbmc-dll-symbols
 
+ifeq (@BUILD_MYTHTV@,1)
+LIB_DIRS+=\
+	lib/cmyth
+endif
+
 SS_DIRS=
 ifeq (@USE_OPENGL@,1)
 SS_DIRS+= xbmc/screensavers/rsxs-0.9/xbmc
@@ -418,7 +422,10 @@ imagelib: dllloader
 	$(MAKE) -C lib/cximage-6.0
 
 codecs: papcodecs dvdpcodecs
-libs: cmyth libhdhomerun libid3tag imagelib libexif system/libcpluff-@ARCH@.so
+libs: libhdhomerun libid3tag imagelib libexif system/libcpluff-@ARCH@.so
+ifeq (@BUILD_MYTHTV@,1)
+libs: cmyth
+endif
 externals: codecs libs visualizations screensavers
 
 xcode_depends: \
--- a/configure.in
+++ b/configure.in
@@ -68,6 +68,9 @@ goom_enabled="== GOOM enabled. =="
 goom_disabled="== GOOM disabled. =="
 pulse_not_found="== Could not find libpulse. PulseAudio support disabled. =="
 pulse_disabled="== PulseAudio support manually disabled. =="
+mysql_not_found="Could not find libmysqlclient. MySQL (and MythTV) support disabled. =="
+mysql_disabled="== MySQL support disabled. =="
+mythtv_disabled="== MythTV support disabled. =="
 dvdcss_enabled="== DVDCSS support enabled. =="
 dvdcss_disabled="== DVDCSS support disabled. =="
 hal_not_found="== Could not find hal. HAL support disabled. =="
@@ -238,6 +241,18 @@ AC_ARG_ENABLE([ffmpeg_libvorbis],
   [use_ffmpeg_libvorbis=$enableval],
   [use_ffmpeg_libvorbis=no])
 
+AC_ARG_ENABLE([mysql],
+  [AS_HELP_STRING([--enable-mysql],
+  [enable MySQL support (default is auto)])],
+  [use_mysql=$enableval],
+  [use_mysql=auto])
+
+AC_ARG_ENABLE([mythtv],
+  [AS_HELP_STRING([--enable-mythtv],
+  [enable MythTV support (default is auto)])],
+  [use_mythtv=$enableval],
+  [use_mythtv=auto])
+
 AC_ARG_ENABLE([dvdcss],
   [AS_HELP_STRING([--enable-dvdcss],
   [enable DVDCSS support (default is yes)])],
@@ -563,14 +578,31 @@ else
 fi
 
 # platform common libraries
-AC_CHECK_PROG(MYSQL_CONFIG, mysql_config, "yes", "no")
-if test $MYSQL_CONFIG = "yes"; then
-  INCLUDES="$INCLUDES `mysql_config --include`"
-  MYSQL_LIBS=`mysql_config --libs`
-  LIBS="$LIBS $MYSQL_LIBS"
-  AC_SUBST(MYSQL_LIBS)
-else
-  AC_MSG_ERROR($missing_program)
+have_mysql=no
+if test "$use_mysql" != "no"; then
+  AC_CHECK_PROG(MYSQL_CONFIG, mysql_config, "yes", "no")
+  if test $MYSQL_CONFIG = "yes"; then
+    INCLUDES="$INCLUDES `mysql_config --include`"
+    MYSQL_LIBS=`mysql_config --libs`
+    LIBS="$LIBS $MYSQL_LIBS"
+    AC_SUBST(MYSQL_LIBS)
+    AC_CHECK_LIB([mysqlclient], [main], have_mysql=yes)
+  fi
+fi
+if test "$have_mysql" = "yes"; then
+  BUILD_MYTHTV=1
+  AC_DEFINE([BUILD_MYSQL], [1], [Define to 1 to build MySQL.])
+  if test "$use_mysql" != "no"; then
+    AC_DEFINE([BUILD_MYTHTV], [1], [Define to 1 to build mythtv.])
+  fi
+elif test "$use_mysql" = "yes" || test "$use_mythtv" = "yes"; then
+  AC_MSG_ERROR([$mysql_not_found])
+else
+  BUILD_MYTHTV=0
+  use_mysql=no
+  AC_MSG_NOTICE($mysql_disabled)
+  use_mythtv=no
+  AC_MSG_NOTICE($mythtv_disabled)
 fi
 AC_CHECK_HEADER([ass/ass.h],, AC_MSG_ERROR($missing_library))
 AC_CHECK_HEADER([mpeg2dec/mpeg2.h],, AC_MSG_ERROR($missing_library))
@@ -594,7 +625,6 @@ AC_CHECK_LIB([lzo2],        [main],, AC_MSG_ERROR($missing_library))
 AC_CHECK_LIB([z],           [main],, AC_MSG_ERROR($missing_library))
 AC_CHECK_LIB([crypto],      [main],, AC_MSG_ERROR($missing_library))
 AC_CHECK_LIB([ssl],         [main],, AC_MSG_ERROR($missing_library))
-AC_CHECK_LIB([mysqlclient], [main],, AC_MSG_ERROR($missing_library))
 AC_CHECK_LIB([ssh],         [sftp_tell64],, AC_MSG_RESULT([Could not find suitable version of libssh]))
 AC_CHECK_LIB([smbclient],   [main],, AC_MSG_ERROR($missing_library))
 AC_CHECK_LIB([bluetooth],   [hci_devid],, AC_MSG_RESULT([Could not find suitable version of libbluetooth]))
@@ -1319,6 +1349,18 @@ else
   final_message="$final_message\n  HAL Support:\tNo"
 fi
 
+if test "$use_mysql" = "yes"; then
+  final_message="$final_message\n  MySQL:\tYes"
+else
+  final_message="$final_message\n  MySQL:\tNo"
+fi
+
+if test "$use_mythtv" = "yes"; then
+  final_message="$final_message\n  MythTV:\tYes"
+else
+  final_message="$final_message\n  MythTV:\tNo"
+fi
+
 # DVDCSS
 if test "$use_dvdcss" = "yes"; then
   AC_MSG_NOTICE($dvdcss_enabled)
@@ -1490,6 +1532,8 @@ AC_SUBST(USE_EXTERNAL_FFMPEG)
 AC_SUBST(PYTHON_VERSION)
 AC_SUBST(OUTPUT_FILES)
 AC_SUBST(HAVE_XBMC_NONFREE)
+AC_SUBST(BUILD_MYSQL)
+AC_SUBST(BUILD_MYTHTV)
 AC_SUBST(USE_ASAP_CODEC)
 AC_SUBST(LIBCURL_BASENAME)
 AC_SUBST(LIBFLAC_BASENAME)
--- a/xbmc/dbwrappers/Database.cpp
+++ b/xbmc/dbwrappers/Database.cpp
@@ -29,7 +29,9 @@
 #include "utils/AutoPtrHandle.h"
 #include "utils/log.h"
 #include "utils/URIUtils.h"
+#ifdef BUILD_MYSQL
 #include "mysqldataset.h"
+#endif /* BUILD_MYSQL */
 #include "sqlitedataset.h"
 
 
@@ -266,6 +268,7 @@
 
   m_sqlite = true;
 
+#ifdef BUILD_MYSQL
   if ( dbSettings.type.Equals("mysql") )
   {
     // check we have all information before we cancel the fallback
@@ -276,7 +279,8 @@
       CLog::Log(LOGINFO, "Essential mysql database information is missing. Require at least host, user and pass defined.");
   }
   else
+#endif /* BUILD_MYSQL */
   {
     dbSettings.type = "sqlite3";
     dbSettings.host = _P(g_settings.GetDatabaseFolder());
     dbSettings.name = GetBaseDBName();
@@ -369,10 +373,12 @@
   {
     m_pDB.reset( new SqliteDatabase() ) ;
   }
+#ifdef BUILD_MYSQL
   else if (dbSettings.type.Equals("mysql"))
   {
     m_pDB.reset( new MysqlDatabase() ) ;
   }
+#endif /* BUILD_MYSQL */
   else
   {
     CLog::Log(LOGERROR, "Unable to determine database type: %s", dbSettings.type.c_str());
--- a/xbmc/dbwrappers/mysqldataset.cpp
+++ b/xbmc/dbwrappers/mysqldataset.cpp
@@ -23,9 +23,11 @@
 #include <string>
 #include <set>
 
+#include "system.h" // for GetLastError()
+#ifdef BUILD_MYSQL
+
 #include "mysqldataset.h"
 #include "utils/log.h"
-#include "system.h" // for GetLastError()
 #include "mysql/errmsg.h"
 #ifdef _WIN32
 #pragma comment(lib, "mysqlclient.lib")
@@ -1562,3 +1564,4 @@
 
 }//namespace
 
+#endif /* BUILD_MYSQL */