diff --git a/enumtypes.c.template b/enumtypes.c.template
new file mode 100644
index 0000000..0a99121
--- /dev/null
+++ b/enumtypes.c.template
@@ -0,0 +1,37 @@
+/*** BEGIN file-header ***/
+/*** END file-header ***/
+
+/*** BEGIN file-production ***/
+/* enumerations from "@filename@" */
+#include "@filename@"
+
+/*** END file-production ***/
+
+/*** BEGIN value-header ***/
+GType
+@enum_name@_get_type (void)
+{
+	static volatile gsize the_type__volatile = 0;
+
+	if (g_once_init_enter (&the_type__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 the_type = g_@type@_register_static (
+			g_intern_static_string ("@EnumName@"),
+			values);
+		g_once_init_leave (&the_type__volatile, the_type);
+	}
+	return the_type__volatile;
+}
+
+/*** END value-tail ***/
diff --git a/enumtypes.h.template b/enumtypes.h.template
new file mode 100644
index 0000000..e1ff4b3
--- /dev/null
+++ b/enumtypes.h.template
@@ -0,0 +1,24 @@
+/*** BEGIN file-header ***/
+/*** END file-header ***/
+
+/*** BEGIN file-production ***/
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+/* Enumerations from "@filename@" */
+
+/*** END file-production ***/
+
+/*** BEGIN enumeration-production ***/
+#define E_TYPE_@ENUMSHORT@	(@enum_name@_get_type())
+GType @enum_name@_get_type	(void) G_GNUC_CONST;
+
+/*** END enumeration-production ***/
+
+/*** BEGIN file-tail ***/
+G_END_DECLS
+
+/*** END file-tail ***/
+
diff --git a/src/server/Makefile.am b/src/server/Makefile.am
index 3a145f2..d852ae0 100644
--- a/src/server/Makefile.am
+++ b/src/server/Makefile.am
@@ -6,11 +6,16 @@ privlib_LTLIBRARIES = libeews-1.2.la
 
 ENUM_TYPES = e-ews-enums.h
 
-e-ews-enumtypes.h: e-ews-enumtypes.h.template $(ENUM_TYPES)
-	$(AM_V_GEN) (cd $(srcdir) && $(GLIB_MKENUMS) --template e-ews-enumtypes.h.template $(ENUM_TYPES)) > $@
-
-e-ews-enumtypes.c: e-ews-enumtypes.c.template $(ENUM_TYPES)
-	$(AM_V_GEN) (cd $(srcdir) && $(GLIB_MKENUMS) --template e-ews-enumtypes.c.template $(ENUM_TYPES)) > $@
+e-ews-enumtypes.h: $(top_srcdir)/enumtypes.h.template $(ENUM_TYPES)
+	$(AM_V_GEN) (cd $(srcdir) && $(GLIB_MKENUMS) --template $(top_srcdir)/enumtypes.h.template \
+		--fhead "#ifndef E_EWS_ENUMTYPES_H\n#define E_EWS_ENUMTYPES_H\n" \
+		--ftail "#endif /* E_EWS_ENUMTYPES_H */\n" \
+		$(ENUM_TYPES)) > $@
+
+e-ews-enumtypes.c: $(top_srcdir)/enumtypes.h.template $(ENUM_TYPES)
+	$(AM_V_GEN) (cd $(srcdir) && $(GLIB_MKENUMS) --template $(top_srcdir)/enumtypes.c.template \
+		--fhead "#include \"e-ews-enumtypes.h\"" \
+		$(ENUM_TYPES)) > $@
 
 ENUM_GENERATED = \
 	e-ews-enumtypes.h \
diff --git a/src/server/e-ews-enumtypes.c.template b/src/server/e-ews-enumtypes.c.template
deleted file mode 100644
index 90dd2e7..0000000
--- a/src/server/e-ews-enumtypes.c.template
+++ /dev/null
@@ -1,38 +0,0 @@
-/*** BEGIN file-header ***/
-#include "e-ews-enumtypes.h"
-
-/*** END file-header ***/
-
-/*** BEGIN file-production ***/
-/* enumerations from "@filename@" */
-#include "@filename@"
-
-/*** END file-production ***/
-
-/*** BEGIN value-header ***/
-GType
-@enum_name@_get_type (void)
-{
-	static GType the_type = 0;
-	
-	if (the_type == 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 }
-		};
-		the_type = g_@type@_register_static (
-			g_intern_static_string ("@EnumName@"),
-			values);
-	}
-	return the_type;
-}
-
-/*** END value-tail ***/
diff --git a/src/server/e-ews-enumtypes.h.template b/src/server/e-ews-enumtypes.h.template
deleted file mode 100644
index 31b36d7..0000000
--- a/src/server/e-ews-enumtypes.h.template
+++ /dev/null
@@ -1,27 +0,0 @@
-/*** BEGIN file-header ***/
-#ifndef E_EWS_ENUMTYPES_H
-#define E_EWS_ENUMTYPES_H
-
-#include <glib-object.h>
-
-G_BEGIN_DECLS
-
-/*** END file-header ***/
-
-/*** BEGIN file-production ***/
-/* Enumerations from "@filename@" */
-
-/*** END file-production ***/
-
-/*** BEGIN enumeration-production ***/
-#define E_TYPE_@ENUMSHORT@	(@enum_name@_get_type())
-GType @enum_name@_get_type	(void) G_GNUC_CONST;
-
-/*** END enumeration-production ***/
-
-/*** BEGIN file-tail ***/
-G_END_DECLS
-
-#endif /* E_EWS_ENUMTYPES_H */
-/*** END file-tail ***/
-
