[totem/wip/inigomartinez/meson-improve: 12/16] build: Use template files for enums generation



commit 47eaa20bf1e5c9a797561dd27ec5f4b2e1ae1659
Author: Iñigo Martínez <inigomartinez gmail com>
Date:   Mon Feb 19 19:48:20 2018 +0100

    build: Use template files for enums generation
    
    The data contents for the enum related files are stored in the
    build files.
    
    This patch moves this information to template files to be used
    along with glib-mkenums.

 src/backend/bacon-video-widget-enums.c.template |   34 +++++++++++++++++++++++
 src/backend/bacon-video-widget-enums.h.template |   27 ++++++++++++++++++
 src/backend/meson.build                         |   21 +++-----------
 3 files changed, 65 insertions(+), 17 deletions(-)
---
diff --git a/src/backend/bacon-video-widget-enums.c.template b/src/backend/bacon-video-widget-enums.c.template
new file mode 100644
index 0000000..38ea6ac
--- /dev/null
+++ b/src/backend/bacon-video-widget-enums.c.template
@@ -0,0 +1,34 @@
+/*** BEGIN file-header ***/
+#include "bacon-video-widget-enums.h"
+#include <glib-object.h>
+
+/*** END file-header ***/
+
+/*** BEGIN file-production ***/
+/* enumerations from "@basename@" */
+#include "@basename@"
+
+/*** END file-production ***/
+
+/*** BEGIN value-header ***/
+GType
+@enum_name@_get_type (void)
+{
+  static GType etype = 0;
+  if (etype == 0) {
+    static const G@Type@Value values[] = {
+/*** END value-header ***/
+
+/*** BEGIN value-production ***/
+      { @VALUENAME@, "@VALUENAME@", "@valuenick@" },
+/*** END value-production ***/
+
+/*** BEGIN value-tail ***/
+      { 0, NULL, NULL }
+    };
+    etype = g_@type@_register_static ("@EnumName@", values);
+  }
+  return etype;
+}
+
+/*** END value-tail ***/
diff --git a/src/backend/bacon-video-widget-enums.h.template b/src/backend/bacon-video-widget-enums.h.template
new file mode 100644
index 0000000..56b683d
--- /dev/null
+++ b/src/backend/bacon-video-widget-enums.h.template
@@ -0,0 +1,27 @@
+/*** BEGIN file-header ***/
+#ifndef BVW_ENUMS_H
+#define BVW_ENUMS_H
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+/*** END file-header ***/
+
+/*** BEGIN file-production ***/
+/* enumerations from "@basename@" */
+
+/*** END file-production ***/
+
+/*** BEGIN enumeration-production ***/
+GType @enum_name@_get_type (void) G_GNUC_CONST;
+#define BVW_TYPE_@ENUMSHORT@ (@enum_name@_get_type())
+
+/*** END enumeration-production ***/
+
+/*** BEGIN file-tail ***/
+G_END_DECLS
+
+#endif /* !BVW_ENUMS_H */
+/*** END file-tail ***/
+
diff --git a/src/backend/meson.build b/src/backend/meson.build
index 35c0b41..cc97798 100644
--- a/src/backend/meson.build
+++ b/src/backend/meson.build
@@ -37,24 +37,11 @@ sources = files(
 enum = 'bacon-video-widget-enums'
 enum_headers = files('bacon-video-widget.h')
 
-enum_sources = []
-enum_sources += gnome.mkenums(
-  enum + '.c',
+enum_sources = gnome.mkenums(
+  enum,
   sources: enum_headers,
-  fhead: '#include "bacon-video-widget.h"\n#include "bacon-video-widget-enums.h"',
-  fprod: '\n/* enumerations from "@filename@" */',
-  vhead: 'GType\n@enum_name@_get_type (void)\n{\n  static GType etype = 0;\n  if (etype == 0) {\n    static 
const G@Type@Value values[] = {',
-  vprod: '      { @VALUENAME@, "@VALUENAME@", "@valuenick@" },',
-  vtail: '      { 0, NULL, NULL }\n    };\n    etype = g_@type@_register_static ("@EnumName@", values);\n  
}\n  return etype;\n}\n'
-)
-
-enum_sources += gnome.mkenums(
-  enum + '.h',
-  sources: enum_headers,
-  fhead: '#ifndef BVW_ENUMS_H\n#define BVW_ENUMS_H\n\n#include <glib-object.h>\n\nG_BEGIN_DECLS\n',
-  fprod: '/* enumerations from "@filename@" */\n',
-  vhead: 'GType @enum_name@_get_type (void) G_GNUC_CONST;\n#define BVW_TYPE_@ENUMSHORT@ 
(@enum_name@_get_type())\n',
-  ftail: 'G_END_DECLS\n\n#endif /* !BVW_ENUMS_H */'
+  c_template: enum + '.c.template',
+  h_template: enum + '.h.template'
 )
 
 deps = [


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