[sound-juicer/gnome-3-18] Fix build with libdiscid < 0.4.0



commit f5afc7e390cbc6fd2da9dd9244805e61886d8d91
Author: Phillip Wood <phillip wood dunelm org uk>
Date:   Mon Apr 4 19:06:50 2016 +0100

    Fix build with libdiscid < 0.4.0
    
    discid_has_feature() was introduced in libdiscid version 0.4.0 and
    discid_get_mcn() in version 0.3.0. Add fallback functions when
    compiling against older versions to maintain compatibility.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=764535

 configure.ac                         |    9 ++++++
 libjuicer/sj-libdiscid.h             |   53 ++++++++++++++++++++++++++++++++++
 libjuicer/sj-metadata-musicbrainz5.c |    6 +---
 3 files changed, 63 insertions(+), 5 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 143181d..ee08f9a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -80,6 +80,15 @@ AC_SUBST(MUSICBRAINZ5_CFLAGS)
 AC_SUBST(MUSICBRAINZ5_LIBS)
 if test "$have_mb5" = "yes" ; then
         AC_DEFINE([HAVE_MUSICBRAINZ5], 1, [Whether libmusicbrainz5 is available])
+       # Whether libdiscid has discid_get_mcn() or discid_has_feature()
+       SAVE_LIBS=$LIBS
+       SAVE_CFLAGS=$CFLAGS
+       CFLAGS=$MUSICBRAINZ5_CFLAGS
+       LIBS=$MUSICBRAINZ5_LIBS
+       AC_CHECK_FUNC(discid_get_mcn, [AC_DEFINE([HAVE_DISCID_GET_MCN], 1, [Whether discid_get_mcn is 
available])], [])
+       AC_CHECK_FUNC(discid_has_feature, [AC_DEFINE([HAVE_DISCID_HAS_FEATURE], 1, [Whether 
discid_has_feature is available])], [])
+       LIBS=$SAVED_LIBS
+       CFLAGS=$SAVED_CFLAGS
 else
         AC_MSG_ERROR([libmusicbrainz5 needs to be available for sound-juicer to build])
 fi
diff --git a/libjuicer/sj-libdiscid.h b/libjuicer/sj-libdiscid.h
new file mode 100644
index 0000000..87d4a83
--- /dev/null
+++ b/libjuicer/sj-libdiscid.h
@@ -0,0 +1,53 @@
+/*
+ * sj-discid.h
+ * Copyright (C) 2016 Phillip Wood <phillip wood dunelm org uk>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+/*
+ * Provide dummy functions for older versions of libdiscid that are
+ * missing have discid_get_mcn(), discid_has_feature() or
+ * discid_sparse_read()
+ */
+
+#ifndef SJ_LIBDISCID
+#define SJ_LIBDISCID
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif /* HAVE_CONFIG_H */
+
+#include <discid/discid.h>
+
+#ifndef HAVE_DISCID_GET_MCN
+#define discid_get_mcn(x) NULL
+#endif /* HAVE_DISCID_GET_MCN */
+
+#ifndef HAVE_DISCID_HAS_FEATURE
+enum discid_feature {
+        DISCID_FEATURE_READ = 1 << 0,
+        DISCID_FEATURE_MCN  = 1 << 1,
+        DISCID_FEATURE_ISRC = 1 << 2,
+};
+
+/* Report TRUE for everything */
+#define discid_has_feature(x) TRUE
+#endif /* HAVE_DISCID_HAS_FEATURE */
+
+#ifndef DISCID_HAVE_SPARSE_READ
+#define discid_read_sparse(disc, dev, i) discid_read(disc, dev)
+#endif /* DISCID_HAVE_SPARSE_READ */
+
+#endif /* SJ_LIBDISCID */
diff --git a/libjuicer/sj-metadata-musicbrainz5.c b/libjuicer/sj-metadata-musicbrainz5.c
index edb1cda..0d423ec 100644
--- a/libjuicer/sj-metadata-musicbrainz5.c
+++ b/libjuicer/sj-metadata-musicbrainz5.c
@@ -28,9 +28,9 @@
 #include <glib/gi18n.h>
 #include <glib-object.h>
 #include <gdesktop-enums.h>
-#include <discid/discid.h>
 #include <musicbrainz5/mb5_c.h>
 
+#include "sj-libdiscid.h"
 #include "sj-metadata-musicbrainz5.h"
 #include "sj-structures.h"
 #include "sj-error.h"
@@ -47,10 +47,6 @@ static char language[3];
                field = g_strdup (buffer);                                      \
 }
 
-#ifndef DISCID_HAVE_SPARSE_READ
-#define discid_read_sparse(disc, dev, i) discid_read(disc, dev)
-#endif
-
 #define SJ_MUSICBRAINZ_USER_AGENT "libjuicer-"VERSION
 
 typedef struct {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]