[glib/wip/makefile.glib: 2/2] Add Makefile.glib and GLIB_CONFIG configure macro



commit 78bb904308d80a6c4387e61712802ee1575350e8
Author: Dan Winship <danw gnome org>
Date:   Fri May 27 14:11:22 2011 -0400

    Add Makefile.glib and GLIB_CONFIG configure macro
    
    Add a Makefile fragment containing rules to generate marshallers,
    enums files, etc, so that people don't have to copy and paste the
    complicated rules into every project's Makefile.am
    
    https://bugzilla.gnome.org/show_bug.cgi?id=654395

 .gitignore                     |    1 +
 Makefile.am                    |    3 +
 Makefile.glib                  |  416 ++++++++++++++++++++++++++++++++++++++++
 configure.ac                   |   12 ++
 gio/Makefile.am                |   31 ++--
 gio/gioenumtypes.c.template    |   38 ----
 gio/gioenumtypes.h.template    |   24 ---
 gio/tests/Makefile.am          |   36 ++---
 glib-2.0.pc.in                 |    1 +
 m4macros/glib-2.0.m4           |   38 ++++
 tests/gobject/Makefile.am      |   42 +----
 tests/gobject/testmarshal.list |    4 -
 12 files changed, 502 insertions(+), 144 deletions(-)
---
diff --git a/.gitignore b/.gitignore
index 7243e1f..06b3d98 100644
--- a/.gitignore
+++ b/.gitignore
@@ -19,6 +19,7 @@ TAGS
 *.exe
 *.def
 *.test
+*.stamp
 
 # autofoo stuff here
 compile
diff --git a/Makefile.am b/Makefile.am
index b2555ad..63c9942 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -102,6 +102,9 @@ endif
 
 $(pkgconfig_DATA): config.status
 
+makedir = $(datadir)/glib-2.0
+dist_make_DATA = Makefile.glib
+
 # build documentation when doing distcheck
 DISTCHECK_CONFIGURE_FLAGS = --enable-debug --enable-gtk-doc --enable-man --disable-maintainer-mode
 
diff --git a/Makefile.glib b/Makefile.glib
new file mode 100644
index 0000000..4e67d82
--- /dev/null
+++ b/Makefile.glib
@@ -0,0 +1,416 @@
+# -*- Mode: makefile -*-
+#
+# To use:
+#
+# In configure.ac:
+#   add -Wno-portability to AM_INIT_AUTOMAKE
+#   add GLIB_CONFIG([modules, [min-version[, max-version]]])
+#   (remove AM_PATH_GLIB_2_0 and GLIB_GSETTINGS)
+#
+#   Note that if you specify min-version then it will add
+#   -DGLIB_VERSION_MIN_REQUIRED=GLIB_VERSION_X_Y to GLIB_CFLAGS, to
+#   get appropriate deprecation warnings. Likewise with max-version
+#   and GLIB_VERSION_MAX_ALLOWED.
+#
+# Add *.stamp to .gitignore
+#
+# Add to Makefile.am where your library/program is built:
+#   include $(GLIB_MAKEFILE)
+#
+#   BUILT_SOURCES = $(GLIB_GENERATED)
+#
+# Add a GLIB_GENERATED variable with the files you want to generate,
+# as described below. (The examples below use filenames with hyphens,
+# eg foo-marshal.h, but you can omit the hyphens if that matches your
+# file naming scheme better.)
+#
+# You do not need to modify CLEANFILES or EXTRA_DIST for any of these
+# macros.
+
+
+# glib-genmarshal
+#
+# 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
+#
+# Makefile.glib 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
+# _SOURCES variable, even if that variable contains foo-marshal.c.
+#
+# You can set GLIB_GENMARSHAL_H_FLAGS and GLIB_GENMARSHAL_C_FLAGS (or
+# an appropriate file-specific variable, eg
+# foo_marshal_GENMARSHAL_H_FLAGS) to set/override glib-genmarshal
+# options.
+
+
+# glib-mkenums
+#
+# To generate enum type registrations, add files with names ending
+# in "-enum-types.[ch]" or "enumtypes.[ch]" to GLIB_GENERATED:
+#
+#    GLIB_GENERATED += foo-enum-types.h foo-enum-types.c
+#    foo_enum_types_sources = aaa.h bbb.h ccc.h ddd.h
+#
+# Makefile.glib 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.
+#
+# 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
+# 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.)
+
+
+# glib-compile-schemas
+#
+# 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
+#
+# All enums files will be built before any schema files are validated.
+
+
+# glib-compile-resources
+#
+# To compile resources, add files with names ending in
+# "resources.h" and "resources.c" to GLIB_GENERATED:
+#
+#    GLIB_GENERATED += foo-resources.h foo-resources.c
+#
+# Makefile.glib will then compile "foo.gresource.xml" into the named
+# files, creating a method foo_get_resource(). Makefile.glib will
+# figure out the resource's dependencies automatically, and add those
+# files to EXTRA_DIST.
+#
+# If you specify both a .c and a .h file, Makefile.glib will compile
+# the resource with the --manual-register flag. If you specify only a
+# .c file, it will not.
+#
+# Alternatively, you can build a standalone resource file by doing:
+#
+#    GLIB_GENERATED += foo.gresource
+#
+# You can set GLIB_COMPILE_RESOURCES_FLAGS (or an appropriate
+# file-specific variable, eg foo_resources_COMPILE_RESOURCES_FLAGS or
+# foo_gresource_COMPILE_RESOURCES_FLAGS) to set/override
+# glib-compile-resources options.
+
+
+########
+
+# Notes on Makefile.glib hacking:
+#
+#   - The exact rules that automake outputs to Makefile.in vary
+#     depending on what sorts of things were done in the Makefile.am,
+#     so we have to be careful with what we assume here. In
+#     particular: (a) the glue to handle BUILT_SOURCES won't be output
+#     unless BUILT_SOURCES gets set in the Makefile.am (which is why
+#     we can't just set "BUILT_SOURCES = $(GLIB_GENERATED)"
+#     ourselves); (b) likewise for CLEANFILES / DISTCLEANFILES, which
+#     is why we hook into clean-am/distclean-am directly; (c) the glue
+#     for the various -hook rules won't be output unless those rules
+#     are defined in the Makefile.am, so we can't make use of any of
+#     them; and (c) a Makefile.am with SUBDIRS will get different
+#     rules than one without.
+#
+#     One exception is EXTRA_DIST, which is always used, even if it
+#     isn't set in Makefile.am. And since automake appears to
+#     automatically move the "include $(GLIB_MAKEFILE)" to the end of
+#     Makefile.in regardless of where it appeared in Makefile.am, this
+#     means we can just use "EXTRA_DIST += ...", and it will do the
+#     right thing.
+#
+#   - Any file that gets put into a SOURCES variable will get disted,
+#     so source files we generate should be put into
+#     _GLIB_DISTCLEANFILES, not _GLIB_CLEANFILES. Intermediate files
+#     go into _GLIB_CLEANFILES.
+#
+#   - When writing macros, remember that single-$ variables will be
+#     expanded when the macro is called, and double-$ variables will
+#     be expanded when the rule is invoked.
+#
+#   - To make srcdir!=builddir builds work, build rules should always
+#     refer to their dependencies via $^ or $< (which, as above, will
+#     usually be written as "$$^" or "$$<"), not by reusing a variable
+#     that is listed in the rule's dependencies. ($^ and $< will have
+#     the correct path prepended to each element automatically). You
+#     can use $$(filter)/$$(filter-out) if $^ has things you don't
+#     want in it.
+#
+#   - When using a filename as something other than a filename (eg, to
+#     generate a symbol name), consider whether you need to wrap it in
+#     $$(notdir) to get the right result when that file is being pulled
+#     out of a subdirectory.
+#
+#   - All private variables should be prefixed with _glib or _GLIB
+#
+#   - If things aren't working, "make -qp > makefile.out" will give
+#     you a copy of the Makefile after all macros are expanded.
+#
+# The genmarshal code is commented; the other sections are generally
+# similar.
+
+_GLIB_CLEANFILES =
+_GLIB_DISTCLEANFILES =
+
+_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-genmarshal
+
+# _GLIB_MARSHAL_GENERATED contains the basenames (eg, "foo-marshal")
+# of all the marshal-related files to be generated.
+_GLIB_MARSHAL_GENERATED = $(subst .h,,$(filter %marshal.h,$(GLIB_GENERATED)))
+
+# These are used as macros (with the value of $(1) inherited from the "caller")
+#   _glib_marshal_prefix("foo-marshal") = "foo" (used in the C marshal names)
+#   _glib_marshal_sources_var("foo-marshal") = "foo_marshal_sources"
+#   _glib_marshal_sources = the filtered value of $(foo_marshal_sources)
+_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))))
+
+# This is a multi-line macro (ending with the "endef" below) that
+# outputs a set of rules for a single .h/.c pair (whose basename is
+# $(1)). We have to include "Makefile" in the dependencies so that the
+# outputs get regenerated when you remove files from
+# $(_glib_marshal_sources) as well. (This is especially important for
+# foo-enum-types.h, which might otherwise try to #include files that
+# no longer exist.). The $$(if ... $$(error)) makes make error out
+# when making foo-marshal.list if foo_marshal_sources wasn't set.
+define _glib_make_genmarshal_rules
+$(1).list.stamp: $(_glib_marshal_sources) Makefile
+       $$(if $(_glib_marshal_sources),,$$(error Need to define $(_glib_marshal_sources_var) for $(1).[ch])) \
+       $$(_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 && \
+       echo timestamp > $$@
+
+$(1).list: $(1).list.stamp
+       @true
+
+$(1).h: $(1).list
+       $$(_GLIB_V_GEN) $$(GLIB_GENMARSHAL) \
+               --prefix=_$(_glib_marshal_prefix) --header \
+               $$(GLIB_GENMARSHAL_H_FLAGS) \
+               $$($(_glib_marshal_prefix)_GENMARSHAL_H_FLAGS) \
+               $$< > $$  tmp && \
+       mv $$  tmp $$@
+
+$(1).c: $(1).list
+       $$(_GLIB_V_GEN) (echo "#include \"$$(subst .c,.h,$$(@F))\""; $$(GLIB_GENMARSHAL) \
+               --prefix=_$(_glib_marshal_prefix) --body \
+               $$(GLIB_GENMARSHAL_C_FLAGS) \
+               $$($(_glib_marshal_prefix)_GENMARSHAL_C_FLAGS) \
+               $$< ) > $$  tmp && \
+       mv $$  tmp $$@
+
+_GLIB_CLEANFILES += $(1).list.stamp $(1).list
+_GLIB_DISTCLEANFILES += $(1).h $(1).c
+endef
+
+# Run _glib_make_genmarshal_rules for each set of generated files
+$(foreach f,$(_GLIB_MARSHAL_GENERATED),$(eval $(call _glib_make_genmarshal_rules,$f)))
+
+
+### glib-mkenums
+
+_GLIB_ENUM_TYPES_GENERATED = $(subst .h,,$(filter %enum-types.h %enumtypes.h,$(GLIB_GENERATED)))
+
+_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_h_sources = $(filter %.h,$(_glib_enum_types_sources))
+
+define _glib_make_mkenums_rules
+$(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" \
+               $$(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" \
+               --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) && \
+       rm -f $(1).h.tmp && \
+       echo timestamp > $$@
+
+$(1).h: $(1).h.stamp
+       @true
+
+$(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" \
+               $$(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" \
+               --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" \
+               $$(filter-out Makefile, $$^) > $(1).c.tmp && \
+       (cmp -s $(1).c.tmp $(1).c || cp $(1).c.tmp $(1).c) && \
+       rm -f $(1).c.tmp && \
+       echo timestamp > $$@
+
+$(1).c: $(1).c.stamp
+       @true
+
+_GLIB_CLEANFILES += $(1).h.stamp $(1).c.stamp
+_GLIB_DISTCLEANFILES += $(1).h $(1).c $(1).h.stamp $(1).c.stamp
+endef
+
+$(foreach f,$(_GLIB_ENUM_TYPES_GENERATED),$(eval $(call _glib_make_mkenums_rules,$f)))
+
+
+### glib-compile-schemas
+
+_GLIB_ENUMS_XML_GENERATED = $(filter %.enums.xml,$(GLIB_GENERATED))
+_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_namespace = $(subst .enums.xml,,$(notdir $(1)))
+
+define _glib_make_enums_xml_rule
+$(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 $$@
+endef
+
+_GLIB_V_CHECK = $(_glib_v_check_$(V))
+_glib_v_check_ = $(_glib_v_check_$(AM_DEFAULT_VERBOSITY))
+_glib_v_check_0 = @echo "  CHECK   " $(subst .valid,.xml,$@);
+
+define _glib_make_schema_validate_rule
+$(subst .xml,.valid,$(1)): $(_GLIB_ENUMS_XML_GENERATED) $(1)
+       $$(_GLIB_V_CHECK) $$(GLIB_COMPILE_SCHEMAS) --strict --dry-run $$(addprefix --schema-file=,$$^) && 
touch $$@
+endef
+
+define _glib_make_schema_rules
+all-am: $(_GLIB_GSETTINGS_VALID_FILES)
+
+install-data-am: glib-install-schemas-hook
+
+glib-install-schemas-hook: install-gsettingsschemaDATA
+       @test -n "$(GSETTINGS_DISABLE_SCHEMAS_COMPILE)$(DESTDIR)" || (echo $(GLIB_COMPILE_SCHEMAS) 
$(gsettingsschemadir); $(GLIB_COMPILE_SCHEMAS) $(gsettingsschemadir))
+
+uninstall-am: glib-uninstall-schemas-hook
+
+glib-uninstall-schemas-hook: uninstall-gsettingsschemaDATA
+       @test -n "$(GSETTINGS_DISABLE_SCHEMAS_COMPILE)$(DESTDIR)" || (echo $(GLIB_COMPILE_SCHEMAS) 
$(gsettingsschemadir); $(GLIB_COMPILE_SCHEMAS) $(gsettingsschemadir))
+
+.PHONY: glib-install-schemas-hook glib-uninstall-schemas-hook
+endef
+
+_GLIB_CLEANFILES += $(_GLIB_ENUMS_XML_GENERATED) $(_GLIB_GSETTINGS_VALID_FILES)
+
+$(foreach f,$(_GLIB_ENUMS_XML_GENERATED),$(eval $(call _glib_make_enums_xml_rule,$f)))
+$(foreach f,$(_GLIB_GSETTINGS_SCHEMA_FILES),$(eval $(call _glib_make_schema_validate_rule,$f)))
+$(if $(_GLIB_GSETTINGS_SCHEMA_FILES),$(eval $(_glib_make_schema_rules)))
+
+
+### glib-compile-resources
+
+_GLIB_RESOURCES_CH_GENERATED = $(subst .h,,$(filter %resources.h,$(GLIB_GENERATED)))
+_GLIB_RESOURCES_C_GENERATED = $(filter-out $(_GLIB_RESOURCES_CH_GENERATED),$(subst .c,,$(filter 
%resources.c,$(GLIB_GENERATED))))
+
+_glib_resources_c_prefix = $(subst resources,,$(subst _resources,,$(subst -,_,$(notdir $(1)))))
+_glib_resources_c_xml = $(subst resources,,$(subst -resources,,$(1))).gresource.xml
+_glib_resources_c_sources = $(shell $(GLIB_COMPILE_RESOURCES) --sourcedir=$(srcdir) --generate-dependencies 
$(_glib_resources_c_xml))
+
+define _glib_make_h_resources_rules
+$(1).h: $(_glib_resources_c_xml) $(_glib_resources_c_sources)
+       $$(_GLIB_V_GEN) $$(GLIB_COMPILE_RESOURCES) \
+               --target=$$@ --sourcedir="$(srcdir)" \
+               --generate-header $(2) \
+               --c-name $(_glib_resources_c_prefix) \
+               $$(GLIB_COMPILE_RESOURCES_FLAGS) \
+               $$($(_glib_resources_c_prefix)_resources_COMPILE_RESOURCES_FLAGS) \
+               $$<
+
+_GLIB_DISTCLEANFILES += $(1).h
+endef
+
+define _glib_make_c_resources_rules
+$(1).c: $(_glib_resources_c_xml) $(_glib_resources_c_sources)
+       $$(_GLIB_V_GEN) $$(GLIB_COMPILE_RESOURCES) \
+               --target=$$@ --sourcedir="$(srcdir)" \
+               --generate-source $(2) \
+               --c-name $(_glib_resources_c_prefix) \
+               $$(GLIB_COMPILE_RESOURCES_FLAGS) \
+               $$($(_glib_resources_c_prefix)_resources_COMPILE_RESOURCES_FLAGS) \
+               $$<
+
+_GLIB_DISTCLEANFILES += $(1).c
+EXTRA_DIST += $(_glib_resources_c_xml) $(_glib_resources_c_sources)
+endef
+
+$(foreach f,$(_GLIB_RESOURCES_CH_GENERATED),$(eval $(call 
_glib_make_h_resources_rules,$f,--manual-register)))
+$(foreach f,$(_GLIB_RESOURCES_CH_GENERATED),$(eval $(call 
_glib_make_c_resources_rules,$f,--manual-register)))
+$(foreach f,$(_GLIB_RESOURCES_C_GENERATED),$(eval $(call _glib_make_c_resources_rules,$f,)))
+
+_GLIB_RESOURCES_STANDALONE_GENERATED = $(subst .gresource,,$(filter %.gresource,$(GLIB_GENERATED)))
+
+_glib_resources_standalone_prefix = $(subst -,_,$(notdir $(1)))
+_glib_resources_standalone_xml = $(1).gresource.xml
+_glib_resources_standalone_sources = $(shell $(GLIB_COMPILE_RESOURCES) --sourcedir=$(srcdir) 
--generate-dependencies $(_glib_resources_standalone_xml))
+
+define _glib_make_standalone_resources_rules
+$(1).gresource: $(_glib_resources_standalone_xml) $(_glib_resources_standalone_sources)
+       $$(_GLIB_V_GEN) $$(GLIB_COMPILE_RESOURCES) \
+               --target=$$@ --sourcedir="$(srcdir)" \
+               $$(GLIB_COMPILE_RESOURCES_FLAGS) \
+               $$($(_glib_resources_standalone_prefix)_COMPILE_RESOURCES_FLAGS) \
+               $$<
+
+_GLIB_CLEANFILES += $(1).gresource
+EXTRA_DIST += $(_glib_resources_standalone_xml) $(_glib_resources_standalone_sources)
+endef
+
+$(foreach f,$(_GLIB_RESOURCES_STANDALONE_GENERATED),$(eval $(call _glib_make_standalone_resources_rules,$f)))
+
+
+### Cleanup
+.PHONY: clean-glib distclean-glib
+
+clean-am: clean-glib
+clean-glib:
+       $(if $(strip $(_GLIB_CLEANFILES)),-rm -f $(_GLIB_CLEANFILES))
+
+distclean-am: distclean-glib
+distclean-glib:
+       $(if $(strip $(_GLIB_DISTCLEANFILES)),-rm -f $(_GLIB_DISTCLEANFILES))
diff --git a/configure.ac b/configure.ac
index 47a7d16..0412272 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2725,8 +2725,20 @@ AS_IF([ test $cross_compiling = yes && test x$enable_modular_tests = xyes], [
   if test x$GLIB_COMPILE_RESOURCES = xno; then
     AC_MSG_ERROR(Could not find a glib-compile-resources in your PATH)
   fi
+],[
+  GLIB_GENMARSHAL='$(top_builddir)/gobject/glib-genmarshal'
+  GLIB_COMPILE_SCHEMAS='$(top_builddir)/gio/glib-compile-schemas'
+  GLIB_COMPILE_RESOURCES='$(top_builddir)/gio/glib-compile-resources'
 ])
 
+dnl ************************************
+dnl *** Internal GLIB_MAKEFILE usage ***
+dnl ************************************
+GLIB_MAKEFILE='$(top_srcdir)/Makefile.glib'
+AC_SUBST(GLIB_MAKEFILE)
+GLIB_MKENUMS='$(top_builddir)/gobject/glib-mkenums'
+AC_SUBST(GLIB_MKENUMS)
+
 dnl **************************
 dnl *** Checks for gtk-doc ***
 dnl **************************
diff --git a/gio/Makefile.am b/gio/Makefile.am
index ff66263..4b3a5bf 100644
--- a/gio/Makefile.am
+++ b/gio/Makefile.am
@@ -1,5 +1,7 @@
 include $(top_srcdir)/Makefile.decl
 
+include $(GLIB_MAKEFILE)
+
 NULL =
 
 SUBDIRS = gdbus-2.0/codegen
@@ -34,6 +36,8 @@ AM_CFLAGS = $(GLIB_WARN_CFLAGS)
 
 lib_LTLIBRARIES = libgio-2.0.la
 
+gioenumtypes_sources = $(gioinclude_HEADERS)
+
 gdbus_headers =                        \
        gdbusauthobserver.h             \
        gcredentials.h                  \
@@ -514,7 +518,8 @@ libgio_2_0_la_DEPENDENCIES = $(gio_win32_res) $(gio_def) $(platform_deps)
 gio-win32-res.o: gio.rc
        $(WINDRES) gio.rc $@
 
-gio_headers =                  \
+gioincludedir=$(includedir)/glib-2.0/gio/
+gioinclude_HEADERS =           \
        gappinfo.h              \
        gasyncinitable.h        \
        gasyncresult.h          \
@@ -553,6 +558,7 @@ gio_headers =                       \
        gio.h                   \
        giotypes.h              \
        gioenums.h              \
+       gioenumtypes.h          \
        gioerror.h              \
        giomodule.h             \
        gioscheduler.h          \
@@ -616,25 +622,22 @@ gio_headers =                     \
        $(gdbus_headers)        \
        $(NULL)
 
-gioincludedir=$(includedir)/glib-2.0/gio/
-gioinclude_HEADERS =           \
-       $(gio_headers)          \
-       gioenumtypes.h
-
 # these sources (also mentioned above) are generated.
+GLIB_GENERATED =       \
+       gioenumtypes.h  \
+       gioenumtypes.c
+GLIB_MKENUMS_H_FLAGS = --vhead "GLIB_AVAILABLE_IN_ALL\n"
+
 BUILT_SOURCES =                \
        gconstructor_as_data.h  \
-       gioenumtypes.h          \
-       gioenumtypes.c          \
        gdbus-daemon-generated.c \
        gdbus-daemon-generated.h \
        gnetworking.h           \
+       $(GLIB_GENERATED)       \
        $(NULL)
 
 EXTRA_DIST +=                  \
        data-to-c.pl            \
-       gioenumtypes.h.template \
-       gioenumtypes.c.template \
        makefile.msc            \
        gio.rc.in               \
        gschema.dtd             \
@@ -658,14 +661,6 @@ DISTCLEANFILES =           \
 
 all-local: gio-public-headers.txt
 
-gioenumtypes.h: $(gio_headers) gioenumtypes.h.template
-       $(AM_V_GEN) $(top_builddir)/gobject/glib-mkenums --template $(filter %.template,$^) $(filter-out 
%.template,$^) > \
-           gioenumtypes.h.tmp && mv gioenumtypes.h.tmp gioenumtypes.h
-
-gioenumtypes.c: $(gio_headers) gioenumtypes.c.template
-       $(AM_V_GEN) $(top_builddir)/gobject/glib-mkenums --template $(filter %.template,$^) $(filter-out 
%.template,$^) > \
-           gioenumtypes.c.tmp && mv gioenumtypes.c.tmp gioenumtypes.c
-
 gio-2.0.lib: libgio-2.0.la gio.def
        lib -machine:@LIB_EXE_MACHINE_FLAG@ -name:libgio-2.0-$(LT_CURRENT_MINUS_AGE).dll 
-def:$(builddir)/gio.def -out:$@
 
diff --git a/gio/tests/Makefile.am b/gio/tests/Makefile.am
index 8b15dba..8c8df2d 100644
--- a/gio/tests/Makefile.am
+++ b/gio/tests/Makefile.am
@@ -1,6 +1,7 @@
+include $(GLIB_MAKEFILE)
 
 NULL =
-BUILT_SOURCES =
+BUILT_SOURCES = $(GLIB_GENERATED)
 
 include $(top_srcdir)/Makefile.decl
 
@@ -452,25 +453,16 @@ test.mo: de.po
        $(MKDIR_P) de/LC_MESSAGES; \
        cp -f test.mo de/LC_MESSAGES
 
-if CROSS_COMPILING
-  glib_compile_resources=$(GLIB_COMPILE_RESOURCES)
-else
-  glib_compile_resources=$(top_builddir)/gio/glib-compile-resources
-endif
-
-BUILT_SOURCES += test2-resources.c test3-resources.c test3-resources.h
-
-test2-resources.c: test2.gresource.xml Makefile $(shell $(glib_compile_resources) --sourcedir=$(srcdir) 
--generate-dependencies $(srcdir)/test2.gresource.xml)
-       $(AM_V_GEN) $(glib_compile_resources) --target=$@ --sourcedir=$(srcdir) --generate-source --c-name 
_g_test2 $<
-
-test3-resources.h test3-resources.c: test3.gresource.xml Makefile $(shell $(glib_compile_resources) 
--sourcedir=$(srcdir) --generate-dependencies $(srcdir)/test3.gresource.xml)
-       $(AM_V_GEN) $(glib_compile_resources) --target=$@ --sourcedir=$(srcdir) --generate --c-name _g_test3 
--manual-register $<
-
-plugin-resources.c: test4.gresource.xml Makefile $(shell $(glib_compile_resources) --sourcedir=$(srcdir) 
--generate-dependencies $(srcdir)/test4.gresource.xml)
-       $(AM_V_GEN) $(glib_compile_resources) --target=$@ --sourcedir=$(srcdir) --generate-source --c-name 
_g_plugin $<
+GLIB_GENERATED =                       \
+       test.gresource                  \
+       test2-resources.c               \
+       test3-resources.c               \
+       test3-resources.h               \
+       test4-resources.c
 
-test.gresource: test.gresource.xml Makefile $(shell $(glib_compile_resources) --sourcedir=$(srcdir) 
--generate-dependencies $(srcdir)/test.gresource.xml)
-       $(AM_V_GEN) $(glib_compile_resources) --target=$@ --sourcedir=$(srcdir) $<
+test2_resources_COMPILE_RESOURCES_FLAGS = --c-name _g_test2
+test3_resources_COMPILE_RESOURCES_FLAGS = --c-name _g_test3
+test4_resources_COMPILE_RESOURCES_FLAGS = --c-name _g_plugin
 
 if BUILDOPT_INSTALL_TESTS
 insttest_LTLIBRARIES = libresourceplugin.la
@@ -478,19 +470,17 @@ else
 noinst_LTLIBRARIES = libresourceplugin.la
 endif
 
-libresourceplugin_la_SOURCES = resourceplugin.c plugin-resources.c
+libresourceplugin_la_SOURCES = resourceplugin.c test4-resources.c
 libresourceplugin_la_LDFLAGS = -avoid-version -module $(no_undefined) -rpath $(insttestdir)
 libresourceplugin_la_LIBADD = $(LDADD)
 
-CLEANFILES = gdbus-test-codegen-generated.[ch] gdbus-test-codegen-generated-doc-*.xml test3-resources.[ch] 
plugin-resources.c
+CLEANFILES = gdbus-test-codegen-generated.[ch] gdbus-test-codegen-generated-doc-*.xml
 
 DISTCLEANFILES = \
        applications/mimeinfo.cache     \
        org.gtk.test.enums.xml          \
        de/LC_MESSAGES/test.mo          \
        test.mo                         \
-       test.gresource                  \
-       test2-resources.c               \
        gsettings.store                 \
        gschemas.compiled               \
        schema-source/gschemas.compiled
diff --git a/glib-2.0.pc.in b/glib-2.0.pc.in
index 4a8898e..9a9ee41 100644
--- a/glib-2.0.pc.in
+++ b/glib-2.0.pc.in
@@ -6,6 +6,7 @@ includedir= includedir@
 glib_genmarshal=glib-genmarshal
 gobject_query=gobject-query
 glib_mkenums=glib-mkenums
+glib_makefile= datadir@/glib-2.0/Makefile.glib
 
 Name: GLib
 Description: C Utility Library
diff --git a/m4macros/glib-2.0.m4 b/m4macros/glib-2.0.m4
index 0507b76..d5c08a7 100644
--- a/m4macros/glib-2.0.m4
+++ b/m4macros/glib-2.0.m4
@@ -1,6 +1,44 @@
 # Configure paths for GLIB
 # Owen Taylor     1997-2001
 
+dnl GLIB_CONFIG([MODULES [, MIN-VERSION [, MAX-VERSION]]])
+dnl Test for GLIB (and error out if it's not available). Define
+dnl GLIB_CFLAGS and GLIB_LIBS, GLIB_MAKEFILE, and variables for
+dnl various glib developer tools (eg, GLIB_GENMARSHAL). If
+dnl gmodule, gobject, or gio is specified in MODULES, pass to
+dnl pkg-config. If MIN-VERSION is set, it will be passed to
+dnl pkg-config, and also used to set GLIB_VERSION_MIN_REQUIRED.
+dnl If MAX-VERSION is set, it will be used to set
+dnl GLIB_VERSION_MAX_ALLOWED.
+dnl
+AC_DEFUN([GLIB_CONFIG],
+[dnl
+  glib_config_modules="$1"
+  glib_config_min_version=ifelse([$2], ,2.35.5,$2)
+  glib_config_max_version="$3"
+
+  AM_PATH_GLIB_2_0([$glib_config_min_version], , [AC_MSG_ERROR([GLIB not found])], [$glib_config_modules])
+
+  if test -n "$glib_config_min_version"; then
+    GLIB_CFLAGS="$GLIB_CFLAGS -DGLIB_VERSION_MIN_REQUIRED=`echo $glib_config_min_version | sed -e 
's/\([[0-9]]*\)\.\([[0-9]]*\).*/GLIB_VERSION_\1_\2/'`"
+  fi
+  if test -n "$glib_config_max_version"; then
+    GLIB_CFLAGS="$GLIB_CFLAGS -DGLIB_VERSION_MAX_ALLOWED=`echo $glib_config_max_version | sed -e 
's/\([[0-9]]*\)\.\([[0-9]]*\).*/GLIB_VERSION_\1_\2/'`"
+  fi
+
+  GLIB_GENMARSHAL=`$PKG_CONFIG --variable=glib_genmarshal glib-2.0`
+  GLIB_MKENUMS=`$PKG_CONFIG --variable=glib_mkenums glib-2.0`
+  GLIB_MAKEFILE=`$PKG_CONFIG --variable=glib_makefile glib-2.0`
+  GLIB_COMPILE_RESOURCES=glib-compile-resources
+
+  AC_SUBST(GLIB_GENMARSHAL)
+  AC_SUBST(GLIB_MKENUMS)
+  AC_SUBST(GLIB_MAKEFILE)
+  AC_SUBST(GLIB_COMPILE_RESOURCES)
+
+  GLIB_GSETTINGS
+])
+
 dnl AM_PATH_GLIB_2_0([MINIMUM-VERSION, [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND [, MODULES]]]])
 dnl Test for GLIB, and define GLIB_CFLAGS and GLIB_LIBS, if gmodule, gobject,
 dnl gthread, or gio is specified in MODULES, pass to pkg-config
diff --git a/tests/gobject/Makefile.am b/tests/gobject/Makefile.am
index 7748dd1..9f67b2f 100644
--- a/tests/gobject/Makefile.am
+++ b/tests/gobject/Makefile.am
@@ -1,5 +1,7 @@
 include $(top_srcdir)/Makefile.decl
 
+include $(GLIB_MAKEFILE)
+
 AM_CPPFLAGS =                                  \
        $(gmodule_INCLUDES)                     \
        -DGLIB_DISABLE_DEPRECATION_WARNINGS     \
@@ -27,26 +29,9 @@ libtestgobject_la_SOURCES =  \
        testmodule.c            \
        testmodule.h
 
-if CROSS_COMPILING
-  glib_genmarshal=$(GLIB_GENMARSHAL)
-else
-  glib_genmarshal=$(top_builddir)/gobject/glib-genmarshal
-endif
-
-testmarshal.h: stamp-testmarshal.h
-       @true
-stamp-testmarshal.h: @REBUILD@ testmarshal.list $(glib_genmarshal)
-       $(AM_V_GEN) $(glib_genmarshal) --prefix=test_marshal $(srcdir)/testmarshal.list --header >> xgen-gmh \
-       && (cmp -s xgen-gmh testmarshal.h 2>/dev/null || cp xgen-gmh testmarshal.h) \
-       && rm -f xgen-gmh xgen-gmh~ \
-       && echo timestamp > $@
-testmarshal.c: @REBUILD@ testmarshal.h testmarshal.list $(glib_genmarshal)
-       $(AM_V_GEN) (echo "#include \"testmarshal.h\""; $(glib_genmarshal) --prefix=test_marshal 
$(srcdir)/testmarshal.list --body) >> xgen-gmc \
-       && cp xgen-gmc testmarshal.c \
-       && rm -f xgen-gmc xgen-gmc~
-
-BUILT_SOURCES = testmarshal.h testmarshal.c
-CLEANFILES = stamp-testmarshal.h
+GLIB_GENERATED = testmarshal.h testmarshal.c
+BUILT_SOURCES = $(GLIB_GENERATED)
+testmarshal_sources = $(libtestgobject_la_SOURCES)
 
 ########################################################################
 
@@ -96,20 +81,3 @@ endif
 
 EXTRA_DIST +=            \
        testmarshal.list
-
-BUILT_EXTRA_DIST =                             \
-       testmarshal.h                           \
-       testmarshal.c
-
-dist-hook: $(BUILT_EXTRA_DIST)
-       files='$(BUILT_EXTRA_DIST)';                            \
-       for f in $$files; do                                    \
-         if test -f $$f; then d=.; else d=$(srcdir); fi;       \
-         cp $$d/$$f $(distdir) || exit 1; done
-
-distclean-local:
-       if test $(srcdir) = .; then :; else     \
-           rm -f $(BUILT_EXTRA_DIST);          \
-       fi
-
-
diff --git a/tests/gobject/testmarshal.list b/tests/gobject/testmarshal.list
index 198c4f9..e69de29 100644
--- a/tests/gobject/testmarshal.list
+++ b/tests/gobject/testmarshal.list
@@ -1,4 +0,0 @@
-# Marshallers used in tests
-BOOLEAN:INT
-STRING:INT
-VARIANT:POINTER


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