[PATCH, gcc] create gtyp-input.list efficiently

Ralf Wildenhues Ralf.Wildenhues@gmx.de
Sun Jul 6 12:52:00 GMT 2008


Same game as done before in libjava: for lists exceeding command line
length limits, avoid forking once per list entry.  This builds
tmp-gi.list in 0.5s on my GNU/Linux system instead of 2s (for w32, the
win is hopefully more pronounced).

The only disadvantage of this change is that 'make' output does not show
any more how exactly the file is created.  For debugging such rules,
  make "SHELL=/bin/sh -x"
is very helpful.

Bootstrapped i686-pc-linux-gnu, checked for identical gtyp-input.list.
OK for trunk?

(PR33781 is about a related issue for libgcc, but it needs more work.)

Thanks,
Ralf

gcc/ChangeLog:
2008-07-06  Ralf Wildenhues  <Ralf.Wildenhues@gmx.de>

	* Makefile.in (write_entries_to_file, write_entries_to_file_split):
	New macros.
	(s-gtyp-input): Use them to write tmp-gi.list.
	(echo_to_gi.list): Remove.

diff --git a/gcc/Makefile.in b/gcc/Makefile.in
index 298e5f2..0dcb1d1 100644
--- a/gcc/Makefile.in
+++ b/gcc/Makefile.in
@@ -256,6 +256,22 @@ build_file_translate = @build_file_translate@
 # Locate mkinstalldirs.
 mkinstalldirs=$(SHELL) $(srcdir)/../mkinstalldirs
 
+# write_entries_to_file - writes each entry in a list
+# to the specified file.  Entries are written in chunks of
+# $(write_entries_to_file_split) to accomodate systems with
+# severe command-line-length limitations.
+# Parameters:
+# $(1): variable containing entries to iterate over
+# $(2): output file
+write_entries_to_file_split = 50
+write_entries_to_file = $(shell rm -f $(2) || :) $(shell touch $(2)) \
+	$(foreach range, \
+	  $(shell i=1; while test $$i -le $(words $(1)); do \
+	     echo $$i; i=`expr $$i + $(write_entries_to_file_split)`; done), \
+	  $(shell echo $(wordlist $(range), \
+			  $(shell expr $(range) + $(write_entries_to_file_split) - 1), $(1)) \
+	     | tr ' ' '\n' >> $(2)))
+
 # --------
 # UNSORTED
 # --------
@@ -3174,20 +3190,13 @@ 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
-
-endef
 
 $(ALL_GTFILES_H) gtype-desc.c gtype-desc.h : s-gtype ; @true
 
 gtyp-input.list: s-gtyp-input ; @true
 s-gtyp-input: Makefile
-	rm -f tmp-gi.list
-	$(foreach gtyp, $(GTFILES), $(echo_to_gi.list))
+	@: $(call write_entries_to_file,$(GTFILES),tmp-gi.list)
+	@ echo "# entries for tmp-gi.list written"
 	$(SHELL) $(srcdir)/../move-if-change tmp-gi.list gtyp-input.list
 	$(STAMP) s-gtyp-input
 



More information about the Gcc-patches mailing list