[polari/wip/resources: 2/3] build: Replace gjs-console with a small executable



commit 308b5f87e43006f1da234d6015a8e5ec7365f7af
Author: Florian Müllner <fmuellner gnome org>
Date:   Thu Oct 31 01:34:46 2013 +0100

    build: Replace gjs-console with a small executable

 configure.ac       |    7 +------
 src/Makefile.am    |   26 +++++++++++++++++++-------
 src/application.js |    2 --
 src/config.js.in   |    1 -
 src/polari.c       |   48 ++++++++++++++++++++++++++++++++++++++++++++++++
 src/polari.in      |   20 --------------------
 6 files changed, 68 insertions(+), 36 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 81da50a..a3b3159 100644
--- a/configure.ac
+++ b/configure.ac
@@ -22,16 +22,11 @@ GLIB_GSETTINGS
 
 PKG_CHECK_MODULES(POLARI,
                   gio-2.0
+                  gjs-1.0
                   gobject-introspection-1.0
                   gtk+-3.0 >= 3.9.12
                   telepathy-glib);
 
-AC_PATH_PROG([GJS_CONSOLE],[gjs-console],[no])
-
-if test "$GJS_CONSOLE" = "no"; then
-  AC_MSG_ERROR([gjs is required to build Polari])
-fi
-
 GLIB_COMPILE_RESOURCES=`$PKG_CONFIG --variable=glib_compile_resources gio-2.0`
 AC_SUBST(GLIB_COMPILE_RESOURCES)
 
diff --git a/src/Makefile.am b/src/Makefile.am
index 75a6ce2..60347de 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -20,11 +20,6 @@ do_subst = sed -e 's|@localedir[ ]|$(localedir)|g' \
                -e 's|@PACKAGE_VERSION[ ]|$(PACKAGE_VERSION)|g' \
                $(NULL)
 
-bin_SCRIPTS = polari
-
-polari: polari.in
-       $(AM_V_GEN) $(do_subst) $< > $@
-
 jsdir = $(pkgdatadir)/js/
 dist_js_DATA = \
        accountsMonitor.js \
@@ -53,6 +48,25 @@ nodist_js_DATA = \
        config.js \
        $(NULL)
 
+bin_PROGRAMS = polari
+
+polari_SOURCES = \
+       polari.c \
+       $(NULL)
+
+AM_CPPFLAGS = \
+       -DPOLARI_TYPELIBDIR=\""$(pkglibdir)/girepository-1.0"\" \
+       -DPOLARI_JSDIR=\""$(pkglibdir)/js"\" \
+       -DLOCALEDIR=\""$(datadir)/locale"\" \
+       -DGETTEXT_PACKAGE=\""$(GETTEXT_PACKAGE)"\" \
+       $(POLARI_CFLAGS) \
+       $(NULL)
+
+polari_LDADD = \
+       $(POLARI_LIBS) \
+       libpolari-1.0.la \
+       $(NULL)
+
 resource_files=$(shell $(GLIB_COMPILE_RESOURCES) --sourcedir=$(srcdir) --generate-dependencies 
$(srcdir)/polari.gresource.xml)
 polari.gresource: polari.gresource.xml $(resource_files)
        $(AM_V_GEN) $(GLIB_COMPILE_RESOURCES) --target=$@ --sourcedir=$(srcdir) $<
@@ -63,12 +77,10 @@ resource_DATA=polari.gresource
 EXTRA_DIST += \
        config.js.in \
        polari.gresource.xml \
-       polari.in \
        $(resource_files) \
        $(NULL)
 
 CLEANFILES += \
        config.js \
-       polari \
        $(resource_DATA) \
        $(NULL)
diff --git a/src/application.js b/src/application.js
index bfeed82..3a6d137 100644
--- a/src/application.js
+++ b/src/application.js
@@ -29,8 +29,6 @@ const Application = new Lang.Class({
     _init: function() {
         this.parent({ application_id: 'org.gnome.Polari' });
 
-        Gettext.bindtextdomain('polari', Config.LOCALE_DIR);
-        Gettext.textdomain('polari');
         GLib.set_prgname('polari');
         GLib.set_application_name('Polari');
         this._window = null;
diff --git a/src/config.js.in b/src/config.js.in
index 148106b..2f5082f 100644
--- a/src/config.js.in
+++ b/src/config.js.in
@@ -1,3 +1,2 @@
-const LOCALE_DIR = "@localedir@";
 const RESOURCE_DIR = "@pkgdatadir@";
 const PACKAGE_VERSION = "@PACKAGE_VERSION@";
diff --git a/src/polari.c b/src/polari.c
new file mode 100644
index 0000000..9e7743b
--- /dev/null
+++ b/src/polari.c
@@ -0,0 +1,48 @@
+#include <girepository.h>
+#include <gjs/gjs.h>
+
+int
+main (int argc, char *argv)
+{
+  const char *search_path[] = { POLARI_JSDIR, 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 (POLARI_TYPELIBDIR);
+
+  context = g_object_new (GJS_TYPE_CONTEXT,
+                          "search-path", search_path,
+                          "js-version", "1.8",
+                          NULL);
+
+  if (!gjs_context_define_string_array(context, "ARGV",
+                                       argc, (const char**)argv,
+                                       &error))
+    {
+      g_message("Failed to defined ARGV: %s", error->message);
+      g_error_free (error);
+
+      return 1;
+    }
+
+
+  if (!gjs_context_eval (context,
+                         "imports.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]