From d5dfe7d457b559bd9c53d65d0315c55611cc6a79 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Sun, 15 Dec 2013 12:32:15 +0100 Subject: configure.ac: add option "--disable-glib" Allows building without GLib. This fails to compile currently, because GLib is still used in the MPD core. --- Makefile.am | 20 ++++++++++++-------- configure.ac | 19 +++++++++++++++---- src/LogBackend.cxx | 14 ++++++++++++++ src/LogInit.cxx | 7 ++++++- src/Main.cxx | 8 +++++++- src/event/SignalMonitor.cxx | 1 + src/system/FatalError.cxx | 6 +++++- src/system/FatalError.hxx | 2 ++ test/run_decoder.cxx | 4 ++++ test/run_input.cxx | 4 ++++ 10 files changed, 70 insertions(+), 15 deletions(-) diff --git a/Makefile.am b/Makefile.am index 6ce95d034..11ae26960 100644 --- a/Makefile.am +++ b/Makefile.am @@ -990,14 +990,6 @@ libplaylist_plugins_a_SOURCES = \ src/playlist/ExtM3uPlaylistPlugin.hxx \ src/playlist/M3uPlaylistPlugin.cxx \ src/playlist/M3uPlaylistPlugin.hxx \ - src/playlist/PlsPlaylistPlugin.cxx \ - src/playlist/PlsPlaylistPlugin.hxx \ - src/playlist/XspfPlaylistPlugin.cxx \ - src/playlist/XspfPlaylistPlugin.hxx \ - src/playlist/AsxPlaylistPlugin.cxx \ - src/playlist/AsxPlaylistPlugin.hxx \ - src/playlist/RssPlaylistPlugin.cxx \ - src/playlist/RssPlaylistPlugin.hxx \ src/playlist/CuePlaylistPlugin.cxx \ src/playlist/CuePlaylistPlugin.hxx \ src/playlist/EmbeddedCuePlaylistPlugin.cxx \ @@ -1024,6 +1016,18 @@ libplaylist_plugins_a_SOURCES += \ PLAYLIST_LIBS += $(YAJL_LIBS) endif +if HAVE_GLIB +libplaylist_plugins_a_SOURCES += \ + src/playlist/PlsPlaylistPlugin.cxx \ + src/playlist/PlsPlaylistPlugin.hxx \ + src/playlist/XspfPlaylistPlugin.cxx \ + src/playlist/XspfPlaylistPlugin.hxx \ + src/playlist/AsxPlaylistPlugin.cxx \ + src/playlist/AsxPlaylistPlugin.hxx \ + src/playlist/RssPlaylistPlugin.cxx \ + src/playlist/RssPlaylistPlugin.hxx +endif + # # Filter plugins # diff --git a/configure.ac b/configure.ac index 1e3dfb098..b789d02d9 100644 --- a/configure.ac +++ b/configure.ac @@ -547,13 +547,24 @@ AC_ARG_WITH(tremor-includes, dnl --------------------------------------------------------------------------- dnl Mandatory Libraries dnl --------------------------------------------------------------------------- -PKG_CHECK_MODULES([GLIB], [glib-2.0 >= 2.28 gthread-2.0],, + +AC_ARG_ENABLE(glib, + AS_HELP_STRING([--enable-glib], + [enable GLib usage (default: enabled)]),, + enable_glib=yes) + +if test x$enable_glib = xyes; then + PKG_CHECK_MODULES([GLIB], [glib-2.0 >= 2.28 gthread-2.0],, [AC_MSG_ERROR([GLib 2.28 is required])]) -if test x$GCC = xyes; then - # suppress warnings in the GLib headers - GLIB_CFLAGS=`echo $GLIB_CFLAGS |sed -e 's,-I/,-isystem /,g'` + if test x$GCC = xyes; then + # suppress warnings in the GLib headers + GLIB_CFLAGS=`echo $GLIB_CFLAGS |sed -e 's,-I/,-isystem /,g'` + fi + + AC_DEFINE(HAVE_GLIB, 1, [Define if GLib is used]) fi +AM_CONDITIONAL(HAVE_GLIB, test x$enable_glib = xyes) dnl --------------------------------------------------------------------------- dnl Protocol Options diff --git a/src/LogBackend.cxx b/src/LogBackend.cxx index a5c0a691f..bddf8db16 100644 --- a/src/LogBackend.cxx +++ b/src/LogBackend.cxx @@ -23,18 +23,24 @@ #include "util/Domain.hxx" #include "util/CharUtil.hxx" +#ifdef HAVE_GLIB #include +#endif #include #include #include +#include #ifdef HAVE_SYSLOG #include #endif static LogLevel log_threshold = LogLevel::INFO; + +#ifdef HAVE_GLIB static const char *log_charset; +#endif static bool enable_timestamp; @@ -48,12 +54,16 @@ SetLogThreshold(LogLevel _threshold) log_threshold = _threshold; } +#ifdef HAVE_GLIB + void SetLogCharset(const char *_charset) { log_charset = _charset; } +#endif + void EnableLogTimestamp() { @@ -142,6 +152,7 @@ LogFinishSysLog() static void FileLog(const Domain &domain, const char *message) { +#ifdef HAVE_GLIB char *converted; if (log_charset != nullptr) { @@ -153,13 +164,16 @@ FileLog(const Domain &domain, const char *message) message = converted; } else converted = nullptr; +#endif fprintf(stderr, "%s%s: %.*s\n", enable_timestamp ? log_date() : "", domain.GetName(), chomp_length(message), message); +#ifdef HAVE_GLIB g_free(converted); +#endif } void diff --git a/src/LogInit.cxx b/src/LogInit.cxx index 42d86951f..bd858a32c 100644 --- a/src/LogInit.cxx +++ b/src/LogInit.cxx @@ -31,13 +31,16 @@ #include "util/Domain.hxx" #include "system/FatalError.hxx" +#ifdef HAVE_GLIB +#include +#endif + #include #include #include #include #include #include -#include #define LOG_LEVEL_SECURE LogLevel::INFO @@ -110,9 +113,11 @@ log_init(bool verbose, bool use_stdout, Error &error) { const struct config_param *param; +#ifdef HAVE_GLIB const char *charset; g_get_charset(&charset); SetLogCharset(charset); +#endif if (verbose) SetLogThreshold(LogLevel::DEBUG); diff --git a/src/Main.cxx b/src/Main.cxx index 2d25297c9..da8458340 100644 --- a/src/Main.cxx +++ b/src/Main.cxx @@ -79,7 +79,9 @@ #include "ArchiveList.hxx" #endif +#ifdef HAVE_GLIB #include +#endif #include @@ -92,6 +94,8 @@ #include #endif +#include + static constexpr unsigned DEFAULT_BUFFER_SIZE = 4096; static constexpr unsigned DEFAULT_BUFFER_BEFORE_PLAY = 10; @@ -359,11 +363,13 @@ int mpd_main(int argc, char *argv[]) setlocale(LC_CTYPE,""); #endif +#ifdef HAVE_GLIB g_set_application_name("Music Player Daemon"); #if !GLIB_CHECK_VERSION(2,32,0) /* enable GLib's thread safety code */ g_thread_init(nullptr); +#endif #endif winsock_init(); @@ -473,7 +479,7 @@ int mpd_main(int argc, char *argv[]) } if (!glue_state_file_init(error)) { - g_printerr("%s\n", error.GetMessage()); + LogError(error); return EXIT_FAILURE; } diff --git a/src/event/SignalMonitor.cxx b/src/event/SignalMonitor.cxx index 0d96fb138..bb75f49a3 100644 --- a/src/event/SignalMonitor.cxx +++ b/src/event/SignalMonitor.cxx @@ -40,6 +40,7 @@ #include #include +#include class SignalMonitor final : private SocketMonitor { #ifdef USE_SIGNALFD diff --git a/src/system/FatalError.cxx b/src/system/FatalError.cxx index 11a0944df..b54a677f2 100644 --- a/src/system/FatalError.cxx +++ b/src/system/FatalError.cxx @@ -23,7 +23,7 @@ #include "util/Domain.hxx" #include "LogV.hxx" -#ifdef WIN32 +#ifdef HAVE_GLIB #include #endif @@ -78,12 +78,16 @@ FatalError(const char *msg, const Error &error) FormatFatalError("%s: %s", msg, error.GetMessage()); } +#ifdef HAVE_GLIB + void FatalError(const char *msg, GError *error) { FormatFatalError("%s: %s", msg, error->message); } +#endif + void FatalSystemError(const char *msg) { diff --git a/src/system/FatalError.hxx b/src/system/FatalError.hxx index 2845359ef..4ef290714 100644 --- a/src/system/FatalError.hxx +++ b/src/system/FatalError.hxx @@ -45,9 +45,11 @@ gcc_noreturn void FatalError(const char *msg, const Error &error); +#ifdef HAVE_GLIB gcc_noreturn void FatalError(const char *msg, GError *error); +#endif /** * Call this after a system call has failed that is not supposed to diff --git a/test/run_decoder.cxx b/test/run_decoder.cxx index 7db8dde22..56ef2068d 100644 --- a/test/run_decoder.cxx +++ b/test/run_decoder.cxx @@ -29,7 +29,9 @@ #include "Log.hxx" #include "stdbin.h" +#ifdef HAVE_GLIB #include +#endif #include #include @@ -192,8 +194,10 @@ int main(int argc, char **argv) decoder_name = argv[1]; decoder.uri = argv[2]; +#ifdef HAVE_GLIB #if !GLIB_CHECK_VERSION(2,32,0) g_thread_init(NULL); +#endif #endif g_log_set_default_handler(my_log_func, NULL); diff --git a/test/run_input.cxx b/test/run_input.cxx index 3817ed418..23316b7c6 100644 --- a/test/run_input.cxx +++ b/test/run_input.cxx @@ -33,7 +33,9 @@ #include "ArchiveList.hxx" #endif +#ifdef HAVE_GLIB #include +#endif #include #include @@ -120,8 +122,10 @@ int main(int argc, char **argv) /* initialize GLib */ +#ifdef HAVE_GLIB #if !GLIB_CHECK_VERSION(2,32,0) g_thread_init(NULL); +#endif #endif g_log_set_default_handler(my_log_func, NULL); -- cgit v1.2.3