[gobject-introspection] examples: Make self contained and add build system integration examples



commit 3ed45723550a21d714ac34a82d20e4aa2d7f9958
Author: Christoph Reiter <reiter christoph gmail com>
Date:   Sat Nov 9 15:26:27 2019 +0100

    examples: Make self contained and add build system integration examples
    
    The libgirepository example now is its own meson project.
    
    There now is a small library that is buildable with meson and autotools
    which creates a gir/typelib. Usefull for testing our build system integration
    and for small experiments.
    
    Fixes #287

 docs/website/writingbindings/libgirepository.rst |   2 +-
 examples/{ => girepository}/glib-print.c         |   0
 examples/girepository/meson.build                |   7 ++
 examples/library/Makefile.am                     |  40 ++++++++
 examples/library/autogen.sh                      |  38 ++++++++
 examples/library/configure.ac                    |  14 +++
 examples/library/gi-sample.c                     | 117 +++++++++++++++++++++++
 examples/library/gi-sample.h                     |  17 ++++
 examples/library/meson.build                     |  24 +++++
 examples/meson.build                             |   3 -
 meson.build                                      |   1 -
 11 files changed, 258 insertions(+), 5 deletions(-)
---
diff --git a/docs/website/writingbindings/libgirepository.rst 
b/docs/website/writingbindings/libgirepository.rst
index 780a12ce..86a3558d 100644
--- a/docs/website/writingbindings/libgirepository.rst
+++ b/docs/website/writingbindings/libgirepository.rst
@@ -12,5 +12,5 @@ For more information about libgirepository see the `API documentation
 The following example shows how to call the ``g_assertion_message()`` function
 from libglib-2.0:
 
-.. literalinclude:: ../../../examples/glib-print.c
+.. literalinclude:: ../../../examples/girepository/glib-print.c
     :language: c
diff --git a/examples/glib-print.c b/examples/girepository/glib-print.c
similarity index 100%
rename from examples/glib-print.c
rename to examples/girepository/glib-print.c
diff --git a/examples/girepository/meson.build b/examples/girepository/meson.build
new file mode 100644
index 00000000..e3e0b7eb
--- /dev/null
+++ b/examples/girepository/meson.build
@@ -0,0 +1,7 @@
+project('girepository-sample', 'c')
+
+girepo_dep = dependency('gobject-introspection-1.0')
+
+executable('glib-print', 'glib-print.c',
+  dependencies: girepo_dep,
+)
diff --git a/examples/library/Makefile.am b/examples/library/Makefile.am
new file mode 100644
index 00000000..e0c77cd5
--- /dev/null
+++ b/examples/library/Makefile.am
@@ -0,0 +1,40 @@
+source_h = \
+       gi-sample.h     \
+       $(NULL)
+
+source_c = \
+       gi-sample.c             \
+       $(NULL)
+
+lib_LTLIBRARIES =
+lib_LTLIBRARIES += libgi-sample.la
+
+libgi_sample_la_CFLAGS = $(GISAMPLE_CFLAGS)
+libgi_sample_la_LIBADD = $(GISAMPLE_LIBS)
+libgi_sample_la_SOURCES = $(source_c) $(source_h)
+libgi_sample_la_LDFLAGS = -export-dynamic
+
+-include $(INTROSPECTION_MAKEFILE)
+
+DISTCHECK_CONFIGURE_FLAGS = --enable-introspection
+
+INTROSPECTION_GIRS = GISample-1.0.gir
+
+GISample-1.0.gir: libgi-sample.la
+
+GISample_1_0_gir_NAMESPACE = GISample
+GISample_1_0_gir_VERSION = 1.0
+GISample_1_0_gir_LIBS = libgi-sample.la
+GISample_1_0_gir_FILES = $(source_c) $(source_h)
+GISample_1_0_gir_CFLAGS = -I$(top_srcdir) -I$(top_builddir) $(GISAMPLE_CFLAGS)
+GISample_1_0_gir_INCLUDES = GObject-2.0
+GISample_1_0_gir_SCANNERFLAGS = --warn-all --symbol-prefix=gi_sample
+
+girdir = $(datadir)/gir-1.0
+dist_gir_DATA = GISample-1.0.gir
+
+typelibsdir = $(libdir)/girepository-1.0/
+typelibs_DATA = GISample-1.0.typelib
+
+CLEANFILES =
+CLEANFILES += $(dist_gir_DATA) $(typelibs_DATA)
diff --git a/examples/library/autogen.sh b/examples/library/autogen.sh
new file mode 100755
index 00000000..d9d12ecf
--- /dev/null
+++ b/examples/library/autogen.sh
@@ -0,0 +1,38 @@
+#!/bin/sh
+# Run this to generate all the initial makefiles, etc.
+test -n "$srcdir" || srcdir=$(dirname "$0")
+test -n "$srcdir" || srcdir=.
+
+olddir=$(pwd)
+
+cd $srcdir
+
+(test -f configure.ac) || {
+        echo "*** ERROR: Directory '$srcdir' does not look like the top-level project directory ***"
+        exit 1
+}
+
+# shellcheck disable=SC2016
+PKG_NAME=$(autoconf --trace 'AC_INIT:$1' configure.ac)
+
+if [ "$#" = 0 -a "x$NOCONFIGURE" = "x" ]; then
+        echo "*** WARNING: I am going to run 'configure' with no arguments." >&2
+        echo "*** If you wish to pass any to it, please specify them on the" >&2
+        echo "*** '$0' command line." >&2
+        echo "" >&2
+fi
+
+autoreconf --verbose --force --install || exit 1
+
+cd "$olddir"
+if [ "$NOCONFIGURE" = "" ]; then
+        $srcdir/configure "$@" || exit 1
+
+        if [ "$1" = "--help" ]; then
+                exit 0
+        else
+                echo "Now type 'make' to compile $PKG_NAME" || exit 1
+        fi
+else
+        echo "Skipping configure process."
+fi
diff --git a/examples/library/configure.ac b/examples/library/configure.ac
new file mode 100644
index 00000000..ee0453dd
--- /dev/null
+++ b/examples/library/configure.ac
@@ -0,0 +1,14 @@
+AC_PREREQ([2.63])
+AC_INIT([gi-sample-autotools], [0.0.1])
+
+AM_INIT_AUTOMAKE([1.11 no-define foreign])
+AM_SILENT_RULES([yes])
+
+LT_PREREQ([2.2])
+LT_INIT([disable-static])
+
+PKG_CHECK_MODULES(GISAMPLE, [gobject-2.0])
+GOBJECT_INTROSPECTION_CHECK([1.30.0])
+
+AC_CONFIG_FILES([Makefile])
+AC_OUTPUT
diff --git a/examples/library/gi-sample.c b/examples/library/gi-sample.c
new file mode 100644
index 00000000..9a0fc7ac
--- /dev/null
+++ b/examples/library/gi-sample.c
@@ -0,0 +1,117 @@
+#include "gi-sample.h"
+
+struct _GISampleThing
+{
+  GObject parent_instance;
+
+  gchar *msg;
+};
+
+G_DEFINE_TYPE (GISampleThing, gi_sample_thing, G_TYPE_OBJECT)
+
+enum {
+  PROP_0,
+  PROP_MSG,
+  LAST_PROP
+};
+
+static GParamSpec *gParamSpecs [LAST_PROP];
+
+/**
+ * gi_sample_thing_new:
+ *
+ * Allocates a new #GISampleThing.
+ *
+ * Returns: (transfer full): a #GISampleThing.
+ */
+GISampleThing *
+gi_sample_thing_new (void)
+{
+  return g_object_new (GI_TYPE_SAMPLE_THING, NULL);
+}
+
+static void
+gi_sample_thing_finalize (GObject *object)
+{
+  GISampleThing *self = (GISampleThing *)object;
+
+  g_clear_pointer (&self->msg, g_free);
+
+  G_OBJECT_CLASS (gi_sample_thing_parent_class)->finalize (object);
+}
+
+static void
+gi_sample_thing_get_property (GObject    *object,
+                              guint       prop_id,
+                              GValue     *value,
+                              GParamSpec *pspec)
+{
+  GISampleThing *self = GI_SAMPLE_THING (object);
+
+  switch (prop_id)
+    {
+    case PROP_MSG:
+      g_value_set_string (value, self->msg);
+      break;
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+    }
+}
+
+static void
+gi_sample_thing_set_property (GObject      *object,
+                              guint         prop_id,
+                              const GValue *value,
+                              GParamSpec   *pspec)
+{
+  GISampleThing *self = GI_SAMPLE_THING (object);
+
+  switch (prop_id)
+    {
+    case PROP_MSG:
+      self->msg = g_value_dup_string (value);
+      break;
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+    }
+}
+
+static void
+gi_sample_thing_class_init (GISampleThingClass *klass)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+  object_class->finalize = gi_sample_thing_finalize;
+  object_class->get_property = gi_sample_thing_get_property;
+  object_class->set_property = gi_sample_thing_set_property;
+
+  gParamSpecs [PROP_MSG] =
+    g_param_spec_string ("message",
+                         "Message",
+                         "The message to print.",
+                         NULL,
+                         (G_PARAM_READWRITE |
+                          G_PARAM_CONSTRUCT_ONLY |
+                          G_PARAM_STATIC_STRINGS));
+
+  g_object_class_install_properties (object_class, LAST_PROP, gParamSpecs);
+}
+
+static void
+gi_sample_thing_init (GISampleThing *self)
+{
+}
+
+/**
+ * gi_sample_thing_print_message:
+ * @self: a #GISampleThing.
+ *
+ * Prints the message.
+ */
+void
+gi_sample_thing_print_message (GISampleThing *self)
+{
+  g_return_if_fail (GI_IS_SAMPLE_THING (self));
+
+  g_print ("Message: %s\n", self->msg);
+}
diff --git a/examples/library/gi-sample.h b/examples/library/gi-sample.h
new file mode 100644
index 00000000..3f6172af
--- /dev/null
+++ b/examples/library/gi-sample.h
@@ -0,0 +1,17 @@
+#ifndef GI_SAMPLE_H
+#define GI_SAMPLE_H
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define GI_TYPE_SAMPLE_THING (gi_sample_thing_get_type())
+
+G_DECLARE_FINAL_TYPE (GISampleThing, gi_sample_thing, GI, SAMPLE_THING, GObject)
+
+GISampleThing    *gi_sample_thing_new           (void);
+void              gi_sample_thing_print_message (GISampleThing *self);
+
+G_END_DECLS
+
+#endif /* GI_SAMPLE_H */
diff --git a/examples/library/meson.build b/examples/library/meson.build
new file mode 100644
index 00000000..2313ffd6
--- /dev/null
+++ b/examples/library/meson.build
@@ -0,0 +1,24 @@
+project('gi-sample-meson', 'c')
+
+libsources = ['gi-sample.c', 'gi-sample.h']
+
+gnome = import('gnome')
+gobj_dep = dependency('gobject-2.0')
+
+girlib = shared_library(
+  'gi-sample',
+  sources : libsources,
+  dependencies : [gobj_dep],
+  install : true
+)
+
+gnome.generate_gir(
+  girlib,
+  sources : libsources,
+  nsversion : '1.0',
+  namespace : 'GISample',
+  symbol_prefix : 'gi_sample',
+  identifier_prefix : 'GISample',
+  includes : ['GObject-2.0'],
+  install : true,
+)
diff --git a/meson.build b/meson.build
index 496813e9..88fb2f9e 100644
--- a/meson.build
+++ b/meson.build
@@ -198,7 +198,6 @@ subdir('girepository')
 subdir('tools')
 subdir('giscanner')
 subdir('gir')
-subdir('examples')
 subdir('docs')
 subdir('tests')
 


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