From 2b38df94db70b05627b043b29a388d760a59c46b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?I=C3=B1igo=20Mart=C3=ADnez?= Date: Tue, 13 Feb 2018 15:33:23 +0100 Subject: [PATCH] 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. https://bugs.freedesktop.org/show_bug.cgi?id=104273 --- .../act-user-enum-types.c.template | 37 ++++++++++++++++++++++ .../act-user-enum-types.h.template | 23 ++++++++++++++ src/libaccountsservice/meson.build | 21 +++--------- 3 files changed, 64 insertions(+), 17 deletions(-) create mode 100644 src/libaccountsservice/act-user-enum-types.c.template create mode 100644 src/libaccountsservice/act-user-enum-types.h.template diff --git a/src/libaccountsservice/act-user-enum-types.c.template b/src/libaccountsservice/act-user-enum-types.c.template new file mode 100644 index 0000000..1d1b745 --- /dev/null +++ b/src/libaccountsservice/act-user-enum-types.c.template @@ -0,0 +1,37 @@ +/*** BEGIN file-header ***/ +#include "act-user-enum-types.h" +#include + +/*** 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 ***/ + +/*** BEGIN file-tail ***/ +/*** END file-tail ***/ diff --git a/src/libaccountsservice/act-user-enum-types.h.template b/src/libaccountsservice/act-user-enum-types.h.template new file mode 100644 index 0000000..110a9ea --- /dev/null +++ b/src/libaccountsservice/act-user-enum-types.h.template @@ -0,0 +1,23 @@ +/*** BEGIN file-header ***/ +#ifndef __ACT_USER_ENUM_TYPES_H__ +#define __ACT_USER_ENUM_TYPES_H__ + +#include + +G_BEGIN_DECLS +/*** END file-header ***/ + +/*** BEGIN file-production ***/ +/* enumerations from "@basename@" */ +/*** END file-production ***/ + +/*** BEGIN value-header ***/ +GType @enum_name@_get_type (void) G_GNUC_CONST; +#define ACT_USER_TYPE_@ENUMSHORT@ (@enum_name@_get_type()) +/*** END value-header ***/ + +/*** BEGIN file-tail ***/ +G_END_DECLS + +#endif /* __ACT_USER_ENUM_TYPES_H__ */ +/*** END file-tail ***/ diff --git a/src/libaccountsservice/meson.build b/src/libaccountsservice/meson.build index b09edf9..dd832d8 100644 --- a/src/libaccountsservice/meson.build +++ b/src/libaccountsservice/meson.build @@ -17,30 +17,17 @@ sources = files( 'act-user-manager.c' ) -enum_sources = [] enum_types = 'act-user-enum-types' -enum_sources += gnome.mkenums( - enum_types + '.h', +enum_sources = gnome.mkenums( + enum_types, sources: headers, - fhead: '#ifndef __ACT_USER_ENUM_TYPES_H__\n#define __ACT_USER_ENUM_TYPES_H__\n\n#include \n\nG_BEGIN_DECLS\n', - fprod: '/* enumerations from "@filename@" */\n', - vhead: 'GType @enum_name@_get_type (void);\n#define ACT_USER_TYPE_@ENUMSHORT@ (@enum_name@_get_type())\n', - ftail: 'G_END_DECLS\n\n#endif /* __ACT_USER_ENUM_TYPES_H__ */', + h_template: enum_types + '.h.template', + c_template: enum_types + '.c.template', install_header: true, install_dir: join_paths(act_pkgincludedir, subdir) ) -enum_sources += gnome.mkenums( - enum_types + '.c', - sources: headers, - fhead: '#include "act-user.h"\n#include "act-user-manager.h"\n#include "act-user-enum-types.h"\n#include \n\n', - 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' -) - dbus_sources = [] ifaces = [ -- 2.16.1