-GTFILES_FILES_LANGS = @all_gtfiles_files_langs@
-GTFILES_FILES_FILES = @all_gtfiles_files_files@
-GTFILES_LANG_DIR_NAMES = @subdirs@
-GTFILES_SRCDIR = @srcdir@
-
-GTFILES_FILES_FILES_C = $(subst $(srcdir)/,, \
- $(filter %.c, $(GTFILES_FILES_FILES)))
-GTFILES_FILES_FILES_H = $(addprefix gt-, \
- $(subst /,-,$(GTFILES_FILES_FILES_C:.c=.h)))
-GTFILES_LANG_DIR_NAMES_H = $(foreach d,$(GTFILES_LANG_DIR_NAMES), gtype-$(d).h)
-ALL_GTFILES_H := $(sort $(GTFILES_FILES_FILES_H) $(GTFILES_LANG_DIR_NAMES_H))
-
-$(ALL_GTFILES_H) : s-gtype ; @true
-
-
-gt-cgraph.h gt-coverage.h gtype-desc.h gtype-desc.c gt-except.h \
-gt-function.h gt-integrate.h gt-tree.h gt-varasm.h \
-gt-emit-rtl.h gt-explow.h gt-stor-layout.h gt-regclass.h \
-gt-lists.h gt-alias.h gt-cselib.h gt-gcse.h \
-gt-expr.h gt-sdbout.h gt-optabs.h gt-bitmap.h gt-dojump.h \
-gt-dwarf2out.h gt-dwarf2asm.h \
-gt-dbxout.h \
-gtype-c.h gt-cfglayout.h \
-gt-tree-mudflap.h gt-tree-vect-generic.h \
-gt-tree-profile.h gt-tree-ssa-address.h \
-gt-tree-iterator.h gt-gimplify.h \
-gt-tree-phinodes.h gt-tree-nested.h \
-gt-tree-ssa-propagate.h gt-varpool.h \
-gt-tree-ssa-structalias.h gt-ipa-inline.h gt-passes.h \
-gt-stringpool.h gt-targhooks.h gt-omp-low.h : s-gtype ; @true
-
-define echo_quoted_to_gtyp
- echo "\"$(gtyp)\", " >> tmp-gtyp.h
+GTFILES_H = $(subst /,-, $(patsubst $(srcdir)/%,gt-%, $(patsubst %.c,%.h, \
+ $(filter %.c, $(GTFILES)))))
+
+GTFILES_LANG_H = $(patsubst [%], gtype-%.h, $(filter [%], $(GTFILES)))
+ALL_GTFILES_H := $(sort $(GTFILES_H) $(GTFILES_LANG_H))
+
+# $(GTFILES) may be too long to put on a command line, so we have to
+# write it out to a file (taking care not to do that in a way that
+# overflows a command line!) and then have gengtype read the file in.
+# The extra blank line in this definition is crucial: it makes the
+# $(foreach ...) below expand to many lines instead of one.
+
+define echo_to_gi.list
+echo '$(gtyp)' >> tmp-gi.list