[gnome-desktop] pnp-ids: Add --disable-udev command-line argument



commit 140aa80ae4b3d83505e374d0d3a53068a6489e17
Author: Bastien Nocera <hadess hadess net>
Date:   Sat Jun 25 14:40:02 2016 +0200

    pnp-ids: Add --disable-udev command-line argument
    
    This will allow building gnome-desktop in environments where libudev
    isn't available (such as flatpak's Sdk) until we have a thumbnailing API
    living in the platform API (likely GLib or GTK+).

 configure.ac                     |   22 +++++++++++++++++++++-
 libgnome-desktop/gnome-pnp-ids.c |   14 ++++++++++++++
 2 files changed, 35 insertions(+), 1 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 2124596..1d580a2 100644
--- a/configure.ac
+++ b/configure.ac
@@ -140,6 +140,25 @@ AC_SUBST(X11_PACKAGE)
 AC_SUBST(XLIB_CFLAGS)
 AC_SUBST(XLIB_LIBS)
 
+dnl ---------------------------------------------------------------------------
+dnl - hwdb for pnp IDs (default enabled)
+dnl ---------------------------------------------------------------------------
+UDEV_PKG=""
+AC_ARG_ENABLE(udev, AS_HELP_STRING([--disable-udev],[Disable udev support]), enable_udev=$enableval)
+if test x$enable_udev != xno; then
+       PKG_CHECK_MODULES(UDEV, libudev, have_udev="yes", have_udev="no")
+       if test "x$have_udev" = "xyes"; then
+               AC_DEFINE(HAVE_UDEV, 1, [define if udev is available])
+               UDEV_PKG="libudev"
+       else
+               if test x$enable_udev = xyes; then
+                       AC_MSG_ERROR([udev enabled but not found])
+               fi
+       fi
+else
+       have_udev=no
+fi
+
 dnl pkg-config dependency checks
 
 PKG_CHECK_MODULES(GNOME_DESKTOP, gdk-pixbuf-2.0 >= $GDK_PIXBUF_REQUIRED
@@ -149,7 +168,7 @@ PKG_CHECK_MODULES(GNOME_DESKTOP, gdk-pixbuf-2.0 >= $GDK_PIXBUF_REQUIRED
                                  gsettings-desktop-schemas >= $GSETTINGS_DESKTOP_SCHEMAS_REQUIRED
                                  xkeyboard-config
                                  iso-codes
-                                 libudev)
+                                 $UDEV_PKG)
 
 XKB_BASE=$($PKG_CONFIG --variable xkb_base xkeyboard-config)
 AC_SUBST(XKB_BASE)
@@ -237,5 +256,6 @@ echo "
         Build debug tools:            ${enable_debug_tools}
         Date in gnome-version.xml:    ${enable_date_in_gnome_version}
         Build gtk-doc documentation:  ${enable_gtk_doc}
+        Build with udev support:      ${enable_udev}
 
 "
diff --git a/libgnome-desktop/gnome-pnp-ids.c b/libgnome-desktop/gnome-pnp-ids.c
index 92fdb61..7ad2caf 100644
--- a/libgnome-desktop/gnome-pnp-ids.c
+++ b/libgnome-desktop/gnome-pnp-ids.c
@@ -21,7 +21,9 @@
 
 #include <glib-object.h>
 #include <libgnome-desktop/gnome-pnp-ids.h>
+#ifdef HAVE_UDEV
 #include <libudev.h>
+#endif
 
 static void     gnome_pnp_ids_finalize     (GObject     *object);
 
@@ -29,8 +31,12 @@ static void     gnome_pnp_ids_finalize     (GObject     *object);
 
 struct _GnomePnpIdsPrivate
 {
+#ifdef HAVE_UDEV
         struct udev *udev;
         struct udev_hwdb *hwdb;
+#else
+        char *placeholder;
+#endif /* HAVE_UDEV */
 };
 
 G_DEFINE_TYPE (GnomePnpIds, gnome_pnp_ids, G_TYPE_OBJECT)
@@ -48,6 +54,7 @@ G_DEFINE_TYPE (GnomePnpIds, gnome_pnp_ids, G_TYPE_OBJECT)
 gchar *
 gnome_pnp_ids_get_pnp_id (GnomePnpIds *pnp_ids, const gchar *pnp_id)
 {
+#ifdef HAVE_UDEV
         GnomePnpIdsPrivate *priv = pnp_ids->priv;
         struct udev_list_entry *list_entry, *l;
         char *modalias;
@@ -70,6 +77,9 @@ gnome_pnp_ids_get_pnp_id (GnomePnpIds *pnp_ids, const gchar *pnp_id)
         ret = g_strdup (udev_list_entry_get_value (l));
 
         return ret;
+#else
+        return "Undefined";
+#endif
 }
 
 static void
@@ -84,8 +94,10 @@ static void
 gnome_pnp_ids_init (GnomePnpIds *pnp_ids)
 {
         pnp_ids->priv = GNOME_PNP_IDS_GET_PRIVATE (pnp_ids);
+#ifdef HAVE_UDEV
         pnp_ids->priv->udev = udev_new();
         pnp_ids->priv->hwdb = udev_hwdb_new (pnp_ids->priv->udev);
+#endif
 }
 
 static void
@@ -94,8 +106,10 @@ gnome_pnp_ids_finalize (GObject *object)
         GnomePnpIds *pnp_ids = GNOME_PNP_IDS (object);
         GnomePnpIdsPrivate *priv = pnp_ids->priv;
 
+#ifdef HAVE_UDEV
         g_clear_pointer (&priv->udev, udev_unref);
         g_clear_pointer (&priv->hwdb, udev_hwdb_unref);
+#endif
 
         G_OBJECT_CLASS (gnome_pnp_ids_parent_class)->finalize (object);
 }


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