From 78b95b49f8715a4782f5b9bdc4c163e445cdc303 Mon Sep 17 00:00:00 2001 From: nobu Date: Sun, 22 Jan 2017 12:50:36 +0000 Subject: [PATCH] template/extinit.c.tmpl * template/extinit.c.tmpl: separate from ext/extmk.rb. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57395 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- common.mk | 4 ++++ ext/extmk.rb | 25 ++++--------------------- template/extinit.c.tmpl | 16 ++++++++++++++++ 3 files changed, 24 insertions(+), 21 deletions(-) create mode 100644 template/extinit.c.tmpl diff --git a/common.mk b/common.mk index 3f4bcf6c3a..9db6a3d032 100644 --- a/common.mk +++ b/common.mk @@ -220,6 +220,10 @@ build-ext: $(EXTS_MK) $(Q)$(MAKE) -f $(EXTS_MK) $(MFLAGS) libdir="$(libdir)" LIBRUBY_EXTS=$(LIBRUBY_EXTS) \ EXTENCS="$(ENCOBJS)" UPDATE_LIBRARIES=no $(EXTSTATIC) +ext/extinit.c: $(srcdir)/template/extinit.c.tmpl + $(Q)$(MINIRUBY) $(srcdir)/tool/generic_erb.rb -o $@ -c \ + $(srcdir)/template/extinit.c.tmpl $(EXTINITS) + prog: program wprogram $(PREP): $(MKFILES) diff --git a/ext/extmk.rb b/ext/extmk.rb index dc6bd04945..486712af47 100755 --- a/ext/extmk.rb +++ b/ext/extmk.rb @@ -11,7 +11,6 @@ $destdir = nil $dryrun = false $clean = nil $nodynamic = nil -$extinit = nil $extobjs = [] $extflags = "" $extlibs = nil @@ -642,13 +641,12 @@ if $ignore exit end -$extinit ||= "" $extobjs ||= [] $extpath ||= [] $extflags ||= "" $extlibs ||= [] +extinits = {} unless $extlist.empty? - $extinit << "\n" unless $extinit.empty? list = $extlist.dup built = [] while e = list.shift @@ -662,27 +660,11 @@ unless $extlist.empty? next end base = File.basename(feature) - $extinit << " init(Init_#{base}, \"#{feature}.so\");\n" + extinits[base] = feature $extobjs << format("ext/%s/%s.%s", target, base, $LIBEXT) built << target end - src = %{\ -#include "ruby/ruby.h" - -#define init(func, name) { \\ - extern void func(void); \\ - ruby_init_ext(name, func); \\ -} - -void ruby_init_ext(const char *name, void (*init)(void)); - -void Init_ext(void)\n{\n#$extinit} -} - if !modified?(extinit.c, MTIMES) || IO.read(extinit.c) != src - open(extinit.c, "w") {|fe| fe.print src} - end - $extpath.delete("$(topdir)") $extflags = libpathflag($extpath) << " " << $extflags.strip conf = [ @@ -749,6 +731,7 @@ if $configure_only and $command_output mf.macro "EXTLIBS", $extlibs mf.macro "EXTSO", extso mf.macro "EXTLDFLAGS", $extflags.split + mf.macro "EXTINITS", extinits.map {|k, v| "#{k},#{v}"} submakeopts = [] if enable_config("shared", $enable_shared) submakeopts << 'DLDOBJS="$(EXTOBJS) $(EXTENCS)"' @@ -785,7 +768,7 @@ if $configure_only and $command_output mf.puts "#{tgt}:\n\t#{submake} $@" end mf.puts "libencs:\n\t$(Q)$(MAKE) -f enc.mk V=$(V) $@" - mf.puts "ext/extinit.#{$OBJEXT}:\n\t$(Q)$(MAKE) $(MFLAGS) V=$(V) $@" if $static + mf.puts "ext/extinit.#{$OBJEXT}:\n\t$(Q)$(MAKE) $(MFLAGS) V=$(V) EXTINITS=\"$(EXTINITS)\" $@" if $static mf.puts if $gnumake == "yes" submake = "$(MAKE) -C $(@D)" diff --git a/template/extinit.c.tmpl b/template/extinit.c.tmpl new file mode 100644 index 0000000000..592eb0452f --- /dev/null +++ b/template/extinit.c.tmpl @@ -0,0 +1,16 @@ +%# -*- C -*- +#include "ruby/ruby.h" + +#define init(func, name) { \ + extern void func(void); \ + ruby_init_ext(name, func); \ +} + +void ruby_init_ext(const char *name, void (*init)(void)); + +void Init_ext(void) +{ +% ARGV.each do |n| + init(Init_<%=n.sub(/,(.*)/, ', "\1.so"')%>); +% end +}