[almanah] build: Update glib-mkenums build rules



commit 06dc5b67203730e1dc8a9362dc74c5d72de577b0
Author: Philip Withnall <philip tecnocode co uk>
Date:   Mon Dec 12 14:54:49 2016 +0000

    build: Update glib-mkenums build rules
    
    Update the build rules to:
     • Atomically replace the target files to avoid race conditions while
       building.
     • Not distribute the generated files, as they are generated.
     • Use template files instead of putting C and escaped newlines in
       Makefile.am in some grotesque display of nesting.
     • Rename from event-factory-builtins.[ch] to enums.[ch] to more
       accurately reflect what they contain.
    
    This might fix https://bugzilla.redhat.com/show_bug.cgi?id=1403508.

 src/Makefile.am      |   64 +++++++++++++++++++++++++++++---------------------
 src/enums.c.template |   56 +++++++++++++++++++++++++++++++++++++++++++
 src/enums.h.template |   43 +++++++++++++++++++++++++++++++++
 src/event-factory.c  |    2 +-
 src/event-manager.c  |    2 +-
 5 files changed, 138 insertions(+), 29 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index dd532d5..40982c3 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1,11 +1,11 @@
 bin_PROGRAMS = almanah
 
+BUILT_SOURCES =
 EXTRA_DIST =
 CLEANFILES =
 
 almanah_SOURCES = \
        $(ALMANAH_MARSHAL_FILES)                \
-       $(ALMANAH_ENUM_FILES)                   \
        main.c                                  \
        application.c                           \
        application.h                           \
@@ -79,6 +79,11 @@ almanah_SOURCES += \
        events/calendar-task.h
 endif
 
+nodist_almanah_SOURCES = \
+       $(almanah_enum_header_file) \
+       $(almanah_enum_source_file) \
+       $(NULL)
+
 almanah_CPPFLAGS = \
        -DPACKAGE_LOCALE_DIR=\""$(datadir)/locale"\"    \
        -DPACKAGE_DATA_DIR=\""$(datadir)"\"             \
@@ -122,31 +127,36 @@ almanah-marshal.c: almanah-marshal.list almanah-marshal.h
        $(AM_V_GEN) $(GLIB_GENMARSHAL) --prefix=almanah_marshal --header --body $< > $@
 
 # Enums
-ALMANAH_ENUM_FILES = \
-       event-factory-builtins.h        \
-       event-factory-builtins.c
-
-event-factory-builtins.h: event-factory.h Makefile
-       $(AM_V_GEN)(cd $(srcdir) && $(GLIB_MKENUMS) \
-                       --fhead "#ifndef __ALMANAH_EVENT_FACTORY_BUILTINS_H__\n#define 
__ALMANAH_EVENT_FACTORY_BUILTINS_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 
ALMANAH_TYPE_@ENUMSHORT@ (@enum_name@_get_type())\n" \
-                       --ftail "G_END_DECLS\n\n#endif /* __ALMANAH_EVENT_FACTORY_BUILTINS_H__ */" \
-               event-factory.h) > $(@F)
-
-event-factory-builtins.c: event-factory.h Makefile event-factory-builtins.h
-       $(AM_V_GEN)(cd $(srcdir) && $(GLIB_MKENUMS) \
-                       --fhead "#include \"event-factory.h\"\n#include \"event-factory-builtins.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" \
-               event-factory.h) > $(@F)
-
-CLEANFILES = \
-       $(ALMANAH_MARSHAL_FILES)        \
-       $(ALMANAH_ENUM_FILES)
-
-EXTRA_DIST = almanah-marshal.list
+almanah_enum_header_file = enums.h
+almanah_enum_source_file = enums.c
+almanah_enum_prerequisites = event-factory.h
+
+$(almanah_enum_header_file): $(almanah_enum_header_file:%=%.template) $(almanah_enum_prerequisites)
+       $(AM_V_GEN)$(GLIB_MKENUMS) --template $< \
+               $(patsubst %,$(srcdir)/%,$(almanah_enum_prerequisites)) \
+               > $@.tmp && mv $@.tmp $@
+
+$(almanah_enum_source_file): $(almanah_enum_source_file:%=%.template) $(almanah_enum_prerequisites)
+       $(AM_V_GEN)$(GLIB_MKENUMS) --template $< \
+               $(patsubst %,$(srcdir)/%,$(almanah_enum_prerequisites)) \
+               > $@.tmp && mv $@.tmp $@
+
+EXTRA_DIST += \
+       $(almanah_enum_header_file:%=%.template) \
+       $(almanah_enum_source_file:%=%.template) \
+       $(NULL)
+BUILT_SOURCES += \
+       $(almanah_enum_header_file) \
+       $(almanah_enum_source_file) \
+       $(NULL)
+CLEANFILES += \
+       $(almanah_enum_header_file) \
+       $(almanah_enum_source_file) \
+       $(NULL)
+
+CLEANFILES += \
+       $(ALMANAH_MARSHAL_FILES)
+
+EXTRA_DIST += almanah-marshal.list
 
 -include $(top_srcdir)/git.mk
diff --git a/src/enums.c.template b/src/enums.c.template
new file mode 100644
index 0000000..2c28513
--- /dev/null
+++ b/src/enums.c.template
@@ -0,0 +1,56 @@
+/*** BEGIN file-header ***/
+/* vim:set et sw=2 cin cino=t0,f0,(0,{s,>2s,n-s,^-s,e2s: */
+/*
+ * Almanah
+ * Copyright © Philip Withnall 2016 <philip tecnocode co uk>
+ *
+ * Almanah 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 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Almanah 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 Almanah.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "event-factory.h"
+#include "enums.h"
+
+/*** END file-header ***/
+
+/*** BEGIN file-production ***/
+/* enumerations from "@filename@" */
+/*** END file-production ***/
+
+/*** BEGIN value-header ***/
+GType
+@enum_name@_get_type (void)
+{
+  static volatile gsize g_define_type_id__volatile = 0;
+
+  if (g_once_init_enter (&g_define_type_id__volatile))
+    {
+      static const G@Type@Value values[] = {
+/*** END value-header ***/
+
+/*** BEGIN value-production ***/
+        { @VALUENAME@, "@VALUENAME@", "@valuenick@" },
+/*** END value-production ***/
+
+/*** BEGIN value-tail ***/
+        { 0, NULL, NULL }
+      };
+      GType g_define_type_id =
+        g_@type@_register_static (g_intern_static_string ("@EnumName@"), values);
+      g_once_init_leave (&g_define_type_id__volatile, g_define_type_id);
+    }
+
+  return g_define_type_id__volatile;
+}
+
+/*** END value-tail ***/
diff --git a/src/enums.h.template b/src/enums.h.template
new file mode 100644
index 0000000..322da90
--- /dev/null
+++ b/src/enums.h.template
@@ -0,0 +1,43 @@
+/*** BEGIN file-header ***/
+/* vim:set et sw=2 cin cino=t0,f0,(0,{s,>2s,n-s,^-s,e2s: */
+/*
+ * Almanah
+ * Copyright © Philip Withnall 2016 <philip tecnocode co uk>
+ *
+ * Almanah 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 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Almanah 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 Almanah.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef ALMANAH_ENUMS_H
+#define ALMANAH_ENUMS_H
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+/*** END file-header ***/
+
+/*** BEGIN file-production ***/
+
+/* enumerations from "@filename@" */
+/*** END file-production ***/
+
+/*** BEGIN value-header ***/
+GType @enum_name@_get_type (void) G_GNUC_CONST;
+#define @ENUMPREFIX@_TYPE_@ENUMSHORT@ (@enum_name@_get_type ())
+/*** END value-header ***/
+
+/*** BEGIN file-tail ***/
+G_END_DECLS
+
+#endif
+/*** END file-tail ***/
diff --git a/src/event-factory.c b/src/event-factory.c
index fcf02d1..44a55e4 100644
--- a/src/event-factory.c
+++ b/src/event-factory.c
@@ -20,7 +20,7 @@
 #include <glib.h>
 
 #include "event-factory.h"
-#include "event-factory-builtins.h"
+#include "enums.h"
 
 static void almanah_event_factory_get_property (GObject *object, guint property_id, GValue *value, 
GParamSpec *pspec);
 
diff --git a/src/event-manager.c b/src/event-manager.c
index ba0044a..9f5334c 100644
--- a/src/event-manager.c
+++ b/src/event-manager.c
@@ -21,7 +21,7 @@
 
 #include "event-manager.h"
 #include "event-factory.h"
-#include "event-factory-builtins.h"
+#include "enums.h"
 
 typedef struct {
        AlmanahEventFactoryType type_id;


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