diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-01-23 02:50:23 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-01-23 02:50:23 +0000 |
commit | 17b748df2bebc3e02abcf48c06ad73469b642779 (patch) | |
tree | ab182f369cdbe4fa47dcb8cd3cc5602445c15c69 | |
parent | ee9f6fdfada57679e2a434ce2f438a6bda20a5ad (diff) | |
download | ruby-17b748df2bebc3e02abcf48c06ad73469b642779.tar.gz |
Parallel ext configuration
* ext/configure-ext.mk: configure each directories underneath ext
in parallel.
* template/exts.mk.tmpl: then collect the results.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57401 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | .gitignore | 2 | ||||
-rw-r--r-- | Makefile.in | 2 | ||||
-rw-r--r-- | common.mk | 14 | ||||
-rwxr-xr-x | ext/extmk.rb | 8 | ||||
-rw-r--r-- | template/configure-ext.mk.tmpl | 27 | ||||
-rw-r--r-- | template/exts.mk.tmpl | 98 | ||||
-rw-r--r-- | win32/Makefile.sub | 4 |
7 files changed, 148 insertions, 7 deletions
diff --git a/.gitignore b/.gitignore index cc09ab9b04..d028b7e436 100644 --- a/.gitignore +++ b/.gitignore @@ -137,6 +137,8 @@ y.tab.c # /ext/ /ext/extinit.c +/ext/configure-ext.mk +/ext/*/exts.mk # /ext/-test-/win32/dln/ /ext/-test-/win32/dln/dlntest.exp diff --git a/Makefile.in b/Makefile.in index d91b42ed57..d5a3c3d459 100644 --- a/Makefile.in +++ b/Makefile.in @@ -432,7 +432,7 @@ clean-ext distclean-ext realclean-ext:: -$(Q)$(RM) ext/extinit.$(OBJEXT) distclean-ext realclean-ext:: - -$(Q)$(RM) ext/extinit.c + -$(Q)$(RM) ext/extinit.c ext/configure-ext.mk ext/*/exts.mk -$(Q)$(RMDIR) ext 2> /dev/null || true clean-extout: @@ -210,9 +210,19 @@ showconfig: exts: build-ext EXTS_MK = exts.mk -$(EXTS_MK): $(MKFILES) all-incs $(PREP) $(RBCONFIG) $(LIBRUBY) $(TIMESTAMPDIR)/.$(arch).time +$(EXTS_MK): ext/configure-ext.mk $(TIMESTAMPDIR)/.$(arch).time $(srcdir)/template/exts.mk.tmpl + $(MAKE) -f ext/configure-ext.mk V=$(V) MINIRUBY='$(MINIRUBY)' \ + SCRIPT_ARGS='$(SCRIPT_ARGS)' EXTSTATIC=$(EXTSTATIC) \ + gnumake=$(gnumake) EXTLDFLAGS="$(EXTLDFLAGS)" srcdir="$(srcdir)" $(ECHO) generating makefile $@ - $(Q)$(MINIRUBY) $(srcdir)/ext/extmk.rb --make="$(MAKE)" --command-output=$(EXTS_MK) $(EXTMK_ARGS) configure + $(Q)$(MINIRUBY) $(srcdir)/tool/generic_erb.rb -o $@ -c \ + $(srcdir)/template/exts.mk.tmpl + +ext/configure-ext.mk: $(PREP) all-incs $(MKFILES) $(RBCONFIG) $(LIBRUBY) + $(ECHO) generating makefiles $@ + $(Q)$(MAKEDIRS) ext + $(Q)$(MINIRUBY) $(srcdir)/tool/generic_erb.rb -o $@ -c \ + $(srcdir)/template/$(@F).tmpl --srcdir="$(srcdir)" configure-ext: $(EXTS_MK) diff --git a/ext/extmk.rb b/ext/extmk.rb index 602d30826a..1f0d5bdbf6 100755 --- a/ext/extmk.rb +++ b/ext/extmk.rb @@ -421,7 +421,8 @@ if target = ARGV.shift and /^[a-z-]+$/ =~ target "INSTALL_DATA=install -c -p -m 0644", "MAKEDIRS=mkdir -p") if $dryrun when /configure/ - $configure_only = true + target = target.sub(/^sub/, '') + $configure_only = $& || true end end unless $message @@ -674,7 +675,7 @@ unless $extlist.empty? ].map {|n, v| "#{n}=#{v}" if v &&= v[/\S(?:.*\S)?/] }.compact - puts(*conf) + puts(*conf) unless $configure_only == 'sub' $stdout.flush $mflags.concat(conf) $makeflags.concat(conf) @@ -701,6 +702,7 @@ ENV.delete("RUBYOPT") if $configure_only and $command_output exts.map! {|d| "ext/#{d}/."} gems.map! {|d| "gems/#{d}/."} + FileUtils.makedirs(File.dirname($command_output)) atomic_write_open($command_output) do |mf| mf.puts "V = 0" mf.puts "Q1 = $(V:1=)" @@ -760,7 +762,7 @@ if $configure_only and $command_output mf.puts mf.puts "#{rubies.join(' ')}: $(extensions:/.=/#{$force_static ? 'static' : 'all'}) $(gems:/.=/all)" submake = "$(Q)$(MAKE) $(MFLAGS) $(SUBMAKEOPTS)" - mf.puts "all static: #{rubies.join(' ')}\n" + mf.puts "all static: #{rubies.join(' ')}\n" unless $configure_only == 'sub' $extobjs.each do |tgt| mf.puts "#{tgt}: #{File.dirname(tgt)}/static" end diff --git a/template/configure-ext.mk.tmpl b/template/configure-ext.mk.tmpl new file mode 100644 index 0000000000..974a257e2e --- /dev/null +++ b/template/configure-ext.mk.tmpl @@ -0,0 +1,27 @@ +V = 0 +Q1 = $(V:1=) +Q = $(Q1:0=@) +ECHO1 = $(V:1=@:) +ECHO = $(ECHO1:0=@echo) + +<% +srcdir = miniruby = nil +opt = OptionParser.new do |o| + o.on('--srcdir=SRCDIR') {|v| srcdir = v} + o.on('--miniruby=MINIRUBY') {|v| miniruby = v} + o.order!(ARGV) +end +srcdir ||= File.dirname(File.dirname(__FILE__)) +exts = Dir.glob("#{srcdir}/ext/*/").map(&File.method(:basename)) +%> +all: +% exts.each do |dir| +all: ext/<%=dir%>/exts.mk +ext/<%=dir%>/exts.mk: FORCE + $(Q)$(MINIRUBY) $(srcdir)/ext/extmk.rb --make="$(MAKE)" --command-output=ext/<%=dir%>/exts.mk \ + $(SCRIPT_ARGS) --extension=<%=dir%> --extstatic $(EXTSTATIC) \ + --gnumake=$(gnumake) --extflags="$(EXTLDFLAGS)" \ + -- subconfigure +% end + +.PHONY: FORCE diff --git a/template/exts.mk.tmpl b/template/exts.mk.tmpl new file mode 100644 index 0000000000..6fadf79108 --- /dev/null +++ b/template/exts.mk.tmpl @@ -0,0 +1,98 @@ +# -*- makefile -*- +V = 0 +Q1 = $(V:1=) +Q = $(Q1:0=@) +ECHO1 = $(V:1=@:) +ECHO = $(ECHO1:0=@echo) +<% +require './rbconfig' +macros = {} +deps = [] +note = [] +Dir.glob("ext/*/exts.mk") do |e| + s = File.read(e) + s.scan(/^(extensions|EXT[A-Z]+)[ \t]*=[ \t]*((?>(?>[^\\\n]|\\.)*\\\n)*(?>[^\\\n]|\\.)*)$/) do |n, v| + v.gsub!(/\\\n[ \t]*/, ' ') + next if v.empty? + v = v.split + m = macros[n] ||= [] + case n + when "LIBS" + m.concat(v) + else + macros[n] = m | v + end + end + s.scan(%r"^(ext/\S+)/[^/\s:]+:[ \t]*\1/static$|^(?:ruby|install(?:-(?:so|rb))?|static|(?:dist|real)?clean):.+$") do + deps << $& + end + s.scan(%r"^note:\n((?:\t.+\n)+)") do |(n)| + note |= n.split(/^/) + end +end +deps.uniq! +if objs = macros["EXTOBJS"] and objs.any? {|e|e.start_with?("ext/extinit.")} + objs.delete_if {|e|e.start_with?("dmyext.")} +end +macros.default = [].freeze +class Array + def fold(h, w = 70) + return "" if empty? + w -= h + ret = [s = String.new] + each do |e| + if s.size + e.size + 1 > w + ret << (s = String.new) + end + s << " " << e + end + ret.join(" \\\n" + "\t" * (h / 8) + " " * (h % 8)) + end +end +@erbout = _erbout +def self.column + w = 0 + @erbout[/^.*\z/].scan(/\t|([^\t]+)/) {|s,| w += (s ? s.size : 8 - w % 8)} + w +end +targets = %w[all static install install-so install-rb clean distclean realclean] +objext = RbConfig::CONFIG["OBJEXT"] +%> + +extensions =<%= macros["extensions"].fold(column) %> +gems = +EXTOBJS =<%= macros["EXTOBJS"].fold(column) %> +EXTLIBS =<%= macros["EXTLIBS"].fold(column) %> +EXTSO =<%= macros["EXTSO"].fold(column) %> +EXTLDFLAGS =<%= macros["EXTLDFLAGS"].fold(column) %> +EXTINITS =<%= macros["EXTINITS"].fold(column) %> +SUBMAKEOPTS = DLDOBJS="$(EXTOBJS) $(EXTENCS)" EXTOBJS= \ + EXTSOLIBS="$(EXTLIBS)" LIBRUBY_SO_UPDATE=$(LIBRUBY_EXTS) \ + EXTLDFLAGS="$(EXTLDFLAGS)" EXTINITS="$(EXTINITS)" \ + UPDATE_LIBRARIES="$(UPDATE_LIBRARIES)" SHOWFLAGS= + +all static: ruby + +clean: + -$(Q)$(RM) ext/extinit.<%= objext %> +distclean: + -$(Q)$(RM) ext/extinit.c + +<%= deps.join("\n") %> +ruby: + $(Q)$(MAKE) $(MFLAGS) $(SUBMAKEOPTS) $@ +libencs: + $(Q)$(MAKE) -f enc.mk V=$(V) $@ +ext/extinit.<%=objext%>: + $(Q)$(MAKE) $(MFLAGS) V=$(V) EXTINITS="$(EXTINITS)" $@ + +% targets.product(macros["extensions"].map {|e|e.chomp("/.")}) do |t, e| +<%=e%>/<%=t%>: + $(Q)$(MAKE) -C $(@D) $(MFLAGS) V=$(V) $(@F) +% end + +extso: + @echo EXTSO=$(EXTSO) + +note: +<%= note.join("") %> diff --git a/win32/Makefile.sub b/win32/Makefile.sub index d90f24f7cd..4b819e635d 100644 --- a/win32/Makefile.sub +++ b/win32/Makefile.sub @@ -1072,7 +1072,9 @@ clean-ext distclean-ext realclean-ext:: ) ) distclean-ext realclean-ext:: - -$(Q)$(RM) ext/extinit.c + -$(Q)$(RM) ext/extinit.c ext/configure-ext.mk + @cd ext && for /D $(EXTS) %I in (.) \ + do @if exist %I\exts.mk del %I\exts.mk -$(Q)rmdir ext 2> nul || @ clean-extout: |