[network-manager-applet/danw/libnm-bgo736911: 5/17] utils: build separate libnm-based and libnm-glib-based versions



commit a0d4d15ed22fff2ed856ca6291812e96374afc94
Author: Dan Winship <danw redhat com>
Date:   Tue Nov 25 10:00:33 2014 -0500

    utils: build separate libnm-based and libnm-glib-based versions

 configure.ac                      |    4 ++-
 src/Makefile.am                   |    3 +-
 src/connection-editor/Makefile.am |    3 +-
 src/libnm-gtk/Makefile.am         |    1 +
 src/utils/Makefile.am             |   31 +++++++++++++++++-----
 src/utils/tests/Makefile.am       |    7 +++--
 src/utils/tests/test-utils.c      |   13 +++------
 src/utils/utils.c                 |   19 +++++++++----
 src/utils/utils.h                 |   52 +++++++++++-------------------------
 src/wireless-security/Makefile.am |    3 +-
 10 files changed, 71 insertions(+), 65 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 09a4fb6..7dffcfe 100644
--- a/configure.ac
+++ b/configure.ac
@@ -77,9 +77,11 @@ PKG_CHECK_MODULES(NMA,
                 libnm-util >= 1.0
                 libnm-glib-vpn >= 1.0
                 gmodule-export-2.0])
-
 NMA_CFLAGS="$NMA_CFLAGS -DGLIB_VERSION_MIN_REQUIRED=GLIB_VERSION_2_32"
 
+PKG_CHECK_MODULES(LIBNM, [libnm gio-2.0 >= 2.32])
+LIBNM_CFLAGS="$LIBNM_CFLAGS -DGLIB_VERSION_MIN_REQUIRED=GLIB_VERSION_2_32"
+
 PKG_CHECK_MODULES(LIBSECRET, [libsecret-unstable])
 
 # Check for libnotify >= 0.7
diff --git a/src/Makefile.am b/src/Makefile.am
index 9379a51..4b1afbb 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -9,6 +9,7 @@ nm_applet_CPPFLAGS = \
        $(NOTIFY_CFLAGS) \
        $(MM_GLIB_CFLAGS) \
        $(APPINDICATOR_CFLAGS) \
+       -DLIBNM_GLIB_BUILD \
        -DNM_VERSION_MIN_REQUIRED=NM_VERSION_0_9_10 \
        -DNM_VERSION_MAX_ALLOWED=NM_VERSION_0_9_10 \
        -DICONDIR=\""$(datadir)/icons"\"                                                \
@@ -82,7 +83,7 @@ nm_applet_LDADD = \
        $(NOTIFY_LIBS) \
        $(MM_GLIB_LIBS) \
        $(APPINDICATOR_LIBS) \
-       ${top_builddir}/src/utils/libutils.la \
+       ${top_builddir}/src/utils/libutils-libnm-glib.la \
        ${top_builddir}/src/wireless-security/libwireless-security.la \
        ${top_builddir}/src/libnm-gtk/libnm-gtk.la
 
diff --git a/src/connection-editor/Makefile.am b/src/connection-editor/Makefile.am
index bc6c14c..ccff613 100644
--- a/src/connection-editor/Makefile.am
+++ b/src/connection-editor/Makefile.am
@@ -3,6 +3,7 @@ bin_PROGRAMS = nm-connection-editor
 nm_connection_editor_CPPFLAGS = \
        $(GTK_CFLAGS) \
        $(NMA_CFLAGS) \
+       -DLIBNM_GLIB_BUILD \
        -DNM_VERSION_MIN_REQUIRED=NM_VERSION_0_9_10 \
        -DNM_VERSION_MAX_ALLOWED=NM_VERSION_0_9_10 \
        -DICONDIR=\""$(datadir)/icons"\" \
@@ -87,7 +88,7 @@ nm-connection-editor-service-glue.h: $(top_srcdir)/src/connection-editor/nm-conn
 
 nm_connection_editor_LDADD = \
        ${top_builddir}/src/wireless-security/libwireless-security.la \
-       ${top_builddir}/src/utils/libutils.la \
+       ${top_builddir}/src/utils/libutils-libnm-glib.la \
        ${top_builddir}/src/libnm-gtk/libnm-gtk.la \
        $(GTK_LIBS) \
        $(NMA_LIBS) \
diff --git a/src/libnm-gtk/Makefile.am b/src/libnm-gtk/Makefile.am
index c2a75a4..b63c67c 100644
--- a/src/libnm-gtk/Makefile.am
+++ b/src/libnm-gtk/Makefile.am
@@ -29,6 +29,7 @@ libnm_gtk_la_CFLAGS = \
        $(NMA_CFLAGS) \
        $(DBUS_CFLAGS) \
        $(GUDEV_CFLAGS) \
+       -DLIBNM_GLIB_BUILD \
        -DICONDIR=\""$(datadir)/icons"\" \
        -DUIDIR=\""$(uidir)"\" \
        -DBINDIR=\""$(bindir)"\" \
diff --git a/src/utils/Makefile.am b/src/utils/Makefile.am
index c2cbe9e..33a1d53 100644
--- a/src/utils/Makefile.am
+++ b/src/utils/Makefile.am
@@ -1,15 +1,32 @@
-SUBDIRS=. tests
+SUBDIRS= . tests
 
-noinst_LTLIBRARIES = libutils.la
+noinst_LTLIBRARIES = \
+       libutils-libnm-glib.la \
+       libutils-libnm.la
 
-libutils_la_SOURCES = \
+libutils_libnm_glib_la_SOURCES = \
        nm-glib-compat.h \
        utils.c \
        utils.h
 
-libutils_la_CPPFLAGS = \
+libutils_libnm_glib_la_CPPFLAGS = \
+       -DLIBNM_GLIB_BUILD \
        $(GTK_CFLAGS) \
-       $(NMA_CFLAGS) \
-       -I${top_srcdir}/src
+       $(NMA_CFLAGS)
 
-libutils_la_LIBADD = $(GTK_LIBS) $(NMA_LIBS)
+libutils_libnm_glib_la_LIBADD = \
+       $(GTK_LIBS) \
+       $(NMA_LIBS)
+
+libutils_libnm_la_SOURCES = \
+       utils.c \
+       utils.h
+
+libutils_libnm_la_CPPFLAGS = \
+       -DLIBNM_BUILD \
+       $(GTK_CFLAGS) \
+       $(LIBNM_CFLAGS)
+
+libutils_libnm_la_LIBADD = \
+       $(GTK_LIBS) \
+       $(LIBNM_LIBS)
diff --git a/src/utils/tests/Makefile.am b/src/utils/tests/Makefile.am
index ba676ce..61e937a 100644
--- a/src/utils/tests/Makefile.am
+++ b/src/utils/tests/Makefile.am
@@ -4,13 +4,14 @@ test_utils_SOURCES = test-utils.c
 
 test_utils_CPPFLAGS = \
        -I $(top_srcdir)/src/utils \
+       -DLIBNM_BUILD \
        $(GTK_CFLAGS) \
-       $(NMA_CFLAGS)
+       $(LIBNM_CFLAGS)
 
 test_utils_LDADD = \
-       ${top_builddir}/src/utils/libutils.la \
+       ${top_builddir}/src/utils/libutils-libnm.la \
        $(GTK_LIBS) \
-       $(NMA_LIBS)
+       $(LIBNM_LIBS)
 
 check-local: test-utils
        $(abs_builddir)/test-utils
diff --git a/src/utils/tests/test-utils.c b/src/utils/tests/test-utils.c
index 68d6472..10e11a5 100644
--- a/src/utils/tests/test-utils.c
+++ b/src/utils/tests/test-utils.c
@@ -49,17 +49,12 @@ typedef struct {
        char *asdf11_adhoc_wpa_rsn;
 } TestData;
 
-static GByteArray *
+static GBytes *
 string_to_ssid (const char *str)
 {
-       GByteArray *ssid;
-
        g_assert (str != NULL);
 
-       ssid = g_byte_array_sized_new (strlen (str));
-       g_assert (ssid != NULL);
-       g_byte_array_append (ssid, (const guint8 *) str, strlen (str));
-       return ssid;
+       return g_bytes_new (str, strlen (str));
 }
 
 static char *
@@ -69,7 +64,7 @@ make_hash (const char *str,
            guint32 wpa_flags,
            guint32 rsn_flags)
 {
-       GByteArray *ssid;
+       GBytes *ssid;
        char *hash, *hash2;
 
        ssid = string_to_ssid (str);
@@ -83,7 +78,7 @@ make_hash (const char *str,
        /* Make sure they are the same each time */
        g_assert (!strcmp (hash, hash2));
 
-       g_byte_array_free (ssid, TRUE);
+       g_bytes_unref (ssid);
        return hash;
 }
 
diff --git a/src/utils/utils.c b/src/utils/utils.c
index 269abe3..42db746 100644
--- a/src/utils/utils.c
+++ b/src/utils/utils.c
@@ -17,7 +17,7 @@
  * with this program; if not, write to the Free Software Foundation, Inc.,
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  *
- * (C) Copyright 2007 - 2011 Red Hat, Inc.
+ * Copyright 2007 - 2014 Red Hat, Inc.
  */
 
 #include <config.h>
@@ -27,9 +27,6 @@
 #include <glib/gi18n.h>
 #include <gtk/gtk.h>
 
-#include <nm-setting-connection.h>
-#include <nm-utils.h>
-
 #include "utils.h"
 
 /*
@@ -68,7 +65,12 @@ utils_ether_addr_valid (const struct ether_addr *test_addr)
 }
 
 char *
-utils_hash_ap (const GByteArray *ssid,
+utils_hash_ap (
+#ifdef LIBNM_BUILD
+               GBytes *ssid,
+#else
+               const GByteArray *ssid,
+#endif
                NM80211Mode mode,
                guint32 flags,
                guint32 wpa_flags,
@@ -78,8 +80,13 @@ utils_hash_ap (const GByteArray *ssid,
 
        memset (&input[0], 0, sizeof (input));
 
-       if (ssid)
+       if (ssid) {
+#ifdef LIBNM_BUILD
+               memcpy (input, g_bytes_get_data (ssid, NULL), g_bytes_get_size (ssid));
+#else
                memcpy (input, ssid->data, ssid->len);
+#endif
+       }
 
        if (mode == NM_802_11_MODE_INFRA)
                input[32] |= (1 << 0);
diff --git a/src/utils/utils.h b/src/utils/utils.h
index a4827de..5adb20d 100644
--- a/src/utils/utils.h
+++ b/src/utils/utils.h
@@ -17,7 +17,7 @@
  * with this program; if not, write to the Free Software Foundation, Inc.,
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  *
- * (C) Copyright 2007 - 2012 Red Hat, Inc.
+ * Copyright 2007 - 2014 Red Hat, Inc.
  */
 
 #ifndef UTILS_H
@@ -25,58 +25,38 @@
 
 #include <glib.h>
 #include <gtk/gtk.h>
+
+#include <net/ethernet.h>
+
+#if defined (LIBNM_BUILD)
+#include <NetworkManager.h>
+#elif defined (LIBNM_GLIB_BUILD)
 #include <nm-connection.h>
 #include <nm-device.h>
-#include <net/ethernet.h>
 #include <nm-access-point.h>
-
-
-#if defined (__GNUC__)
-#define _NM_PRAGMA_WARNING_DO(warning)       G_STRINGIFY(GCC diagnostic ignored warning)
-#elif defined (__clang__)
-#define _NM_PRAGMA_WARNING_DO(warning)       G_STRINGIFY(clang diagnostic ignored warning)
-#endif
-
-/* you can only suppress a specific warning that the compiler
- * understands. Otherwise you will get another compiler warning
- * about invalid pragma option.
- * It's not that bad however, because gcc and clang often have the
- * same name for the same warning. */
-
-#if defined (__GNUC__)
-#define NM_PRAGMA_WARNING_DISABLE(warning) \
-        _Pragma("GCC diagnostic push"); \
-        _Pragma(_NM_PRAGMA_WARNING_DO(warning))
-#elif defined (__clang__)
-#define NM_PRAGMA_WARNING_DISABLE(warning) \
-        _Pragma("clang diagnostic push"); \
-        _Pragma(_NM_PRAGMA_WARNING_DO(warning))
-#else
-#define NM_PRAGMA_WARNING_DISABLE(warning)
-#endif
-
-#if defined (__GNUC__)
-#define NM_PRAGMA_WARNING_REENABLE \
-    _Pragma("GCC diagnostic pop")
-#elif defined (__clang__)
-#define NM_PRAGMA_WARNING_REENABLE \
-    _Pragma("clang diagnostic pop")
 #else
-#define NM_PRAGMA_WARNING_REENABLE
+#error neither LIBNM_BUILD nor LIBNM_GLIB_BUILD defined
 #endif
 
-
 guint32 utils_freq_to_channel (guint32 freq);
 guint32 utils_channel_to_freq (guint32 channel, char *band);
 guint32 utils_find_next_channel (guint32 channel, int direction, char *band);
 
 gboolean utils_ether_addr_valid (const struct ether_addr *test_addr);
 
+#ifdef LIBNM_BUILD
+char *utils_hash_ap (GBytes *ssid,
+                     NM80211Mode mode,
+                     guint32 flags,
+                     guint32 wpa_flags,
+                     guint32 rsn_flags);
+#else
 char *utils_hash_ap (const GByteArray *ssid,
                      NM80211Mode mode,
                      guint32 flags,
                      guint32 wpa_flags,
                      guint32 rsn_flags);
+#endif
 
 char *utils_escape_notify_message (const char *src);
 
diff --git a/src/wireless-security/Makefile.am b/src/wireless-security/Makefile.am
index 4203050..78d5263 100644
--- a/src/wireless-security/Makefile.am
+++ b/src/wireless-security/Makefile.am
@@ -33,13 +33,14 @@ libwireless_security_la_SOURCES = \
 libwireless_security_la_CPPFLAGS = \
        $(GTK_CFLAGS) \
        -DUIDIR=\""$(uidir)"\" \
+       -DLIBNM_GLIB_BUILD \
        $(NMA_CFLAGS) \
        -I${top_srcdir}/src/utils
 
 libwireless_security_la_LIBADD = \
        $(GTK_LIBS) \
        $(NMA_LIBS) \
-       ${top_builddir}/src/utils/libutils.la
+       ${top_builddir}/src/utils/libutils-libnm-glib.la
 
 uidir = $(datadir)/nm-applet
 ui_DATA = \


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