diff options
author | Dan Winship <danw@gnome.org> | 2011-05-27 14:11:22 -0400 |
---|---|---|
committer | Dan Winship <danw@gnome.org> | 2013-08-23 09:07:04 -0400 |
commit | 425d2f591291f18ca0916618be23b91d77c78622 (patch) | |
tree | 258c46683e871eb9d7b232fc8c75641542ba3cf0 | |
parent | 9bcb6d3f007358deb77294b828ea5d706de04aab (diff) | |
download | glib-wip/danw/glib.mk.tar.gz |
glib-build.mk: enumtypes, marshal, schemas, and resources ruleswip/danw/glib.mk
Add a new glib-build.mk with rules to generate enumtypes files,
marshallers, gsettings schemas, and resource files, so that people
don't have to copy and paste the rules into every project's
Makefile.am
https://bugzilla.gnome.org/show_bug.cgi?id=654395
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | configure.ac | 10 | ||||
-rw-r--r-- | gio/Makefile.am | 26 | ||||
-rw-r--r-- | gio/gioenumtypes.c.template | 38 | ||||
-rw-r--r-- | gio/gioenumtypes.h.template | 24 | ||||
-rw-r--r-- | gio/tests/.gitignore | 4 | ||||
-rw-r--r-- | gio/tests/Makefile.am | 23 | ||||
-rw-r--r-- | gio/tests/resources.c | 2 | ||||
-rw-r--r-- | glib-2.0.pc.in | 1 | ||||
-rw-r--r-- | glib-build.mk | 441 | ||||
-rw-r--r-- | tests/gobject/.gitignore | 1 | ||||
-rw-r--r-- | tests/gobject/Makefile.am | 41 | ||||
-rw-r--r-- | tests/gobject/accumulator.c | 6 | ||||
-rw-r--r-- | tests/gobject/testmarshal.list | 4 |
14 files changed, 483 insertions, 139 deletions
diff --git a/.gitignore b/.gitignore index f80afbce5..bd545bf47 100644 --- a/.gitignore +++ b/.gitignore @@ -21,6 +21,7 @@ TAGS *.test *.log *.trs +*.stamp # autofoo stuff here compile diff --git a/configure.ac b/configure.ac index 826204eaf..9be44e79b 100644 --- a/configure.ac +++ b/configure.ac @@ -2704,8 +2704,18 @@ AS_IF([ test $cross_compiling = yes ], [ 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-build.mk usage *** +dnl ************************************ +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 f861e8b5e..dd10f0db6 100644 --- a/gio/Makefile.am +++ b/gio/Makefile.am @@ -1,4 +1,5 @@ include $(top_srcdir)/glib.mk +include $(top_srcdir)/glib-build.mk SUBDIRS = gdbus-2.0/codegen @@ -32,6 +33,8 @@ AM_CFLAGS = $(GLIB_WARN_CFLAGS) lib_LTLIBRARIES = libgio-2.0.la +gioenumtypes_sources = $(gioinclude_HEADERS) + gdbus_headers = \ gdbusauthobserver.h \ gcredentials.h \ @@ -510,7 +513,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 \ @@ -549,6 +553,7 @@ gio_headers = \ gio.h \ giotypes.h \ gioenums.h \ + gioenumtypes.h \ gioerror.h \ giomodule.h \ gioscheduler.h \ @@ -612,25 +617,18 @@ gio_headers = \ $(gdbus_headers) \ $(NULL) -gioincludedir=$(includedir)/glib-2.0/gio/ -gioinclude_HEADERS = \ - $(gio_headers) \ - gioenumtypes.h - # these sources (also mentioned above) are generated. BUILT_SOURCES += \ gconstructor_as_data.h \ - gioenumtypes.h \ - gioenumtypes.c \ gdbus-daemon-generated.c \ gdbus-daemon-generated.h \ gnetworking.h \ $(NULL) +GLIB_MKENUMS_H_FLAGS = --vhead "GLIB_AVAILABLE_IN_ALL\n" + EXTRA_DIST += \ data-to-c.pl \ - gioenumtypes.h.template \ - gioenumtypes.c.template \ makefile.msc \ gio.rc.in \ gschema.dtd \ @@ -654,14 +652,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/gioenumtypes.c.template b/gio/gioenumtypes.c.template deleted file mode 100644 index e9adc4a38..000000000 --- a/gio/gioenumtypes.c.template +++ /dev/null @@ -1,38 +0,0 @@ -/*** BEGIN file-header ***/ -#include "config.h" -#include "gioenumtypes.h" -#include <gio.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/gio/gioenumtypes.h.template b/gio/gioenumtypes.h.template deleted file mode 100644 index 4baa6df32..000000000 --- a/gio/gioenumtypes.h.template +++ /dev/null @@ -1,24 +0,0 @@ -/*** BEGIN file-header ***/ -#ifndef __GIO_ENUM_TYPES_H__ -#define __GIO_ENUM_TYPES_H__ - -#include <glib-object.h> - -G_BEGIN_DECLS -/*** END file-header ***/ - -/*** BEGIN file-production ***/ - -/* enumerations from "@filename@" */ -/*** END file-production ***/ - -/*** BEGIN value-header ***/ -GLIB_AVAILABLE_IN_ALL 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 /* __GIO_ENUM_TYPES_H__ */ -/*** END file-tail ***/ diff --git a/gio/tests/.gitignore b/gio/tests/.gitignore index 99e883759..4b14d3496 100644 --- a/gio/tests/.gitignore +++ b/gio/tests/.gitignore @@ -110,8 +110,8 @@ task test.mo test.gresource test_resources.c -test_resources2.c -test_resources2.h +test2_resources.c +test2_resources.h tls-certificate tls-interaction unix-fd diff --git a/gio/tests/Makefile.am b/gio/tests/Makefile.am index 1327c281e..3be846157 100644 --- a/gio/tests/Makefile.am +++ b/gio/tests/Makefile.am @@ -1,4 +1,5 @@ include $(top_srcdir)/glib-tap.mk +include $(top_srcdir)/glib-build.mk dist_uninstalled_test_data = test_ltlibraries = @@ -408,7 +409,7 @@ endif test_programs += resources resources_SOURCES = resources.c -nodist_resources_SOURCES = test_resources.c test_resources2.c test_resources2.h +nodist_resources_SOURCES = test_resources.c test2_resources.c test2_resources.h resources_DEPENDENCIES = test.gresource test_ltlibraries += libresourceplugin.la @@ -433,19 +434,17 @@ else glib_compile_resources=$(top_builddir)/gio/glib-compile-resources endif -resources.o: test_resources2.h -test_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_test1 $< +resources.o: test2_resources.h -test_resources2.h test_resources2.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_test2 --manual-register $< +test_resources_sources = test2.gresource.xml +test_resources_COMPILE_RESOURCES_FLAGS = --c-name _g_test1 -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 $< +test2_resources_sources = test3.gresource.xml +test2_resources_COMPILE_RESOURCES_FLAGS = --c-name _g_test2 -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) $< +plugin_resources_sources = test4.gresource.xml +plugin_resources_COMPILE_RESOURCES_FLAGS = --c-name _g_plugin -EXTRA_DIST += test.gresource.xml test1.txt test2.gresource.xml test2.txt test3.gresource.xml test3.txt test4.gresource.xml +test_gresource_sources = test.gresource.xml -CLEANFILES += test_resources.c test_resources2.[ch] plugin_resources.c test.gresource +CLEANFILES += test_resources.c test2_resources.[ch] plugin_resources.c test.gresource diff --git a/gio/tests/resources.c b/gio/tests/resources.c index 495c05b29..2f3050688 100644 --- a/gio/tests/resources.c +++ b/gio/tests/resources.c @@ -21,7 +21,7 @@ #include <string.h> #include <gio/gio.h> #include "gconstructor.h" -#include "test_resources2.h" +#include "test2_resources.h" static void test_resource (GResource *resource) diff --git a/glib-2.0.pc.in b/glib-2.0.pc.in index 4a8898e66..9a9ee4115 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/glib-build.mk b/glib-build.mk new file mode 100644 index 000000000..c4e1522a4 --- /dev/null +++ b/glib-build.mk @@ -0,0 +1,441 @@ +# This is like AM_V_GEN, except that it strips ".stamp" from its output +_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)))) +_glib_all_data = $(sort $(foreach var,$(filter-out INSTALL_DATA install_sh_DATA,$(filter %_DATA,$(.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-ensure-built-sources +check: glib-ensure-built-sources +install: glib-ensure-built-sources + +# We can't just add $(_glib_built_sources) as a dependency because it +# doesn't get computed early enough. +glib-ensure-built-sources: + @$(if $(strip $(_glib_built_sources)),$(MAKE) $(_glib_built_sources),:) + +# We need to hook off clean-am, distclean-am, and dist-hook, but if +# automake sees us doing this, it will fail to define its own +# clean-am and distclean-am rules, breaking everything. +define _glib_hooks_hidden +:::clean-am: clean-glib +:::distclean-am: distclean-glib +:::dist-hook: dist-glib +endef +$(eval $(subst :::,,$(_glib_hooks_hidden))) + +# glib-mkenums support +# +# 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. +# +# 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 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). + + +# 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) +# _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_built_sources) $(1).h,$($(_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" 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. (This is especially important for +# foo-enum-types.h, which might otherwise try to #include files that +# no longer exist.). + +# _glib_enum_types_h_sources has to get called when running the rule +# rather than when generating it, because it uses _glib_built_sources, +# which won't be up-to-date when the rule is initially run. + +define _glib_make_mkenums_rules_hidden +:::$(1).h.stamp: $$(call _glib_enum_types_h_sources,$(1)) Makefile +::: $$(_GLIB_V_GEN) $$(GLIB_MKENUMS) \ +::: --fhead "/* Generated by glib-mkenums. Do not edit */\n\n" \ +::: --fhead "#ifndef $(_glib_enum_types_guard)\n" \ +::: --fhead "#define $(_glib_enum_types_guard)\n\n" \ +::: $$(GLIB_MKENUMS_H_FLAGS) \ +::: $$($(_glib_enum_types_prefix)_MKENUMS_H_FLAGS) \ +::: --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\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: $$(call _glib_enum_types_h_sources,$(1)) Makefile +::: $$(_GLIB_V_GEN) $$(GLIB_MKENUMS) \ +::: --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" \ +::: --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" \ +::: --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\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_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_generated_enum_types),$(eval $(call _glib_make_mkenums_rules,$f))) + +# clean/dist stamps when cleaning/disting generated files +_glib_generated_enum_types_pattern = $(foreach f,$(_glib_generated_enum_types),$(f).c $(f).h) +_glib_enumtypes_filter = $(filter $(_glib_generated_enum_types_pattern),$(1)) + +clean-glib: 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-glib: 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-glib: glib-mkenums-dist +glib-mkenums-dist: + @$(if $(strip $(call _glib_enumtypes_filter,$(DISTFILES))),cp -p $(sort $(foreach f,$(call _glib_enumtypes_filter,$(DISTFILES)),$(f).stamp)) $(distdir)/,:) + + + +# glib-genmarshal support +# +# 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 the +# _sources variable 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 certain +# glib-genmarshal options. +# +# 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 .list and .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). + +# see the comments in the glib-mkenums section for details of how this all works + +_glib_marshal_file_prefix = $(subst -,_,$(notdir $(1))) +_glib_marshal_symbol_prefix = $(subst marshal,,$(subst _marshal,,$(subst -,_,$(notdir $(1)))))_marshal +_glib_marshal_sources_var = $(_glib_marshal_file_prefix)_sources +_glib_marshal_sources = $(filter-out $(_glib_built_sources) $(1).c,$($(_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: $$(call _glib_marshal_c_sources,$(1)) Makefile +::: $$(_GLIB_V_GEN) LC_ALL=C sed -ne 's/.*_$(_glib_marshal_symbol_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_symbol_prefix) --header \ +::: $$(GLIB_GENMARSHAL_H_FLAGS) \ +::: $$($(_glib_marshal_symbol_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_symbol_prefix) --body \ +::: $$(GLIB_GENMARSHAL_C_FLAGS) \ +::: $$($(_glib_marshal_symbol_prefix)_GENMARSHAL_C_FLAGS) \ +::: $$< ) > $$@.tmp && \ +::: mv $$@.tmp $$@ +::: +:::_glib_built_sources += $(1).h $(1).c +endef +_glib_make_genmarshal_rules = $(subst :::,,$(_glib_make_genmarshal_rules_hidden)) + +$(foreach f,$(_glib_generated_marshal),$(eval $(call _glib_make_genmarshal_rules,$f))) + +_glib_generated_marshal_pattern = $(foreach f,$(_glib_generated_marshal),$(f).h) +_glib_marshal_filter = $(filter $(_glib_generated_marshal_pattern),$(1)) + +clean-glib: glib-marshal-clean +glib-marshal-clean: + @$(if $(strip $(call _glib_marshal_filter,$(CLEANFILES))),rm -f $(sort $(foreach f,$(call _glib_marshal_filter,$(CLEANFILES)),$(f:.h=.list) $(f:.h=.list.stamp))),:) + +distclean-glib: glib-marshal-distclean +glib-marshal-distclean: + @$(if $(strip $(call _glib_marshal_filter,$(DISTCLEANFILES))),rm -f $(sort $(foreach f,$(call _glib_marshal_filter,$(DISTCLEANFILES)),$(f:.h=.list) $(f:.h=.list.stamp))),:) + +dist-glib: glib-marshal-dist +glib-marshal-dist: + @$(if $(strip $(call _glib_marshal_filter,$(DISTFILES))),cp -p $(sort $(foreach f,$(call _glib_marshal_filter,$(DISTFILES)),$(f:.h=.list) $(f:.h=.list.stamp))) $(distdir)/,:) + + +# 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 to configure) compiled after installation. +# +# 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,$(gsettingsschema_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_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 +::: $$(_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)) + +_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_hidden +:::$(subst .xml,.valid,$(1)): $(_GLIB_ENUMS_XML_GENERATED) $(1) +::: $$(_GLIB_V_CHECK) $$(GLIB_COMPILE_SCHEMAS) --strict --dry-run $$(addprefix --schema-file=,$$^) && touch $$@ +endef +_glib_make_schema_validate_rule = $(subst :::,,$(_glib_make_schema_validate_rule_hidden)) + +define _glib_make_schema_rules_hidden +:::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_make_schema_rules = $(subst :::,,$(_glib_make_schema_rules_hidden)) + +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 support +# +# glib.mk will automatically build/update "foo-resources.c" and/or +# "foo-resources.h" (or "fooresources.c" and/or "fooresources.h") as +# needed, if there is an appropriate $(foo_resources_sources) / +# $(fooresources_sources) variable indicating the source +# .gresource.xml file to use. +# +# If you specify both a .c and a .h file, glib.mk 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 "foo.gresource" file by +# specifying $(foo_gresource_sources). +# +# 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. +# +# You are responsible for adding the generated .c and .h files to +# either CLEANFILES, or to DISTFILES and DISTCLEANFILES, as +# appropriate. glib.mk will figure out the resource's dependencies +# automatically, and will ensure that those files get disted as well. +# +# 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_resources_c_file_prefix = $(subst -,_,$(notdir $(1))) +_glib_resources_c_symbol_prefix = $(subst resources,,$(subst _resources,,$(subst -,_,$(notdir $(1))))) +_glib_resources_c_sources_var = $(_glib_resources_c_file_prefix)_sources +_glib_resources_c_sources = $($(_glib_resources_c_sources_var)) +_glib_resources_c_deps = $(shell $(GLIB_COMPILE_RESOURCES) --sourcedir=$(srcdir) --generate-dependencies $(_glib_resources_c_sources)) + +_glib_all_ch_resources = $(subst .h,,$(notdir $(filter %resources.h,$(_glib_all_sources)))) +_glib_generated_ch_resources = $(foreach f,$(_glib_all_ch_resources),$(if $(strip $(call _glib_resources_c_sources,$f)),$f)) + +_glib_all_c_resources = $(filter-out $(_glib_all_ch_resources),$(subst .c,,$(notdir $(filter %resources.c,$(_glib_all_sources))))) +_glib_generated_c_resources = $(foreach f,$(_glib_all_c_resources),$(if $(strip $(call _glib_resources_c_sources,$f)),$f)) + +define _glib_make_h_resources_rules_hidden +:::$(1).h: $(_glib_resources_c_sources) $(_glib_resources_c_deps) +::: $$(_GLIB_V_GEN) $$(GLIB_COMPILE_RESOURCES) \ +::: --target=$$@ --sourcedir="$(srcdir)" \ +::: --generate-header $(2) \ +::: --c-name $(_glib_resources_c_symbol_prefix) \ +::: $$(GLIB_COMPILE_RESOURCES_FLAGS) \ +::: $$($(_glib_resources_c_file_prefix)_COMPILE_RESOURCES_FLAGS) \ +::: $$< +::: +:::_glib_built_sources += $(1).h +endef +_glib_make_h_resources_rules = $(subst :::,,$(_glib_make_h_resources_rules_hidden)) + +define _glib_make_c_resources_rules_hidden +:::$(1).c: $(_glib_resources_c_sources) $(_glib_resources_c_deps) +::: $$(_GLIB_V_GEN) $$(GLIB_COMPILE_RESOURCES) \ +::: --target=$$@ --sourcedir="$(srcdir)" \ +::: --generate-source $(2) \ +::: --c-name $(_glib_resources_c_symbol_prefix) \ +::: $$(GLIB_COMPILE_RESOURCES_FLAGS) \ +::: $$($(_glib_resources_c_file_prefix)_COMPILE_RESOURCES_FLAGS) \ +::: $$< +::: +:::_glib_built_sources += $(1).c +endef +_glib_make_c_resources_rules = $(subst :::,,$(_glib_make_c_resources_rules_hidden)) + +$(foreach f,$(_glib_generated_ch_resources),$(eval $(call _glib_make_h_resources_rules,$f,--manual-register))) +$(foreach f,$(_glib_generated_ch_resources),$(eval $(call _glib_make_c_resources_rules,$f,--manual-register))) +$(foreach f,$(_glib_generated_c_resources),$(eval $(call _glib_make_c_resources_rules,$f,))) + + +_glib_resources_standalone_prefix = $(subst -,_,$(notdir $(1)))_gresource +_glib_resources_standalone_sources_var = $(_glib_resources_standalone_prefix)_sources +_glib_resources_standalone_sources = $($(_glib_resources_standalone_sources_var)) +_glib_resources_standalone_deps = $(shell $(GLIB_COMPILE_RESOURCES) --sourcedir=$(srcdir) --generate-dependencies $(_glib_resources_standalone_sources)) + +_glib_all_standalone_resources = $(subst .gresource,,$(notdir $(filter %.gresource,$(_glib_all_data)))) +_glib_generated_standalone_resources = $(foreach f,$(_glib_all_standalone_resources),$(if $(strip $(call _glib_resources_standalone_sources,$f)),$f)) + +define _glib_make_standalone_resources_rules_hidden +:::$(1).gresource: $(_glib_resources_standalone_sources) $(_glib_resources_standalone_deps) +::: $$(_GLIB_V_GEN) $$(GLIB_COMPILE_RESOURCES) \ +::: --target=$$@ --sourcedir="$(srcdir)" \ +::: $$(GLIB_COMPILE_RESOURCES_FLAGS) \ +::: $$($(_glib_resources_standalone_prefix)_COMPILE_RESOURCES_FLAGS) \ +::: $$< +::: +:::_glib_built_sources += $(1).gresource +endef +_glib_make_standalone_resources_rules = $(subst :::,,$(_glib_make_standalone_resources_rules_hidden)) + +$(foreach f,$(_glib_generated_standalone_resources),$(eval $(call _glib_make_standalone_resources_rules,$f))) diff --git a/tests/gobject/.gitignore b/tests/gobject/.gitignore index 96ea26af5..2df2a8e41 100644 --- a/tests/gobject/.gitignore +++ b/tests/gobject/.gitignore @@ -12,3 +12,4 @@ performance performance-threaded references singleton +testmarshal.list diff --git a/tests/gobject/Makefile.am b/tests/gobject/Makefile.am index 152637b95..e3b094103 100644 --- a/tests/gobject/Makefile.am +++ b/tests/gobject/Makefile.am @@ -1,4 +1,5 @@ include $(top_srcdir)/glib.mk +include $(top_srcdir)/glib-build.mk LDADD = $(top_builddir)/glib/libglib-2.0.la $(top_builddir)/gobject/libgobject-2.0.la AM_CPPFLAGS = $(gmodule_INCLUDES) $(GLIB_DEBUG_FLAGS) @@ -46,42 +47,8 @@ if ENABLE_TIMELOOP installed_test_programs += timeloop-closure endif -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 +testmarshal_sources = $(accumulator_SOURCES) $(defaultiface_SOURCES) $(dynamictype_SOURCES) +DISTCLEANFILES += testmarshal.c testmarshal.h EXTRA_DIST += \ - testcommon.h \ - 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 + testcommon.h diff --git a/tests/gobject/accumulator.c b/tests/gobject/accumulator.c index f8a6c1287..905cc5052 100644 --- a/tests/gobject/accumulator.c +++ b/tests/gobject/accumulator.c @@ -227,21 +227,21 @@ test_object_class_init (TestObjectClass *class) G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (TestObjectClass, test_signal1), test_signal1_accumulator, NULL, - test_marshal_STRING__INT, + _test_marshal_STRING__INT, G_TYPE_STRING, 1, G_TYPE_INT); g_signal_new ("test-signal2", G_OBJECT_CLASS_TYPE (class), G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (TestObjectClass, test_signal2), g_signal_accumulator_true_handled, NULL, - test_marshal_BOOLEAN__INT, + _test_marshal_BOOLEAN__INT, G_TYPE_BOOLEAN, 1, G_TYPE_INT); g_signal_new ("test-signal3", G_OBJECT_CLASS_TYPE (class), G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (TestObjectClass, test_signal3), test_signal3_accumulator, NULL, - test_marshal_VARIANT__POINTER, + _test_marshal_VARIANT__POINTER, G_TYPE_VARIANT, 1, G_TYPE_POINTER); } diff --git a/tests/gobject/testmarshal.list b/tests/gobject/testmarshal.list deleted file mode 100644 index 198c4f9af..000000000 --- a/tests/gobject/testmarshal.list +++ /dev/null @@ -1,4 +0,0 @@ -# Marshallers used in tests -BOOLEAN:INT -STRING:INT -VARIANT:POINTER |