[gnome-maps/wip/binary] Make gnome-maps a binary



commit ed46f6e1f396f3a6f3ebb883f0c955d422766a68
Author: Mattias Bengtsson <mattias jc bengtsson gmail com>
Date:   Tue Jan 21 06:50:12 2014 +0100

    Make gnome-maps a binary
    
    Make gnome-maps a small C program that loads JS from an included
    GResource.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=722338

 configure.ac                      |   13 +++++-
 src/Makefile-js.am                |   61 ++++++++++++++-------------
 src/Makefile.am                   |   82 +++++++++++++++++++++++++------------
 src/application.js                |    3 -
 src/gnome-maps.data.gresource.xml |   15 +++++++
 src/gnome-maps.gresource.xml      |   15 -------
 src/gnome-maps.in                 |   18 --------
 src/gnome-maps.js.gresource.xml   |   21 +++++++++
 src/main.c                        |   70 +++++++++++++++++++++++++++++++
 9 files changed, 205 insertions(+), 93 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 6d475b6..e5aaaa8 100644
--- a/configure.ac
+++ b/configure.ac
@@ -5,7 +5,7 @@ AC_INIT([gnome-maps],
         [gnome-maps])
 
 AC_CONFIG_HEADERS([config/config.h])
-AC_CONFIG_SRCDIR([src/main.js])
+AC_CONFIG_SRCDIR([src/main.c])
 AC_CONFIG_MACRO_DIR([m4])
 AC_CONFIG_AUX_DIR([config])
 
@@ -22,6 +22,17 @@ AC_DEFINE_UNQUOTED(GETTEXT_PACKAGE,"$GETTEXT_PACKAGE",[The name of the gettext d
 IT_PROG_INTLTOOL(0.40.0)
 PKG_PROG_PKG_CONFIG([0.22])
 
+GIO_MIN_VERSION=2.39.3
+GJS_MIN_VERSION=1.39.0
+GOBJECT_INTROSPECTION_MIN_VERSION=0.10.1
+
+PKG_CHECK_MODULES(GNOME_MAPS, [
+    gio-2.0                      >= $GIO_MIN_VERSION
+    gjs-1.0                      >= $GJS_MIN_VERSION
+    gobject-introspection-1.0    >= $GOBJECT_INTROSPECTION_MIN_VERSION
+])
+
+
 # no stupid static libraries
 AM_DISABLE_STATIC
 # enable libtool
diff --git a/src/Makefile-js.am b/src/Makefile-js.am
index a7055f5..4d2577f 100644
--- a/src/Makefile-js.am
+++ b/src/Makefile-js.am
@@ -1,37 +1,40 @@
-jsdir = $(pkgdatadir)/js/
-dist_js_DATA = \
-    application.js \
-    main.js \
-    mainWindow.js \
-    mapLocation.js \
-    mapView.js \
-    path.js \
-    sidebar.js \
-    settings.js \
-    utils.js \
-    userLocation.js \
-    geoclue.js \
-    zoomControl.js \
-    searchPopup.js \
-    contextMenu.js \
-    placeStore.js
-
-BUILT_SOURCES += \
-    path.js \
-    config.js
+BUILT_SOURCES +=                                                       \
+       path.js                                                         \
+       config.js
 
 path.js: Makefile path.js.in
        $(AM_V_GEN) $(do_subst) $(srcdir)/path.js.in > $@
 config.js: Makefile config.js.in
        $(AM_V_GEN) $(do_subst) $(srcdir)/config.js.in > $@
 
-nodist_js_DATA = \
-    path.js \
-    config.js
+js_files = $(shell $(GLIB_COMPILE_RESOURCES)                           \
+               --sourcedir=$(srcdir)                                   \
+               --generate-dependencies $(srcdir)/gnome-maps.js.gresource.xml)
+
+gnome-maps-js.h: gnome-maps.js.gresource.xml $(js_files) path.js config.js
+       $(AM_V_GEN)                                                     \
+               $(GLIB_COMPILE_RESOURCES)                               \
+               --target=$@                                             \
+               --sourcedir=$(srcdir)                                   \
+               --sourcedir=$(builddir)                                 \
+               --generate                                              \
+               --c-name gnome_maps_js $<
+gnome-maps-js.c: gnome-maps.js.gresource.xml $(js_files) path.js config.js
+       $(AM_V_GEN) \
+               $(GLIB_COMPILE_RESOURCES)                               \
+               --target=$@                                             \
+               --sourcedir=$(srcdir)                                   \
+               --sourcedir=$(builddir)                                 \
+               --generate                                              \
+               --c-name gnome_maps_js $<
+
+js_built_sources = gnome-maps-js.c gnome-maps-js.h
+
+BUILT_SOURCES += $(js_built_sources)
 
-CLEANFILES += \
-    $(BUILT_SOURCES)
+CLEANFILES += $(js_built_sources)
 
-EXTRA_DIST += \
-    path.js.in \
-    config.js.in
+EXTRA_DIST +=                                                          \
+       gnome-maps.js.gresource.xml                                     \
+       path.js.in                                                      \
+       config.js.in
diff --git a/src/Makefile.am b/src/Makefile.am
index b5dbbc0..f0223c3 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -4,39 +4,67 @@ CLEANFILES =
 
 # convenience command for doing Makefile variable substitutions in non-Makefile
 # files (scripts, service files, etc.)
-do_subst = sed -e 's|@abs_top_srcdir[ ]|$(abs_top_srcdir)|g' \
-               -e 's|@abs_top_builddir[ ]|$(abs_top_builddir)|g' \
-               -e 's|@localedir[ ]|$(localedir)|g' \
-               -e 's|@bindir[ ]|$(bindir)|g' \
-               -e 's|@libdir[ ]|$(libdir)|g' \
-               -e 's|@libexecdir[ ]|$(libexecdir)|g' \
-               -e 's|@pkglibdir[ ]|$(pkglibdir)|g' \
-               -e 's|@pkgdatadir[ ]|$(pkgdatadir)|g' \
-               -e 's|@GJS_CONSOLE[ ]|$(GJS_CONSOLE)|g' \
-               -e 's|@PACKAGE_NAME[ ]|$(PACKAGE_NAME)|g' \
-               -e 's|@PACKAGE_VERSION[ ]|$(PACKAGE_VERSION)|g' \
-               -e 's|@GETTEXT_PACKAGE[ ]|$(GETTEXT_PACKAGE)|g'
+do_subst = sed  -e 's|@abs_top_srcdir[ ]|$(abs_top_srcdir)|g'          \
+               -e 's|@abs_top_builddir[ ]|$(abs_top_builddir)|g'       \
+               -e 's|@localedir[ ]|$(localedir)|g'                     \
+               -e 's|@bindir[ ]|$(bindir)|g'                           \
+               -e 's|@libdir[ ]|$(libdir)|g'                           \
+               -e 's|@libexecdir[ ]|$(libexecdir)|g'                   \
+               -e 's|@pkglibdir[ ]|$(pkglibdir)|g'                     \
+               -e 's|@pkgdatadir[ ]|$(pkgdatadir)|g'                   \
+               -e 's|@GJS_CONSOLE[ ]|$(GJS_CONSOLE)|g'                 \
+               -e 's|@PACKAGE_NAME[ ]|$(PACKAGE_NAME)|g'               \
+               -e 's|@PACKAGE_VERSION[ ]|$(PACKAGE_VERSION)|g'         \
+               -e 's|@GETTEXT_PACKAGE[ ]|$(GETTEXT_PACKAGE)|g'
 
 include $(INTROSPECTION_MAKEFILE)
 include Makefile-js.am
 
-resource_files = $(shell $(GLIB_COMPILE_RESOURCES) --sourcedir=$(srcdir) --generate-dependencies 
$(srcdir)/gnome-maps.gresource.xml)
-gnome-maps.gresource: gnome-maps.gresource.xml $(resource_files)
-       $(AM_V_GEN) $(GLIB_COMPILE_RESOURCES) --target=$@ --sourcedir=$(srcdir) $<
-EXTRA_DIST += gnome-maps.gresource.xml $(resource_files)
+data_files = $(shell $(GLIB_COMPILE_RESOURCES)                         \
+               --sourcedir=$(srcdir)                                   \
+               --generate-dependencies $(srcdir)/gnome-maps.data.gresource.xml)
 
-resourcedir = $(pkgdatadir)
-resource_DATA = gnome-maps.gresource
+gnome-maps-data.h: gnome-maps.data.gresource.xml $(data_files)
+       $(AM_V_GEN)                                                     \
+               $(GLIB_COMPILE_RESOURCES)                               \
+               --target=$@                                             \
+               --sourcedir=$(srcdir)                                   \
+               --sourcedir=$(builddir)                                 \
+               --generate                                              \
+               --c-name gnome_maps_data $<
+gnome-maps-data.c: gnome-maps.data.gresource.xml $(data_files)
+       $(AM_V_GEN)                                                     \
+               $(GLIB_COMPILE_RESOURCES)                               \
+               --target=$@                                             \
+               --sourcedir=$(srcdir)                                   \
+               --sourcedir=$(builddir)                                 \
+               --generate                                              \
+               --c-name gnome_maps_data $<
 
-CLEANFILES += gnome-maps.gresource
+EXTRA_DIST += gnome-maps.data.gresource.xml $(resource_files)
 
-bin_SCRIPTS = gnome-maps
+data_built_sources = gnome-maps-data.c gnome-maps-data.h
 
-gnome-maps: gnome-maps.in
-       $(AM_V_GEN) $(do_subst) $< > $@
-       chmod +x $@
+BUILT_SOURCES += $(data_built_sources)
 
-CLEANFILES += \
-    gnome-maps
-EXTRA_DIST += \
-    gnome-maps.in
+bin_PROGRAMS = gnome-maps
+
+CLEANFILES +=                                                          \
+    gnome-maps                                                         \
+       $(data_built_sources)
+
+gnome_maps_SOURCES = main.c                                            \
+       $(NULL)
+nodist_gnome_maps_SOURCES =                                            \
+       $(top_builddir)/src/gnome-maps-data.c                           \
+       $(top_builddir)/src/gnome-maps-data.h                           \
+       $(top_builddir)/src/gnome-maps-js.c                             \
+       $(top_builddir)/src/gnome-maps-js.h                             \
+       $(NULL)
+
+gnome_maps_CPPFLAGS =                                                  \
+       $(GNOME_MAPS_CFLAGS)                                            \
+       -DLOCALEDIR=\"$(localedir)\"                                    \
+       -DGNOME_MAPS_PKGLIBDIR=\"$(pkglibdir)\"
+gnome_maps_LDADD =                                                     \
+       $(GNOME_MAPS_LIBS)
diff --git a/src/application.js b/src/application.js
index 3a67dc6..de4cdfc 100644
--- a/src/application.js
+++ b/src/application.js
@@ -75,9 +75,6 @@ const Application = new Lang.Class({
 
         GtkClutter.init(null);
 
-        let resource = Gio.Resource.load(Path.RESOURCE_DIR + '/gnome-maps.gresource');
-        resource._register();
-
         Utils.loadStyleSheet(Gio.file_new_for_uri('resource:///org/gnome/maps/application.css'));
 
         application = this;
diff --git a/src/gnome-maps.data.gresource.xml b/src/gnome-maps.data.gresource.xml
new file mode 100644
index 0000000..b56e35f
--- /dev/null
+++ b/src/gnome-maps.data.gresource.xml
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<gresources>
+  <gresource prefix="/org/gnome/maps">
+       <file preprocess="xml-stripblanks">app-menu.ui</file>
+       <file preprocess="xml-stripblanks">main-window.ui</file>
+       <file preprocess="xml-stripblanks">zoom-control.ui</file>
+       <file preprocess="xml-stripblanks">search-popup.ui</file>
+       <file preprocess="xml-stripblanks">context-menu.ui</file>
+       <file alias="application.css">../data/gnome-maps.css</file>
+       <file alias="zoom-in.png">../data/media/zoom-in.png</file>
+       <file alias="zoom-out.png">../data/media/zoom-out.png</file>
+       <file alias="zoom-in-insensitive.png">../data/media/zoom-in-insensitive.png</file>
+       <file alias="zoom-out-insensitive.png">../data/media/zoom-out-insensitive.png</file>
+  </gresource>
+</gresources>
diff --git a/src/gnome-maps.js.gresource.xml b/src/gnome-maps.js.gresource.xml
new file mode 100644
index 0000000..cb9a57c
--- /dev/null
+++ b/src/gnome-maps.js.gresource.xml
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<gresources>
+  <gresource prefix="/org/gnome/maps">
+    <file>application.js</file>
+    <file>config.js</file>
+    <file>contextMenu.js</file>
+    <file>geoclue.js</file>
+    <file>main.js</file>
+    <file>mainWindow.js</file>
+    <file>mapLocation.js</file>
+    <file>mapView.js</file>
+    <file>path.js</file>
+    <file>placeStore.js</file>
+    <file>searchPopup.js</file>
+    <file>settings.js</file>
+    <file>sidebar.js</file>
+    <file>userLocation.js</file>
+    <file>utils.js</file>
+    <file>zoomControl.js</file>
+  </gresource>
+</gresources>
diff --git a/src/main.c b/src/main.c
new file mode 100644
index 0000000..b2bb1ac
--- /dev/null
+++ b/src/main.c
@@ -0,0 +1,70 @@
+/* -*- Mode: C; indent-tabs-mode: nil; js2-basic-offset: 4 -*- */
+/* vim: set et ts=4 sw=4: */
+/*
+ * GNOME Maps is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
+ *
+ * GNOME Maps 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 General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with GNOME Maps; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ * Author: Florian Müllner <fmuellner gnome org>
+ *         Mattias Bengtsson <mattias jc bengtsson gmail com>
+ */
+
+#include "config.h"
+
+#include <girepository.h>
+#include <gjs/gjs.h>
+
+int
+main (int argc, char *argv)
+{
+  const char *search_path[] = { "resource:///org/gnome/maps", NULL };
+  GError *error = NULL;
+  GjsContext *context;
+  int status;
+
+  bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
+  bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
+  textdomain (GETTEXT_PACKAGE);
+
+  g_irepository_prepend_search_path (GNOME_MAPS_PKGLIBDIR);
+
+  context = g_object_new (GJS_TYPE_CONTEXT,
+                          "search-path", search_path,
+                          NULL);
+
+  if (!gjs_context_define_string_array(context, "ARGV",
+                                       argc - 1, (const char**)argv + 1,
+                                       &error))
+    {
+      g_message("Failed to defined ARGV: %s", error->message);
+      g_error_free (error);
+
+      return 1;
+    }
+
+
+  if (!gjs_context_eval (context,
+                         "const Main = imports.main; Main.start();",
+                         -1,
+                         "<main>",
+                         &status,
+                         &error))
+    {
+      g_message ("Execution of main.js threw exception: %s", error->message);
+      g_error_free (error);
+
+      return status;
+    }
+
+  return 0;
+}


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