[glib/wip/danw/glib.mk: 3/3] wip
- From: Dan Winship <danw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib/wip/danw/glib.mk: 3/3] wip
- Date: Tue, 6 Aug 2013 12:57:56 +0000 (UTC)
commit fb62a231f75128485d5c3adda32fabcb8d6a14e1
Author: Dan Winship <danw gnome org>
Date: Thu Jun 27 09:39:43 2013 -0400
wip
glib.mk | 202 +++++++++++++++++++++++++++++++++++++++++---------------------
1 files changed, 133 insertions(+), 69 deletions(-)
---
diff --git a/glib.mk b/glib.mk
index 330cdea..caab213 100644
--- a/glib.mk
+++ b/glib.mk
@@ -231,75 +231,103 @@ _GLIB_V_GEN = $(_glib_v_gen_$(V))
_glib_v_gen_ = $(_glib_v_gen_$(AM_DEFAULT_VERBOSITY))
_glib_v_gen_0 = @echo " GEN " $(subst .stamp,,$@);
+# _glib_all_sources contains every file that is (directly or
+# indirectly) part of any _SOURCES variable in Makefile.am. We use
+# this to find the files we need to generate rules for. (We can't just
+# use '%' rules to build things because then the .stamp files get
+# treated as "intermediate files" by make, and then things don't
+# always get rebuilt when we need them to be.)
+#
+# ($(sort) is used here only for its side effect of removing
+# duplicates.)
+_glib_all_sources = $(sort $(foreach var,$(filter %_SOURCES,$(.VARIABLES)),$($(var))))
+
+# We can't add our generated files to BUILT_SOURCES because that would
+# create recursion with _glib_all_sources
+_glib_built_sources =
+all: $(_glib_built_sources)
+check: $(_glib_built_sources)
+install: $(_glib_built_sources)
+
# glib-mkenums support
#
-# To generate enum type registrations, add files with names ending
-# in "-enum-types.[ch]" or "enumtypes.[ch]" to GLIB_GENERATED:
+# glib.mk will automatically build/update "foo-enum-types.c" and
+# "foo-enum-types.h" (or "fooenumtypes.c" and "fooenumtypes.h") as
+# needed, if there is an appropriate $(foo_enum_types_sources) /
+# $(fooenumtypes_sources) variable indicating the source files to use.
#
-# GLIB_GENERATED += foo-enum-types.h foo-enum-types.c
-# foo_enum_types_sources = aaa.h bbb.h ccc.h ddd.h
-#
-# glib.mk will create a list all of the enum/flags types declared in
-# $(foo_enum_type_sources), and will rebuild
-# foo-enum-types.c/foo-enum-types.h whenever that list changes. (No
-# template files are required.)
-#
-# For your convenience, any .c files or $(GLIB_GENERATED) files in
-# $(foo_enum_types_sources) will be ignored. This means you can
-# usually set foo_enum_types_sources to the value of your
-# library/program's _HEADERS and/or _SOURCES variables, even if that
-# contains foo-enum-types.h.
+# For your convenience, any .c files or glib.mk-generated sources in
+# the _sources variable will be ignored. This means you can usually
+# just set it to the value of your library/program's _HEADERS and/or
+# _SOURCES variables, even if that variable contains the files being
+# generated.
#
# You can set GLIB_MKENUMS_H_FLAGS and GLIB_MKENUMS_C_FLAGS (or an
# appropriate file-specific variable, eg
-# foo_enum_types_MKENUMS_H_FLAGS) to set/override glib-mkenums
+# foo_enum_types_MKENUMS_H_FLAGS) to set/override certain glib-mkenums
# options. In particular, you can do:
#
# GLIB_MKENUMS_C_FLAGS = --fhead "\#define FOO_I_KNOW_THIS_IS_UNSTABLE"
#
# (The backslash is necessary to keep make from thinking the "#" is
# the start of a comment.)
+#
+# You are responsible for adding the generated .c and .h files to
+# either CLEANFILES, or to DISTFILES and DISTCLEANFILES, as
+# appropriate. glib.mk will ensure that the .stamp files it builds get
+# cleaned/disted along with the generated .c and .h files.
+#
+# You do not need to add the generated files to BUILT_SOURCES; glib.mk
+# will cause them to be built at the correct time (but note that it does
+# not actually add them to BUILT_SOURCES).
-# _GLIB_ENUM_TYPES_GENERATED contains the basenames (eg, "foo-enum-types")
-# of all the enum-type-related files to be generated.
-_GLIB_ENUM_TYPES_GENERATED = $(subst .h,,$(filter %enum-types.h %enumtypes.h,$(GLIB_GENERATED)))
-
-# These are used as macros (with the value of $(1) inherited from the "caller")
+# These are used as macros (with the value of $(1) possibly inherited
+# from the "caller")
# _glib_enum_types_prefix("foo-enum-types") = "foo_enum_types"
# _glib_enum_types_guard("foo-enum-types") = "__FOO_ENUM_TYPES_H__"
# _glib_enum_types_sources_var("foo-enum_types") = "foo_enum_types_sources"
-# _glib_enum_types_sources = the filtered value of $(foo_enum_types_sources_var)
-# _glib_enum_types_h_sources = the .h files in $(foo_enum_types_sources)
+# _glib_enum_types_sources = the filtered value of $(foo_enum_types_sources)
+# _glib_enum_types_h_sources = the .h files in $(_glib_enum_types_sources)
_glib_enum_types_prefix = $(subst -,_,$(notdir $(1)))
_glib_enum_types_guard = __$(shell LC_ALL=C echo $(_glib_enum_types_prefix) | tr 'a-z' 'A-Z')_H__
_glib_enum_types_sources_var = $(_glib_enum_types_prefix)_sources
-_glib_enum_types_sources = $(filter-out $(GLIB_GENERATED),$($(_glib_enum_types_sources_var)))
+_glib_enum_types_sources = $(filter-out $(_glib_built_sources),$($(_glib_enum_types_sources_var)))
_glib_enum_types_h_sources = $(filter %.h,$(_glib_enum_types_sources))
+# _glib_all_enum_types contains the basenames (eg, "fooenumtypes",
+# "bar-enum-types") of all enum-types files known to the Makefile.
+# _glib_generated_enum_types contains only the ones being generated by
+# glib.mk.
+_glib_all_enum_types = $(subst .h,,$(notdir $(filter %enum-types.h %enumtypes.h,$(_glib_all_sources))))
+_glib_generated_enum_types = $(foreach f,$(_glib_all_enum_types),$(if $(strip $(call
_glib_enum_types_sources,$f)),$f))
+
# _glib_make_mkenums_rules is a multi-line macro that outputs a set of
# rules for a single .h/.c pair (whose basename is $(1)). automake
# doesn't recognize GNU make's define/endef syntax, so if we defined
-# the macro directly, it would try to, eg, add the literal
-# "$(1).h.stamp" to CLEANFILES. So we hide the macro by prefixing each
-# line with ":::", and then use $(subst) to extract the actual rule.
+# the macro directly, it would try to, eg, add the literal "$(1).h" to
+# _glib_built_sources. So we hide the macro by prefixing each line
+# with ":::", and then use $(subst) to extract the actual rule.
# We have to include "Makefile" in the dependencies so that the
# outputs get regenerated when you remove files from
-# foo_enum_types_sources as well. (This is especially important for
+# foo_enum_types_sources. (This is especially important for
# foo-enum-types.h, which might otherwise try to #include files that
# no longer exist.).
define _glib_make_mkenums_rules_hidden
:::$(1).h.stamp: $(_glib_enum_types_h_sources) Makefile
-::: $$(if $(_glib_enum_types_sources),,$$(error Need to define $(_glib_enum_types_sources_var) for
$(1).[ch])) \
::: $$(_GLIB_V_GEN) $$(GLIB_MKENUMS) \
-::: --fhead "/* Generated by glib-mkenums. Do not edit */\n\n#ifndef
$(_glib_enum_types_guard)\n#define $(_glib_enum_types_guard)\n\n" \
+::: --fhead "/* Generated by glib-mkenums. Do not edit */\n\n" \
+::: --fhead "#ifndef $(_glib_enum_types_guard)\n" \
+::: --fehad "#define $(_glib_enum_types_guard)\n\n" \
::: $$(GLIB_MKENUMS_H_FLAGS) \
::: $$($(_glib_enum_types_prefix)_MKENUMS_H_FLAGS) \
-::: --fhead "#include <glib-object.h>\n\nG_BEGIN_DECLS\n" \
-::: --vhead "GType @enum_name _get_type (void) G_GNUC_CONST;\n#define @ENUMPREFIX
_TYPE_@ENUMSHORT@ (@enum_name _get_type ())\n" \
+::: --fhead "#include <glib-object.h>\n\n" \
+::: --fhead "G_BEGIN_DECLS\n" \
+::: --vhead "GType @enum_name _get_type (void) G_GNUC_CONST;\n" \
+::: --vhead "#define @ENUMPREFIX _TYPE_@ENUMSHORT@ (@enum_name _get_type ())\n" \
::: --ftail "G_END_DECLS\n\n#endif /* $(_glib_enum_types_guard) */" \
::: $$(filter-out Makefile, $$^) > $(1).h.tmp && \
::: (cmp -s $(1).h.tmp $(1).h || cp $(1).h.tmp $(1).h) && \
@@ -311,13 +339,30 @@ define _glib_make_mkenums_rules_hidden
:::
:::$(1).c.stamp: $(_glib_enum_types_h_sources) Makefile
::: $$(_GLIB_V_GEN) $$(GLIB_MKENUMS) \
-::: --fhead "/* Generated by glib-mkenums. Do not edit */\n\n#ifdef HAVE_CONFIG_H\n#include
\"config.h\"\n#endif\n\n#include \"$(notdir $(1)).h\"\n" \
+::: --fhead "/* Generated by glib-mkenums. Do not edit */\n\n" \
+::: --fhead "#ifdef HAVE_CONFIG_H\n" \
+::: --fhead "#include \"config.h\"\n" \
+::: --fhead "#endif\n\n" \
+::: --fhead "#include \"$(notdir $(1)).h\"\n" \
::: $$(GLIB_MKENUMS_C_FLAGS) \
::: $$($(_glib_enum_types_prefix)_MKENUMS_C_FLAGS) \
::: --fhead "$$(foreach f,$$(filter-out Makefile,$$(^F)),\n#include \"$$(f)\")\n\n" \
-::: --vhead "GType\n enum_name@_get_type (void)\n{\n static volatile gsize
g_define_type_id__volatile = 0;\n\n if (g_once_init_enter (&g_define_type_id__volatile))\n {\n
static const G Type@Value values[] = {\n" \
+::: --vhead "GType\n" \
+::: --vhead "@enum_name _get_type (void)\n" \
+::: --vhead "{\n" \
+::: --vhead " static volatile gsize g_define_type_id__volatile = 0;\n\n" \
+::: --vhead " if (g_once_init_enter (&g_define_type_id__volatile))\n" \
+::: --vhead " {\n" \
+::: --vhead " static const G Type@Value values[] = {\n" \
::: --vprod " { @VALUENAME@, \"@VALUENAME \", \"@valuenick \" },\n" \
-::: --vtail " { 0, NULL, NULL }\n };\n GType g_define_type_id =\n g_
type@_register_static (g_intern_static_string (\"@EnumName \"), values);\n g_once_init_leave
(&g_define_type_id__volatile, g_define_type_id);\n }\n\n return g_define_type_id__volatile;\n}\n" \
+::: --vtail " { 0, NULL, NULL }\n" \
+::: --vtail " };\n" \
+::: --vtail " GType g_define_type_id =\n" \
+::: --vtail " g_ type@_register_static (g_intern_static_string (\"@EnumName \"),
values);\n" \
+::: --vtail " g_once_init_leave (&g_define_type_id__volatile, g_define_type_id);\n" \
+::: --vtail " }\n\n" \
+::: --vtail " return g_define_type_id__volatile;\n" \
+::: --vtail "}\n" \
::: $$(filter-out Makefile, $$^) > $(1).c.tmp && \
::: (cmp -s $(1).c.tmp $(1).c || cp $(1).c.tmp $(1).c) && \
::: rm -f $(1).c.tmp && \
@@ -326,31 +371,43 @@ define _glib_make_mkenums_rules_hidden
:::$(1).c: $(1).c.stamp
::: @true
:::
-:::CLEANFILES += $(1).h.stamp $(1).c.stamp
-:::DISTCLEANFILES += $(1).h $(1).c $(1).h.stamp $(1).c.stamp
+:::_glib_built_sources += $(1).h $(1).c
endef
_glib_make_mkenums_rules = $(subst :::,,$(_glib_make_mkenums_rules_hidden))
# Run _glib_make_mkenums_rules for each set of generated files
-$(foreach f,$(_GLIB_ENUM_TYPES_GENERATED),$(eval $(call _glib_make_mkenums_rules,$f)))
+$(foreach f,$(_glib_generated_enum_types),$(eval $(call _glib_make_mkenums_rules,$f)))
+
+# clean/dist stamps when cleaning/disting generated files
+_glib_enumtypes_filter = $(filter %enumtypes.h %enumtypes.c %-enum-types.h %-enum-types.c,$(1))
+
+clean-am: glib-mkenums-clean
+glib-mkenums-clean:
+ @$(if $(strip $(call _glib_enumtypes_filter,$(CLEANFILES))),rm -f $(foreach f,$(call
_glib_enumtypes_filter,$(CLEANFILES)),$(f).stamp),:)
+
+distclean-am: glib-mkenums-distclean
+glib-mkenums-distclean:
+ @$(if $(strip $(call _glib_enumtypes_filter,$(DISTCLEANFILES))),rm -f $(foreach f,$(call
_glib_enumtypes_filter,$(DISTCLEANFILES)),$(f).stamp),:)
+
+dist-hook: glib-mkenums-dist-hook
+glib-mkenums-dist-hook:
+ @$(if $(strip $(call _glib_enumtypes_filter,$(DISTFILES))),cp -p $(foreach f,$(call
_glib_enumtypes_filter,$(DISTFILES)),$(f).stamp) $(distdir)/,:)
+
# glib-genmarshal support
#
-# To generate signal marshallers, add files with names ending in
-# "marshal.h" and "marshal.c" to GLIB_GENERATED:
-#
-# GLIB_GENERATED += foo-marshal.h foo-marshal.c
-# foo_marshal_sources = aaa.c bbb.c ccc.c ddd.c
-#
-# glib.mk will then generate a foo-marshal.list file containing
-# all _foo_marshal_* functions referenced by $(foo_marshal_sources),
-# and will rebuild foo-marshal.c/foo-marshal.h whenever the list
-# changes.
-#
-# For your convenience, any .h files or $(GLIB_GENERATED) files in
-# $(foo_marshal_sources) will be ignored. This means you can usually just
-# set foo_marshal_sources to the value of your library/program's
+# glib.mk will automatically build/update "foo-marshal.c" and
+# "foo-marshal.h" (or "foomarshal.c" and "foomarshal.h") as needed, if
+# there is an appropriate $(foo_marshal_sources) /
+# $(foomarshal_sources) variable indicating the source files to use;
+# glib.mk will generate a "foo-marshal.list" file containing all
+# _foo_marshal_* functions referenced by $(foo_marshal_sources), and
+# will then rebuild the generated C files whenever the list changes.
+#
+# For your convenience, any .h files or glib.mk-generated files in
+# $(foo_marshal_sources) will be ignored. This means you can usually
+# just set foo_marshal_sources to the value of your library/program's
# _SOURCES variable, even if that variable contains foo-marshal.c.
#
# You can set GLIB_GENMARSHAL_H_FLAGS and GLIB_GENMARSHAL_C_FLAGS (or
@@ -359,15 +416,17 @@ $(foreach f,$(_GLIB_ENUM_TYPES_GENERATED),$(eval $(call _glib_make_mkenums_rules
# options.
# see the comments in the glib-mkenums section for details of how this all works
-_GLIB_MARSHAL_GENERATED = $(subst .h,,$(filter %marshal.h,$(GLIB_GENERATED)))
_glib_marshal_prefix = $(subst marshal,,$(subst _marshal,,$(subst -,_,$(notdir $(1)))))_marshal
-_glib_marshal_sources_var = $(subst -,_,$(notdir $(1)))_sources
-_glib_marshal_sources = $(filter-out %.h,$(filter-out $(GLIB_GENERATED),$($(_glib_marshal_sources_var))))
+_glib_marshal_sources_var = $(_glib_marshal_prefix)_sources
+_glib_marshal_sources = $(filter-out $(_glib_built_sources),$($(_glib_marshal_sources_var)))
+_glib_marshal_c_sources = $(filter %.c,$(_glib_marshal_sources))
+
+_glib_all_marshal = $(subst .h,,$(notdir $(filter %marshal.h,$(_glib_all_sources))))
+_glib_generated_marshal = $(foreach f,$(_glib_all_marshal),$(if $(strip $(call
_glib_marshal_sources,$f)),$f))
define _glib_make_genmarshal_rules_hidden
-:::$(1).list.stamp: $(_glib_marshal_sources) Makefile
-::: $$(if $(_glib_marshal_sources),,$$(error Need to define $(_glib_marshal_sources_var) for $(1).[ch])) \
+:::$(1).list.stamp: $(_glib_marshal_c_sources) Makefile
::: $$(_GLIB_V_GEN) LC_ALL=C sed -ne 's/.*_$(_glib_marshal_prefix)_\([_A-Z]*\).*/\1/p' $$(filter-out
Makefile, $$^) | sort -u | sed -e 's/__/:/' -e 's/_/,/g' > $(1).list.tmp && \
::: (cmp -s $(1).list.tmp $(1).list || cp $(1).list.tmp $(1).list) && \
::: rm -f $(1).list.tmp && \
@@ -397,37 +456,42 @@ define _glib_make_genmarshal_rules_hidden
endef
_glib_make_genmarshal_rules = $(subst :::,,$(_glib_make_genmarshal_rules_hidden))
-$(foreach f,$(_GLIB_MARSHAL_GENERATED),$(eval $(call _glib_make_genmarshal_rules,$f)))
+$(foreach f,$(_glib_generated_marshal),$(eval $(call _glib_make_genmarshal_rules,$f)))
# glib-compile-schemas support
#
# Any foo.gschemas.xml files listed in gsettingsschema_DATA will be
# validated before installation, and (if --disable-schemas-compile was
-# not passed) compiled after installation.
-#
-# To build an enums file, add it to GLIB_GENERATED (in addition to
-# gsettingsschema_DATA):
-#
-# GLIB_GENERATED += org.gnome.foo.enums.xml
-# org_gnome_foo_enums_xml_sources = aaa.h bbb.h ccc.h ddd.h
+# not passed to configure) compiled after installation.
#
-# All enums files will be built before any schema files are validated.
+# glib.mk will automatically build/update any "org.foo.bar.enums.xml"
+# files in gsettingsschema_DATA, if there is an appropriate
+# $(org_foo_bar_enums_xml_sources) variable indicating the source
+# files to use. All enums files will automatically be built before any
+# schema files are validated.
# see the comments in the glib-mkenums section for details of how this all works
-_GLIB_ENUMS_XML_GENERATED = $(filter %.enums.xml,$(GLIB_GENERATED))
+_GLIB_ENUMS_XML_GENERATED = $(filter %.enums.xml,$(gsettingsscheme_DATA))
_GLIB_GSETTINGS_SCHEMA_FILES = $(filter %.gschema.xml,$(gsettingsschema_DATA))
_GLIB_GSETTINGS_VALID_FILES = $(subst .xml,.valid,$(_GLIB_GSETTINGS_SCHEMA_FILES))
_glib_enums_xml_prefix = $(subst .,_,$(notdir $(1)))
_glib_enums_xml_sources_var = $(_glib_enums_xml_prefix)_sources
-_glib_enums_xml_sources = $(filter-out $(GLIB_GENERATED),$($(_glib_enums_xml_sources_var)))
+_glib_enums_xml_sources = $(filter-out $(_glib_built_sources),$($(_glib_enums_xml_sources_var)))
_glib_enums_xml_namespace = $(subst .enums.xml,,$(notdir $(1)))
define _glib_make_enums_xml_rule_hidden
:::$(1): $(_glib_enums_xml_sources) Makefile
-::: $$(if $(_glib_enums_xml_sources),,$$(error Need to define $(_glib_enums_xml_sources_var) for $(1))) \
-::: $$(_GLIB_V_GEN) $$(GLIB_MKENUMS) --comments '<!-- @comment@ -->' --fhead "<schemalist>" --vhead "
<@type@ id='$(_glib_enums_xml_namespace) EnumName@'>" --vprod " <value nick='@valuenick@'
value='@valuenum@'/>" --vtail " </@type@>" --ftail "</schemalist>" $$(filter-out Makefile, $$^) > $$ tmp &&
mv $$ tmp $$@
+::: $$(_GLIB_V_GEN) $$(GLIB_MKENUMS) \
+::: --comments '<!-- @comment@ -->' \
+::: --fhead "<schemalist>" \
+::: --vhead " <@type@ id='$(_glib_enums_xml_namespace) EnumName@'>" \
+::: --vprod " <value nick='@valuenick@' value='@valuenum@'/>" \
+::: --vtail " </@type@>" \
+::: --ftail "</schemalist>" \
+::: $$(filter-out Makefile, $$^) > $$ tmp && \
+::: mv $$ tmp $$@
endef
_glib_make_enums_xml_rule = $(subst :::,,$(_glib_make_enums_xml_rule_hidden))
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]