ruby-changes:14375
From: nobu <ko1@a...>
Date: Thu, 31 Dec 2009 01:59:11 +0900 (JST)
Subject: [ruby-changes:14375] Ruby:r26205 (ruby_1_8, trunk): * ext/extmk.rb: fix for extstatic.
nobu 2009-12-31 01:58:51 +0900 (Thu, 31 Dec 2009) New Revision: 26205 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=26205 Log: * ext/extmk.rb: fix for extstatic. Modified files: branches/ruby_1_8/ChangeLog branches/ruby_1_8/ext/extmk.rb branches/ruby_1_8/lib/mkmf.rb branches/ruby_1_8/version.h trunk/ChangeLog trunk/ext/extmk.rb trunk/version.h Index: ChangeLog =================================================================== --- ChangeLog (revision 26204) +++ ChangeLog (revision 26205) @@ -1,3 +1,7 @@ +Thu Dec 31 01:58:47 2009 Nobuyoshi Nakada <nobu@r...> + + * ext/extmk.rb: fix for extstatic. + Wed Dec 30 19:43:00 2009 NARUSE, Yui <naruse@r...> * include/ruby/ruby.h (RREGEXP_SRC_END): added. Index: ext/extmk.rb =================================================================== --- ext/extmk.rb (revision 26204) +++ ext/extmk.rb (revision 26205) @@ -69,8 +69,10 @@ end $target = target $extconf_h = m[/^RUBY_EXTCONF_H[ \t]*=[ \t]*(\S+)/, 1] - $static ||= m[/^EXTSTATIC[ \t]*=[ \t]*(\S+)/, 1] || false - /^STATIC_LIB[ \t]*=[ \t]*\S+/ =~ m or $static = nil + if $static.nil? + $static ||= m[/^EXTSTATIC[ \t]*=[ \t]*(\S+)/, 1] || false + /^STATIC_LIB[ \t]*=[ \t]*\S+/ =~ m or $static = false + end $preload = Shellwords.shellwords(m[/^preload[ \t]*=[ \t]*(.*)/, 1] || "") $DLDFLAGS += " " + (m[/^dldflags[ \t]*=[ \t]*(.*)/, 1] || "") if s = m[/^LIBS[ \t]*=[ \t]*(.*)/, 1] @@ -439,7 +441,7 @@ hdrdir = $hdrdir $hdrdir = ($top_srcdir = relative_from(srcdir, $topdir = "..")) + "/include" exts.each do |d| - $static = $force_static ? $static_ext[target] : false + $static = $force_static ? $static_ext[target] : nil if $ignore or !$nodynamic or $static extmake(d) or abort @@ -491,7 +493,7 @@ end next end - f = format("%s/%s.%s", s, i, $LIBEXT) + f = format("%s/%s.%s", t, i, $LIBEXT) if File.exist?(f) $extinit << " init(Init_#{i}, \"#{t}.so\");\n" $extobjs << "ext/#{f} " @@ -570,7 +572,7 @@ ENV.delete("RUBYOPT") if $command_output message = "echo #{message}" - cmd = $makeflags.join(' ') + cmd = $makeflags.map {|s|s.sub(/.*[$(){};\s].*/, %q['\&'])}.join(' ') open($command_output, 'wb') do |f| case $command_output when /\.sh\z/ Index: version.h =================================================================== --- version.h (revision 26204) +++ version.h (revision 26205) @@ -1,5 +1,5 @@ #define RUBY_VERSION "1.9.2" -#define RUBY_RELEASE_DATE "2009-12-30" +#define RUBY_RELEASE_DATE "2009-12-31" #define RUBY_PATCHLEVEL -1 #define RUBY_BRANCH_NAME "trunk" @@ -8,7 +8,7 @@ #define RUBY_VERSION_TEENY 1 #define RUBY_RELEASE_YEAR 2009 #define RUBY_RELEASE_MONTH 12 -#define RUBY_RELEASE_DAY 30 +#define RUBY_RELEASE_DAY 31 #include "ruby/version.h" Index: ruby_1_8/ext/extmk.rb =================================================================== --- ruby_1_8/ext/extmk.rb (revision 26204) +++ ruby_1_8/ext/extmk.rb (revision 26205) @@ -25,17 +25,18 @@ $extlist = [] $compiled = {} -$:.replace([Dir.pwd]) +srcdir = File.dirname(File.dirname(__FILE__)) +unless defined?(CROSS_COMPILING) and CROSS_COMPILING + $:.replace([File.expand_path("lib", srcdir), Dir.pwd]) +end +$:.unshift(srcdir) require 'rbconfig' -srcdir = File.dirname(File.dirname(__FILE__)) - -$:.unshift(srcdir, File.expand_path("lib", srcdir)) - $topdir = "." $top_srcdir = srcdir -require 'mkmf' +$" << "mkmf.rb" +load File.expand_path("lib/mkmf.rb", srcdir) require 'optparse/shellwords' def sysquote(x) @@ -43,15 +44,6 @@ @quote ? x.quote : x end -def relative_from(path, base) - dir = File.join(path, "") - if File.expand_path(dir) == File.expand_path(dir, base) - path - else - File.join(base, path) - end -end - def extract_makefile(makefile, keep = true) m = File.read(makefile) if !(target = m[/^TARGET[ \t]*=[ \t]*(\S*)/, 1]) @@ -70,15 +62,17 @@ unless installrb.empty? config = CONFIG.dup install_dirs(target_prefix).each {|var, val| config[var] = val} - FileUtils.rm_f(installrb.values.collect {|f| Config.expand(f, config)}, :verbose => true) + FileUtils.rm_f(installrb.values.collect {|f| RbConfig.expand(f, config)}, :verbose => true) end end return false end $target = target $extconf_h = m[/^RUBY_EXTCONF_H[ \t]*=[ \t]*(\S+)/, 1] - $static ||= m[/^EXTSTATIC[ \t]*=[ \t]*(\S+)/, 1] || false - /^STATIC_LIB[ \t]*=[ \t]*\S+/ =~ m or $static = nil + if $static.nil? + $static ||= m[/^EXTSTATIC[ \t]*=[ \t]*(\S+)/, 1] || false + /^STATIC_LIB[ \t]*=[ \t]*\S+/ =~ m or $static = false + end $preload = Shellwords.shellwords(m[/^preload[ \t]*=[ \t]*(.*)/, 1] || "") $DLDFLAGS += " " + (m[/^dldflags[ \t]*=[ \t]*(.*)/, 1] || "") if s = m[/^LIBS[ \t]*=[ \t]*(.*)/, 1] @@ -120,7 +114,7 @@ makefile = "./Makefile" ok = File.exist?(makefile) unless $ignore - rbconfig0 = Config::CONFIG + rbconfig0 = RbConfig::CONFIG mkconfig0 = CONFIG rbconfig = { "hdrdir" => $hdrdir, @@ -134,7 +128,7 @@ } rbconfig0.each_pair {|key, val| rbconfig[key] ||= val.dup} mkconfig0.each_pair {|key, val| mkconfig[key] ||= val.dup} - Config.module_eval { + RbConfig.module_eval { remove_const(:CONFIG) const_set(:CONFIG, rbconfig) remove_const(:MAKEFILE_CONFIG) @@ -177,7 +171,7 @@ ok = yield(ok) if block_given? unless ok open(makefile, "w") do |f| - f.print dummy_makefile(CONFIG["srcdir"]) + f.print(*dummy_makefile(CONFIG["srcdir"])) end return true end @@ -200,7 +194,6 @@ if $clean != true FileUtils.rm_f([makefile, $extconf_h || "extconf.h"]) end - File.unlink(makefile) rescue nil end if $static $extflags ||= "" @@ -214,7 +207,7 @@ end ensure unless $ignore - Config.module_eval { + RbConfig.module_eval { remove_const(:CONFIG) const_set(:CONFIG, rbconfig0) remove_const(:MAKEFILE_CONFIG) @@ -247,7 +240,6 @@ $mflags = [] $makeflags = [] - opts = nil $optparser ||= OptionParser.new do |opts| opts.on('-n') {$dryrun = true} opts.on('--[no-]extension [EXTS]', Array) do |v| @@ -290,7 +282,7 @@ rescue OptionParser::InvalidOption => e retry if /^--/ =~ e.args[0] $optparser.warn(e) - abort opts.to_s + abort $optparser.to_s end $destdir ||= '' @@ -316,7 +308,7 @@ $continue = $mflags.set?(?k) if $extout $extout = '$(topdir)/'+$extout - Config::CONFIG["extout"] = CONFIG["extout"] = $extout + RbConfig::CONFIG["extout"] = CONFIG["extout"] = $extout $extout_prefix = $extout ? "$(extout)$(target_prefix)/" : "" $mflags << "extout=#$extout" << "extout_prefix=#$extout_prefix" end @@ -361,7 +353,7 @@ $ruby << " -I'$(extout)/$(arch)' -I'$(extout)/common'" if $extout $ruby << " -I./- -I'$(top_srcdir)/ext' -rpurelib.rb" ENV["RUBYLIB"] = "-" - ENV["RUBYOPT"] = "-rpurelib.rb" + ENV["RUBYOPT"] = "-r#{File.expand_path('ext/purelib.rb', $top_srcdir)}" end $config_h = '$(topdir)/config.h' $mflags << "ruby=#$ruby" @@ -371,8 +363,9 @@ # get static-link modules $static_ext = {} if $extstatic - $extstatic.each do |target| - target = target.downcase if /mswin32|bccwin32/ =~ RUBY_PLATFORM + $extstatic.each do |t| + target = t + target = target.downcase if File::FNM_SYSCASE.nonzero? $static_ext[target] = $static_ext.size end end @@ -392,7 +385,7 @@ end next end - target = target.downcase if /mswin32|bccwin32/ =~ RUBY_PLATFORM + target = target.downcase if File::FNM_SYSCASE.nonzero? $static_ext[target] = $static_ext.size end MTIMES << f.mtime @@ -408,12 +401,12 @@ exts |= $extension.select {|d| File.directory?("#{ext_prefix}/#{d}")} else withes, withouts = %w[--with --without].collect {|w| - if not (w = %w[-extensions -ext].collect {|opt|arg_config(w+opt)}).any? + if not (w = %w[-extensions -ext].collect {|o|arg_config(w+o)}).any? nil elsif (w = w.grep(String)).empty? proc {true} else - proc {|c1| w.collect {|opt| opt.split(/,/)}.flatten.any?(&c1)} + proc {|c1| w.collect {|o| o.split(/,/)}.flatten.any?(&c1)} end } if withes @@ -422,8 +415,8 @@ withes = proc {false} withouts ||= withes end - cond = proc {|ext| - cond1 = proc {|n| File.fnmatch(n, ext, File::FNM_PATHNAME)} + cond = proc {|ext, *| + cond1 = proc {|n| File.fnmatch(n, ext)} withes.call(cond1) or !withouts.call(cond1) } exts |= Dir.glob("#{ext_prefix}/*/**/extconf.rb").collect {|d| @@ -436,7 +429,7 @@ end if $extout - extout = Config.expand("#{$extout}", Config::CONFIG.merge("topdir"=>$topdir)) + extout = RbConfig.expand("#{$extout}", RbConfig::CONFIG.merge("topdir"=>$topdir)) unless $ignore FileUtils.mkpath(extout) end @@ -449,7 +442,7 @@ hdrdir = $hdrdir $hdrdir = $top_srcdir = relative_from(srcdir, $topdir = "..") exts.each do |d| - $static = $force_static ? $static_ext[target] : false + $static = $force_static ? $static_ext[target] : nil if $ignore or !$nodynamic or $static extmake(d) or abort @@ -501,7 +494,7 @@ end next end - f = format("%s/%s.%s", s, i, $LIBEXT) + f = format("%s/%s.%s", t, i, $LIBEXT) if File.exist?(f) $extinit << " init(Init_#{i}, \"#{t}.so\");\n" $extobjs << "ext/#{f} " @@ -512,14 +505,17 @@ src = %{\ #include "ruby.h" -#define init(func, name) {void func _((void)); ruby_init_ext(name, func);} +#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") {|f| f.print src} + open(extinit.c, "w") {|fe| fe.print src} end $extobjs = "ext/#{extinit.o} #{$extobjs}" @@ -536,7 +532,7 @@ ].map {|n, v| "#{n}=#{v}" if v and !(v = v.strip).empty? }.compact - puts conf + puts(*conf) $stdout.flush $mflags.concat(conf) $makeflags.concat(conf) @@ -544,10 +540,10 @@ FileUtils.rm_f(extinit.to_a) end rubies = [] -%w[RUBY RUBYW STATIC_RUBY].each {|r| - n = r +%w[RUBY RUBYW STATIC_RUBY].each {|n| + r = n if r = arg_config("--"+r.downcase) || config_string(r+"_INSTALL_NAME") - rubies << Config.expand(r+=EXEEXT) + rubies << RbConfig.expand(r+=EXEEXT) $mflags << "#{n}=#{r}" end } @@ -573,9 +569,11 @@ vars.each {|flag| flag.sub!(/\A/, "-D")} end end +$mflags.unshift("topdir=#$topdir") +ENV.delete("RUBYOPT") if $command_output message = "echo #{message}" - cmd = $makeflags.join(' ') + cmd = $makeflags.map {|s|s.sub(/.*[$(){};\s].*/, %q['\&'])}.join(' ') open($command_output, 'wb') do |f| case $command_output when /\.sh\z/ Index: ruby_1_8/ChangeLog =================================================================== --- ruby_1_8/ChangeLog (revision 26204) +++ ruby_1_8/ChangeLog (revision 26205) @@ -1,3 +1,7 @@ +Thu Dec 31 01:58:47 2009 Nobuyoshi Nakada <nobu@r...> + + * ext/extmk.rb: fix for extstatic. + Tue Dec 29 11:20:41 2009 Marc-Andre Lafortune <ruby-core@m...> * lib/delegate.rb (marshal_dump/load): Revert r26122, r26194, as per Index: ruby_1_8/version.h =================================================================== --- ruby_1_8/version.h (revision 26204) +++ ruby_1_8/version.h (revision 26205) @@ -1,7 +1,7 @@ #define RUBY_VERSION "1.8.8" -#define RUBY_RELEASE_DATE "2009-12-29" +#define RUBY_RELEASE_DATE "2009-12-31" #define RUBY_VERSION_CODE 188 -#define RUBY_RELEASE_CODE 20091229 +#define RUBY_RELEASE_CODE 20091231 #define RUBY_PATCHLEVEL -1 #define RUBY_VERSION_MAJOR 1 @@ -9,7 +9,7 @@ #define RUBY_VERSION_TEENY 8 #define RUBY_RELEASE_YEAR 2009 #define RUBY_RELEASE_MONTH 12 -#define RUBY_RELEASE_DAY 29 +#define RUBY_RELEASE_DAY 31 #ifdef RUBY_EXTERN RUBY_EXTERN const char ruby_version[]; Index: ruby_1_8/lib/mkmf.rb =================================================================== --- ruby_1_8/lib/mkmf.rb (revision 26204) +++ ruby_1_8/lib/mkmf.rb (revision 26205) @@ -6,15 +6,16 @@ require 'fileutils' require 'shellwords' -CONFIG = Config::MAKEFILE_CONFIG +CONFIG = RbConfig::MAKEFILE_CONFIG ORIG_LIBPATH = ENV['LIB'] CXX_EXT = %w[cc cxx cpp] -if /mswin|bccwin|mingw|cygwin|msdosdjgpp|human|os2/ !~ CONFIG['build_os'] +if File::FNM_SYSCASE.zero? CXX_EXT.concat(%w[C]) end SRC_EXT = %w[c m].concat(CXX_EXT) -$static = $config_h = nil +$static = nil +$config_h = '$(hdrdir)/config.h' $default_static = $static unless defined? $configure_args @@ -65,6 +66,7 @@ $os2 = /os2/ =~ RUBY_PLATFORM $beos = /beos/ =~ RUBY_PLATFORM $solaris = /solaris/ =~ RUBY_PLATFORM +$universal = /universal/ =~ RUBY_PLATFORM $dest_prefix_pattern = (File::PATH_SEPARATOR == ';' ? /\A([[:alpha:]]:)?/ : /\A/) # :stopdoc: @@ -77,6 +79,15 @@ Regexp.new('\$(?:\('+dir+'\)|\{'+dir+'\})(?:\$(?:\(target_prefix\)|\{target_prefix\}))?') end +def relative_from(path, base) + dir = File.join(path, "") + if File.expand_path(dir) == File.expand_path(dir, base) + path + else + File.join(base, path) + end +end + INSTALL_DIRS = [ [dir_re('commondir'), "$(RUBYCOMMONDIR)"], [dir_re('sitedir'), "$(RUBYCOMMONDIR)"], @@ -86,8 +97,11 @@ [dir_re('sitelibdir'), "$(RUBYLIBDIR)"], [dir_re('vendorlibdir'), "$(RUBYLIBDIR)"], [dir_re('sitearchdir'), "$(RUBYARCHDIR)"], + [dir_re('vendorarchdir'), "$(RUBYARCHDIR)"], + [dir_re('rubyhdrdir'), "$(RUBYHDRDIR)"], + [dir_re('sitehdrdir'), "$(SITEHDRDIR)"], + [dir_re('vendorhdrdir'), "$(VENDORHDRDIR)"], [dir_re('bindir'), "$(BINDIR)"], - [dir_re('vendorarchdir'), "$(RUBYARCHDIR)"], ] def install_dirs(target_prefix = nil) @@ -97,6 +111,8 @@ ['RUBYCOMMONDIR', '$(extout)/common'], ['RUBYLIBDIR', '$(RUBYCOMMONDIR)$(target_prefix)'], ['RUBYARCHDIR', '$(extout)/$(arch)$(target_prefix)'], + ['HDRDIR', '$(extout)/include/ruby$(target_prefix)'], + ['ARCHHDRDIR', '$(extout)/include/$(arch)/ruby$(target_prefix)'], ['extout', "#$extout"], ['extout_prefix', "#$extout_prefix"], ] @@ -106,6 +122,8 @@ ['RUBYCOMMONDIR', '$(rubylibdir)'], ['RUBYLIBDIR', '$(rubylibdir)$(target_prefix)'], ['RUBYARCHDIR', '$(archdir)$(target_prefix)'], + ['HDRDIR', '$(rubyhdrdir)$(target_prefix)'], + ['ARCHHDRDIR', '$(rubyhdrdir)$(target_prefix)'], ] elsif $configure_args.has_key?('--vendor') dirs = [ @@ -113,6 +131,8 @@ ['RUBYCOMMONDIR', '$(vendordir)$(target_prefix)'], ['RUBYLIBDIR', '$(vendorlibdir)$(target_prefix)'], ['RUBYARCHDIR', '$(vendorarchdir)$(target_prefix)'], + ['HDRDIR', '$(vendordir)$(target_prefix)'], + ['ARCHHDRDIR', '$(vendordir)$(target_prefix)'], ] else dirs = [ @@ -120,6 +140,8 @@ ['RUBYCOMMONDIR', '$(sitedir)$(target_prefix)'], ['RUBYLIBDIR', '$(sitelibdir)$(target_prefix)'], ['RUBYARCHDIR', '$(sitearchdir)$(target_prefix)'], + ['HDRDIR', '$(sitedir)$(target_prefix)'], + ['ARCHHDRDIR', '$(sitedir)$(target_prefix)'], ] end dirs << ['target_prefix', (target_prefix ? "/#{target_prefix}" : "")] @@ -128,24 +150,31 @@ def map_dir(dir, map = nil) map ||= INSTALL_DIRS - map.inject(dir) {|dir, (orig, new)| dir.gsub(orig, new)} + map.inject(dir) {|d, (orig, new)| d.gsub(orig, new)} end topdir = File.dirname(libdir = File.dirname(__FILE__)) extdir = File.expand_path("ext", topdir) -$extmk = File.expand_path($0)[0, extdir.size+1] == extdir+"/" -if not $extmk and File.exist?(($hdrdir = Config::CONFIG["archdir"]) + "/ruby.h") +path = File.expand_path($0) +$extmk = path[0, topdir.size+1] == topdir+"/" +$extmk &&= %r"\A(?:ext|enc|tool|test(?:/.+))\z" =~ File.dirname(path[topdir.size+1..-1]) +$extmk &&= true +if not $extmk and File.exist?(($hdrdir = RbConfig::CONFIG["archdir"]) + "/ruby.h") $topdir = $hdrdir -elsif File.exist?(($hdrdir = ($top_srcdir ||= topdir)) + "/ruby.h") and - File.exist?(($topdir ||= Config::CONFIG["topdir"]) + "/config.h") + $top_srcdir = $hdrdir + $arch_hdrdir = $hdrdir +elsif File.exist?(($hdrdir = ($top_srcdir ||= topdir)) + "/ruby.h") + $topdir ||= RbConfig::CONFIG["topdir"] + $arch_hdrdir = $topdir else abort "mkmf.rb can't find header files for ruby at #{$hdrdir}/ruby.h" end OUTFLAG = CONFIG['OUTFLAG'] +COUTFLAG = CONFIG['COUTFLAG'] CPPOUTFILE = CONFIG['CPPOUTFILE'] -CONFTEST_C = "conftest.c" +CONFTEST_C = "conftest.c".freeze class String # Wraps a string in escaped quotes if it contains whitespace. @@ -166,11 +195,13 @@ end def rm_f(*files) - FileUtils.rm_f(Dir[files.join("\0")]) + opt = (Hash === files.last ? [files.pop] : []) + FileUtils.rm_f(Dir[*files.flatten], *opt) end def rm_rf(*files) - FileUtils.rm_rf(Dir[*files]) + opt = (Hash === files.last ? [files.pop] : []) + FileUtils.rm_rf(Dir[*files.flatten], *opt) end # Returns time stamp of the +target+ file if it exists and is newer @@ -211,9 +242,13 @@ @postpone = 0 @quiet = $extmk + def self::log_open + @log ||= File::open(@logfile, 'wb') + @log.sync = true + end + def self::open - @log ||= File::open(@logfile, 'w') - @log.sync = true + log_open $stderr.reopen(@log) $stdout.reopen(@log) yield @@ -223,8 +258,7 @@ end def self::message(*s) - @log ||= File::open(@logfile, 'w') - @log.sync = true + log_open @log.printf(*s) end @@ -236,7 +270,7 @@ @log = nil end end - + def self::postpone tmplog = "mkmftmp#{@postpone += 1}.log" open do @@ -304,8 +338,16 @@ src.gsub!(/[ \t]+$/, '') src.gsub!(/\A\n+|^\n+$/, '') src.sub!(/[^\n]\z/, "\\&\n") - open(CONFTEST_C, "wb") do |cfile| - cfile.print src + count = 0 + begin + open(CONFTEST_C, "wb") do |cfile| + cfile.print src + end + rescue Errno::EACCES + if (count += 1) < 5 + sleep 0.2 + retry + end end src end @@ -333,29 +375,35 @@ end def link_command(ldflags, opt="", libpath=$DEFLIBPATH|$LIBPATH) - conf = Config::CONFIG.merge('hdrdir' => $hdrdir.quote, - 'src' => CONFTEST_C, - 'INCFLAGS' => $INCFLAGS, - 'CPPFLAGS' => $CPPFLAGS, - 'CFLAGS' => "#$CFLAGS", - 'ARCH_FLAG' => "#$ARCH_FLAG", - 'LDFLAGS' => "#$LDFLAGS #{ldflags}", - 'LIBPATH' => libpathflag(libpath), - 'LOCAL_LIBS' => "#$LOCAL_LIBS #$libs", - 'LIBS' => "#$LIBRUBYARG_STATIC #{opt} #$LIBS") - Config::expand(TRY_LINK.dup, conf) + conf = RbConfig::CONFIG.merge('hdrdir' => $hdrdir.quote, + 'src' => "#{CONFTEST_C}", + 'arch_hdrdir' => "#$arch_hdrdir", + 'top_srcdir' => $top_srcdir.quote, + 'INCFLAGS' => "#$INCFLAGS", + 'CPPFLAGS' => "#$CPPFLAGS", + 'CFLAGS' => "#$CFLAGS", + 'ARCH_FLAG' => "#$ARCH_FLAG", + 'LDFLAGS' => "#$LDFLAGS #{ldflags}", + 'LIBPATH' => libpathflag(libpath), + 'LOCAL_LIBS' => "#$LOCAL_LIBS #$libs", + 'LIBS' => "#$LIBRUBYARG_STATIC #{opt} #$LIBS") + RbConfig::expand(TRY_LINK.dup, conf) end def cc_command(opt="") - conf = Config::CONFIG.merge('hdrdir' => $hdrdir.quote, 'srcdir' => $srcdir.quote) - Config::expand("$(CC) #$INCFLAGS #$CPPFLAGS #$CFLAGS #$ARCH_FLAG #{opt} -c #{CONFTEST_C}", - conf) + conf = RbConfig::CONFIG.merge('hdrdir' => $hdrdir.quote, 'srcdir' => $srcdir.quote, + 'arch_hdrdir' => "#$arch_hdrdir", + 'top_srcdir' => $top_srcdir.quote) + RbConfig::expand("$(CC) #$INCFLAGS #$CPPFLAGS #$CFLAGS #$ARCH_FLAG #{opt} -c #{CONFTEST_C}", + conf) end def cpp_command(outfile, opt="") - conf = Config::CONFIG.merge('hdrdir' => $hdrdir.quote, 'srcdir' => $srcdir.quote) - Config::expand("$(CPP) #$INCFLAGS #$CPPFLAGS #$CFLAGS #{opt} #{CONFTEST_C} #{outfile}", - conf) + conf = RbConfig::CONFIG.merge('hdrdir' => $hdrdir.quote, 'srcdir' => $srcdir.quote, + 'arch_hdrdir' => "#$arch_hdrdir", + 'top_srcdir' => $top_srcdir.quote) + RbConfig::expand("$(CPP) #$INCFLAGS #$CPPFLAGS #$CFLAGS #{opt} #{CONFTEST_C} #{outfile}", + conf) end def libpathflag(libpath=$DEFLIBPATH|$LIBPATH) @@ -370,7 +418,20 @@ end def try_link0(src, opt="", &b) - try_do(src, link_command("", opt), &b) + cmd = link_command("", opt) + if $universal + require 'tmpdir' + Dir.mktmpdir("mkmf_", oldtmpdir = ENV["TMPDIR"]) do |tmpdir| + begin + ENV["TMPDIR"] = tmpdir + try_do(src, cmd, &b) + ensure + ENV["TMPDIR"] = oldtmpdir + end + end + else + try_do(src, cmd, &b) + end end def try_link(src, opt="", &b) @@ -391,10 +452,14 @@ rm_f "conftest*" end +class Object + alias_method :try_header, (config_string('try_header') || :try_cpp) +end + def cpp_include(header) if header header = [header] unless header.kind_of? Array - header.map {|h| "#include <#{h}>\n"}.join + header.map {|h| String === h ? "#include <#{h}>\n" : h}.join else "" end @@ -558,7 +623,7 @@ ifiles or return ifiles.empty? and return srcprefix ||= '$(srcdir)' - Config::expand(srcdir = srcprefix.dup) + RbConfig::expand(srcdir = srcprefix.dup) dirs = [] path = Hash.new {|h, i| h[i] = dirs.push([i])[-1]} ifiles.each do |files, dir, prefix| @@ -574,7 +639,8 @@ len = srcdir.size end f = nil - Dir.glob(files) do |f| + Dir.glob(files) do |fx| + f = fx f[0..len] = "" if len case File.basename(f) when *$NONINSTALLFILES @@ -617,7 +683,7 @@ # Internal use only. # def checking_for(m, fmt = nil) - f = caller[0][/in `(.*)'$/, 1] and f << ": " #` for vim + f = caller[0][/in `(.*)'$/, 1] and f << ": " #` for vim #' m = "checking #{/\Acheck/ =~ f ? '' : 'for '}#{m}... " message "%s", m a = r = nil @@ -761,9 +827,9 @@ # For example, if have_header('foo.h') returned true, then the HAVE_FOO_H # preprocessor macro would be passed to the compiler. # -def have_header(header, &b) +def have_header(header, preheaders = nil, &b) checking_for header do - if try_cpp(cpp_include(header), &b) + if try_header(cpp_include(preheaders)+cpp_include(header), &b) $defs.push(format("-DHAVE_%s", header.tr("a-z./\055", "A-Z___"))) true else @@ -782,13 +848,13 @@ message = checking_message(header, paths) header = cpp_include(header) checking_for message do - if try_cpp(header) + if try_header(header) true else found = false paths.each do |dir| opt = "-I#{dir}".quote - if try_cpp(header, opt) + if try_header(header, opt) $INCFLAGS << " " << opt found = true break @@ -805,11 +871,13 @@ # (in addition to the common header files). # # If found, a macro is passed as a preprocessor constant to the compiler using -# the member name, in uppercase, prepended with 'HAVE_ST_'. +# the type name and the member name, in uppercase, prepended with 'HAVE_'. # # For example, if have_struct_member('struct foo', 'bar') returned true, then the -# HAVE_ST_BAR preprocessor macro would be passed to the compiler. -# +# HAVE_STRUCT_FOO_BAR preprocessor macro would be passed to the compiler. +# +# HAVE_ST_BAR is also defined for backward compatibility. +# def have_struct_member(type, member, headers = nil, &b) checking_for checking_message("#{type}.#{member}", headers) do if try_compile(<<"SRC", &b) @@ -818,7 +886,8 @@ #{MAIN_DOES_NOTHING} int s = (char *)&((#{type}*)0)->#{member} - (char *)0; SRC - $defs.push(format("-DHAVE_ST_%s", member.tr_cpp)) + $defs.push(format("-DHAVE_%s_%s", type.tr_cpp, member.tr_cpp)) + $defs.push(format("-DHAVE_ST_%s", member.tr_cpp)) # backward compatibility true else false @@ -926,16 +995,28 @@ # For example, if check_sizeof('mystruct') returned 12, then the # SIZEOF_MYSTRUCT=12 preprocessor macro would be passed to the compiler. # -def check_sizeof(type, headers = nil, &b) - expr = "sizeof(#{type})" - fmt = "%d" +def check_sizeof(type, headers = nil, opts = "", &b) + typename, member = type.split('.', 2) + prelude = cpp_include(headers).split(/$/) + prelude << "typedef #{typename} rbcv_typedef_;\n" + prelude << "static rbcv_typedef_ *rbcv_ptr_;\n" + prelude = [prelude] + expr = "sizeof((*rbcv_ptr_)#{"." << member if member})" + fmt = "%s" def fmt.%(x) x ? super : "failed" end checking_for checking_message("size of #{type}", headers), fmt do - if size = try_constant(expr, headers, &b) - $defs.push(format("-DSIZEOF_%s=%d", type.tr_cpp, size)) + if UNIVERSAL_INTS.include?(type) + type + elsif size = UNIVERSAL_INTS.find {|t| + try_static_assert("#{expr} == sizeof(#{t})", prelude, opts, &b) + } + $defs.push(format("-DSIZEOF_%s=SIZEOF_%s", type.tr_cpp, size.tr_cpp)) size + elsif size = try_constant(expr, prelude, opts, &b) + $defs.push(format("-DSIZEOF_%s=%s", type.tr_cpp, size)) + size end end end @@ -966,35 +1047,74 @@ SRC end +# Used internally by the what_type? method to check if _typeof_ GCC +# extension is available. +def have_typeof? + return $typeof if defined?($typeof) + $typeof = %w[__typeof__ typeof].find do |t| + try_compile(<<SRC) +int rbcv_foo; +#{t}(rbcv_foo) rbcv_bar; +SRC + end +end + def what_type?(type, member = nil, headers = nil, &b) m = "#{type}" - name = type + var = val = "*rbcv_var_" + func = "rbcv_func_(void)" if member m << "." << member - name = "(((#{type} *)0)->#{member})" + else + type, member = type.split('.', 2) end - fmt = "seems %s" + if member + val = "(#{var}).#{member}" + end + prelude = [cpp_include(headers).split(/^/)] + prelude << ["typedef #{type} rbcv_typedef_;\n", + "extern rbcv_typedef_ *#{func};\n", + "static rbcv_typedef_ #{var};\n", + ] + type = "rbcv_typedef_" + fmt = member && !(typeof = have_typeof?) ? "seems %s" : "%s" + if typeof + var = "*rbcv_member_" + func = "rbcv_mem_func_(void)" + member = nil + type = "rbcv_mem_typedef_" + prelude[-1] << "typedef #{typeof}(#{val}) #{type};\n" + prelude[-1] << "extern #{type} *#{func};\n" + prelude[-1] << "static #{type} #{var};\n" + val = var + end def fmt.%(x) x ? super : "unknown" end checking_for checking_message(m, headers), fmt do - if scalar_ptr_type?(type, member, headers, &b) - if try_static_assert("sizeof(*#{name}) == 1", headers) - "string" + if scalar_ptr_type?(type, member, prelude, &b) + if try_static_assert("sizeof(*#{var}) == 1", prelude) + return "string" end - elsif scalar_type?(type, member, headers, &b) - if try_static_assert("sizeof(#{name}) > sizeof(long)", headers) - "long long" - elsif try_static_assert("sizeof(#{name}) > sizeof(int)", headers) - "long" - elsif try_static_assert("sizeof(#{name}) > sizeof(short)", headers) - "int" - elsif try_static_assert("sizeof(#{name}) > 1", headers) - "short" - else - "char" + ptr = "*" + elsif scalar_type?(type, member, prelude, &b) + unless member and !typeof or try_static_assert("(#{type})-1 < 0", prelude) + unsigned = "unsigned" end + ptr = "" + else + next end + type = UNIVERSAL_INTS.find do |t| + pre = prelude + unless member + pre += [["static #{unsigned} #{t} #{ptr}#{var};\n", + "extern #{unsigned} #{t} #{ptr}*#{func};\n"]] + end + try_static_assert("sizeof(#{ptr}#{val}) == sizeof(#{unsigned} #{t})", pre) + end + type or next + [unsigned, type, ptr].join(" ").strip end end @@ -1045,9 +1165,14 @@ # :stopdoc: -def arg_config(config, *defaults, &block) - $arg_config << [config, *defaults] - defaults << nil if !block and defaults.empty? +def arg_config(config, default=nil, &block) + $arg_config << [config, default] + defaults = [] + if default + defaults << default + elsif !block + defaults << nil + end $configure_args.fetch(config.tr('_', '-'), *defaults, &block) end @@ -1065,15 +1190,15 @@ # $defs.push("-DOSSL_DEBUG") unless $defs.include? "-DOSSL_DEBUG" # end # -def with_config(config, *defaults) +def with_config(config, default=nil) config = config.sub(/^--with[-_]/, '') val = arg_config("--with-"+config) do if arg_config("--without-"+config) false elsif block_given? - yield(config, *defaults) + yield(config, default) else - break *defaults + break default end end case val @@ -1098,15 +1223,15 @@ # $defs.push("-DOSSL_DEBUG") unless $defs.include? "-DOSSL_DEBUG" # end # -def enable_config(config, *defaults) +def enable_config(config, default=nil) if arg_config("--enable-"+config) true elsif arg_config("--disable-"+config) false elsif block_given? - yield(config, *defaults) + yield(config, default) else - return *defaults + return default end end @@ -1116,7 +1241,7 @@ # 'extconf.h'. # # For example: -# +# # # extconf.rb # require 'mkmf' # have_func('realpath') @@ -1151,7 +1276,7 @@ hdr << "#endif\n" hdr = hdr.join unless (IO.read(header) == hdr rescue false) - open(header, "w") do |hfile| + open(header, "wb") do |hfile| hfile.write(hdr) end end @@ -1182,11 +1307,11 @@ idirs = idir ? Array === idir ? idir : idir.split(File::PATH_SEPARATOR) : [] if defaults - idirs.concat(defaults.collect {|dir| dir + "/include"}) + idirs.concat(defaults.collect {|d| d + "/include"}) idir = ([idir] + idirs).compact.join(File::PATH_SEPARATOR) end unless idirs.empty? - idirs.collect! {|dir| "-I" + dir} + idirs.collect! {|d| "-I" + d} idirs -= Shellwords.shellwords($CPPFLAGS) unless idirs.empty? $CPPFLAGS = (idirs.quote << $CPPFLAGS).join(" ") @@ -1195,7 +1320,7 @@ ldirs = ldir ? Array === ldir ? ldir : ldir.split(File::PATH_SEPARATOR) : [] if defaults - ldirs.concat(defaults.collect {|dir| dir + "/lib"}) + ldirs.concat(defaults.collect {|d| d + "/lib"}) ldir = ([ldir] + ldirs).compact.join(File::PATH_SEPARATOR) end $LIBPATH = ldirs | $LIBPATH @@ -1211,7 +1336,7 @@ if pkgconfig = with_config("#{pkg}-config") and find_executable0(pkgconfig) # iff package specific config command is given get = proc {|opt| `#{pkgconfig} --#{opt}`.chomp} - elsif ($PKGCONFIG ||= + elsif ($PKGCONFIG ||= (pkgconfig = with_config("pkg-config", ("pkg-config" unless CROSS_COMPILING))) && find_executable0(pkgconfig) && pkgconfig) and system("#{$PKGCONFIG} --exists #{pkg}") @@ -1277,17 +1402,18 @@ def configuration(srcdir) mk = [] - vpath = %w[$(srcdir) $(topdir) $(hdrdir)] + vpath = $VPATH.dup if !CROSS_COMPILING case CONFIG['build_os'] when 'cygwin' if CONFIG['target_os'] != 'cygwin' - vpath.each {|p| p.sub!(/.*/, '$(shell cygpath -u \&)')} + vpath = vpath.map {|p| p.sub(/.*/, '$(shell cygpath -u \&)')} end when 'msdosdjgpp' CONFIG['PATH_SEPARATOR'] = ';' end end + CONFIG["hdrdir"] ||= $hdrdir mk << %{ SHELL = /bin/sh @@ -1295,11 +1421,12 @@ #{"top_srcdir = " + $top_srcdir.sub(%r"\A#{Regexp.quote($topdir)}/", "$(topdir)/") if $extmk} srcdir = #{srcdir.gsub(/\$\((srcdir)\)|\$\{(srcdir)\}/) {mkintpath(CONFIG[$1||$2])}.quote} topdir = #{mkintpath($extmk ? CONFIG["topdir"] : $topdir).quote} -hdrdir = #{$extmk ? mkintpath(CONFIG["hdrdir"]).quote : '$(topdir)'} +hdrdir = #{mkintpath(CONFIG["hdrdir"]).quote} +arch_hdrdir = #{$arch_hdrdir} VPATH = #{vpath.join(CONFIG['PATH_SEPARATOR'])} } if $extmk - mk << "RUBYLIB = -\nRUBYOPT = -rpurelib.rb\n" + mk << "RUBYLIB = -\nRUBYOPT = -r$(top_srcdir)/ext/purelib.rb\n" end if destdir = CONFIG["prefix"][$dest_prefix_pattern, 1] mk << "\nDESTDIR = #{destdir}\n" @@ -1310,7 +1437,8 @@ end CONFIG.each do |key, var| next if /^abs_/ =~ key - next unless /^(?:src|top|hdr|(.*))dir$/ =~ key and $1 + next if /^(?:src|top|hdr)dir$/ =~ key + next unless /dir$/ =~ key mk << "#{key} = #{with_destdir(var)}\n" end if !$extmk and !$configure_args.has_key?('--ruby') and @@ -1319,13 +1447,17 @@ else sep = "" end + possible_command = (proc {|s| s if /top_srcdir/ !~ s} unless $extmk) extconf_h = $extconf_h ? "-DRUBY_EXTCONF_H=\\\"$(RUBY_EXTCONF_H)\\\" " : $defs.join(" ") << " " mk << %{ CC = #{CONFIG['CC']} +CXX = #{CONFIG['CXX']} LIBRUBY = #{CONFIG['LIBRUBY']} LIBRUBY_A = #{CONFIG['LIBRUBY_A']} LIBRUBYARG_SHARED = #$LIBRUBYARG_SHARED LIBRUBYARG_STATIC = #$LIBRUBYARG_STATIC +OUTFLAG = #{OUTFLAG} +COUTFLAG = #{COUTFLAG} RUBY_EXTCONF_H = #{$extconf_h} cflags = #{CONFIG['cflags']} @@ -1342,26 +1474,30 @@ archflag = #{$ARCH_FLAG} DLDFLAGS = $(ldflags) $(dldflags) $(archflag) LDSHARED = #{CONFIG['LDSHARED']} +LDSHAREDXX = #{config_string('LDSHAREDXX') || '$(LDSHARED)'} AR = #{CONFIG['AR']} EXEEXT = #{CONFIG['EXEEXT']} +RUBY_BASE_NAME = #{CONFIG['RUBY_BASE_NAME']} RUBY_INSTALL_NAME = #{CONFIG['RUBY_INSTALL_NAME']} RUBY_SO_NAME = #{CONFIG['RUBY_SO_NAME']} arch = #{CONFIG['arch']} sitearch = #{CONFIG['sitearch']} -ruby_version = #{Config::CONFIG['ruby_version']} +ruby_version = #{RbConfig::CONFIG['ruby_version']} ruby = #{$ruby} RUBY = $(ruby#{sep}) -RM = #{config_string('RM') || '$(RUBY) -run -e rm -- -f'} -MAKEDIRS = #{config_string('MAKEDIRS') || '@$(RUBY) -run -e mkdir -- -p'} -INSTALL = #{config_string('INSTALL') || '@$(RUBY) -run -e install -- -vp'} +RM = #{config_string('RM', &possible_command) || '$(RUBY) -run -e rm -- -f'} +RM_RF = #{'$(RUBY) -run -e rm -- -rf'} +RMDIRS = #{config_string('RMDIRS', &possible_command) || '$(RUBY) -run -e rmdir -- -p'} +MAKEDIRS = #{config_string('MAKEDIRS', &possible_command) || '@$(RUBY) -run -e mkdir -- -p'} +INSTALL = #{config_string('INSTALL', &possible_command) || '@$(RUBY) -run -e install -- -vp'} INSTALL_PROG = #{config_string('INSTALL_PROG') || '$(INSTALL) -m 0755'} INSTALL_DATA = #{config_string('INSTALL_DATA') || '$(INSTALL) -m 0644'} -COPY = #{config_string('CP') || '@$(RUBY) -run -e cp -- -v'} +COPY = #{config_string('CP', &possible_command) || '@$(RUBY) -run -e cp -- -v'} #### End of system configuration section. #### -preload = #{$preload ? $preload.join(' ') : ''} +preload = #{defined?($preload) && $preload ? $preload.join(' ') : ''} } if $nmake == ?b mk.each do |x| @@ -1374,6 +1510,7 @@ end mk end +# :startdoc: def dummy_makefile(srcdir) configuration(srcdir) << <<RULES << CLEANINGS @@ -1386,8 +1523,63 @@ RULES end -# :startdoc: +def depend_rules(depend) + suffixes = [] + depout = [] + cont = implicit = nil + impconv = proc do + COMPILE_RULES.each {|rule| depout << (rule % implicit[0]) << implicit[1]} + implicit = nil + end + ruleconv = proc do |line| + if implicit + if /\A\t/ =~ line + implicit[1] << line + next + else + impconv[] + end + end + if m = /\A\.(\w+)\.(\w+)(?:\s*:)/.match(line) + suffixes << m[1] << m[2] + implicit = [[m[1], m[2]], [m.post_match]] + next + elsif RULE_SUBST and /\A(?!\s*\w+\s*=)[$\w][^#]*:/ =~ line + line.gsub!(%r"(\s)(?!\.)([^$(){}+=:\s\/\\,]+)(?=\s|\z)") {$1 + RULE_SUBST % $2} + end + depout << line + end + depend.each_line do |line| + line.gsub!(/\.o\b/, ".#{$OBJEXT}") + line.gsub!(/\$\((?:hdr|top)dir\)\/config.h/, $config_h) + # line.gsub!(%r"\$\(hdrdir\)/(?!ruby(?![^:;/\s]))(?=[-\w]+\.h)", '\&ruby/') + if $nmake && /\A\s*\$\(RM|COPY\)/ =~ line + line.gsub!(%r"[-\w\./]{2,}"){$&.tr("/", "\\")} + line.gsub!(/(\$\((?!RM|COPY)[^:)]+)(?=\))/, '\1:/=\\') + end + if /(?:^|[^\\])(?:\\\\)*\\$/ =~ line + (cont ||= []) << line + next + elsif cont + line = (cont << line).join + cont = nil + end + ruleconv.call(line) + end + if cont + ruleconv.call(cont.join) + elsif implicit + impconv.call + end + unless suffixes.empty? + depout.unshift(".SUFFIXES: ." + suffixes.uniq.join(" .") + "\n\n") + end + depout.unshift("$(OBJS): $(RUBY_EXTCONF_H)\n\n") if $extconf_h + depout.flatten! + depout +end + # Generates the Makefile for your extension, passing along any options and # preprocessor constants that you may have generated through other methods. # @@ -1412,7 +1604,7 @@ # Makefile. # # Setting the +target_prefix+ will, in turn, install the generated binary in -# a directory under your Config::CONFIG['sitearchdir'] that mimics your local +# a directory under your RbConfig::CONFIG['sitearchdir'] that mimics your local # filesystem when you run 'make install'. # # For example, given the following file tree: @@ -1460,21 +1652,24 @@ end srcprefix ||= '$(srcdir)' - Config::expand(srcdir = srcprefix.dup) + RbConfig::expand(srcdir = srcprefix.dup) ext = ".#{$OBJEXT}" if not $objs - srcs = $srcs ||= Dir[File.join(srcdir, "*.{#{SRC_EXT.join(%q{,})}}")] + srcs = $srcs || Dir[File.join(srcdir, "*.{#{SRC_EXT.join(%q{,})}}")] objs = srcs.inject(Hash.new {[]}) {|h, f| h[File.basename(f, ".*") << ext] <<= f; h} $objs = objs.keys - objs.delete_if {|b, f| f.size == 1} - unless objs.empty? - raise "source files duplication - #{objs.sort.map {|b, f| f.inspect}.join(", ")}" + unless objs.delete_if {|b, f| f.size == 1}.empty? + dups = objs.sort.map {|b, f| + "#{b[/.*\./]}{#{f.collect {|n| n[/([^.]+)\z/]}.join(',')}}" + } + abort "source files duplication - #{dups.join(", ")}" end else - $objs.collect! {|o| o.sub(/\.o\z/, ext)} unless $OBJEXT == "o" - srcs = $srcs ||= $objs.collect {|o| o.chomp(ext) << ".c"} + $objs.collect! {|o| File.basename(o, ".*") << ext} unless $OBJEXT == "o" + srcs = $srcs || $objs.collect {|o| o.chomp(ext) << ".c"} end + $srcs = srcs target = nil if $objs.empty? @@ -1482,25 +1677,34 @@ if File.exist?(File.join(srcdir, target + '.def')) deffile = "$(srcdir)/$(TARGET).def" unless EXPORT_PREFIX.empty? - makedef = %{-pe "sub!(/^(?=\\w)/,'#{EXPORT_PREFIX}') unless 1../^EXPORTS$/i"} + makedef = %{-pe "$_.sub!(/^(?=\\w)/,'#{EXPORT_PREFIX}') unless 1../^EXPORTS$/i"} end else makedef = %{-e "puts 'EXPORTS', '#{EXPORT_PREFIX}Init_$(TARGET)'"} end if makedef - $distcleanfiles << '$(DEFFILE)' + $cleanfiles << '$(DEFFILE)' origdef = deffile deffile = "$(TARGET)-$(arch).def" end end origdef ||= '' + if $extout and $INSTALLFILES + $cleanfiles.concat($INSTALLFILES.collect {|files, dir|File.join(dir, files.sub(/\A\.\//, ''))}) + $distcleandirs.concat($INSTALLFILES.collect {|files, dir| dir}) + end + + if false and $extmk and not $extconf_h + create_header + end + libpath = libpathflag(libpath) dllib = target ? "$(TARGET).#{CONFIG['DLEXT']}" : "" staticlib = target ? "$(TARGET).#$LIBEXT" : "" mfile = open("Makefile", "wb") - mfile.print configuration(srcprefix) + mfile.print(*configuration(srcprefix)) mfile.print " libpath = #{($DEFLIBPATH|$LIBPATH).join(" ")} LIBPATH = #{libpath} @@ -1508,6 +1712,7 @@ CLEANFILES = #{$cleanfiles.join(' ')} DISTCLEANFILES = #{$distcleanfiles.join(' ')} +DISTCLEANDIRS = #{$distcleandirs.join(' ')} extout = #{$extout && $extout.quote} extout_prefix = #{$extout_prefix} @@ -1521,13 +1726,14 @@ EXTSTATIC = #{$static || ""} STATIC_LIB = #{staticlib unless $static.nil?} #{!$extout && defined?($installed_list) ? "INSTALLED_LIST = #{$installed_list}\n" : ""} -" +" #" + # TODO: fixme install_dirs.each {|d| mfile.print("%-14s= %s\n" % d) if /^[[:upper:]]/ =~ d[0]} n = ($extout ? '$(RUBYARCHDIR)/' : '') + '$(TARGET)' mfile.print " TARGET_SO = #{($extout ? '$(RUBYARCHDIR)/' : '')}$(DLLIB) CLEANLIBS = #{n}.#{CONFIG['DLEXT']} #{config_string('cleanlibs') {|t| t.gsub(/\$\*/) {n}}} -CLEANOBJS = *.#{$OBJEXT} #{config_string('cleanobjs') {|t| t.gsub(/\$\*/, '$(TARGET)')}} *.bak +CLEANOBJS = *.#{$OBJEXT} #{config_string('cleanobjs') {|t| t.gsub(/\$\*/, "$(TARGET)#{deffile ? '-$(arch)': ''}")} if target} *.bak all: #{$extout ? "install" : target ? "$(DLLIB)" : "Makefile"} static: $(STATIC_LIB)#{$extout ? " install-rb" : ""} @@ -1535,6 +1741,18 @@ .PHONY: clean clean-so clean-rb " mfile.print CLEANINGS + fsep = config_string('BUILD_FILE_SEPARATOR') {|s| s unless s == "/"} + if fsep + sep = ":/=#{fsep}" + fseprepl = proc {|s| + s = s.gsub("/", fsep) + s = s.gsub(/(\$\(\w+)(\))/) {$1+sep+$2} + s = s.gsub(/(\$\{\w+)(\})/) {$1+sep+$2} + } + else + fseprepl = proc {|s| s} + sep = "" + end dirs = [] mfile.print "install: install-so install-rb\n\n" sodir = (dir = "$(RUBYARCHDIR)").dup @@ -1543,19 +1761,13 @@ f = "$(DLLIB)" dest = "#{dir}/#{f}" mfile.puts dir, "install-so: #{dest}" - unless $extout - mfile.print "#{dest}: #{f}\n" - if (sep = config_string('BUILD_FILE_SEPARATOR')) - f.gsub!("/", sep) - dir.gsub!("/", sep) - sep = ":/="+sep - f.gsub!(/(\$\(\w+)(\))/) {$1+sep+$2} - f.gsub!(/(\$\{\w+)(\})/) {$1+sep+$2} - dir.gsub!(/(\$\(\w+)(\))/) {$1+sep+$2} - dir.gsub!(/(\$\{\w+)(\})/) {$1+sep+$2} - end - mfile.print "\t@-$(MAKEDIRS) $(@D#{sep})\n" - mfile.print "\t$(INSTALL_PROG) #{f} $(@D#{sep})\n" + if $extout + mfile.print "clean-so::\n" + mfile.print "\t@-$(RM) #{fseprepl[dest]}\n" + mfile.print "\t@-$(RMDIRS) #{fseprepl[dir]}\n" + else + mfile.print "#{dest}: #{f}\n\t@-$(MAKEDIRS) $(@D#{sep})\n" + mfile.print "\t$(INSTALL_PROG) #{fseprepl[f]} $(@D#{sep})\n" if defined?($installed_list) mfile.print "\t@echo #{dir}/#{File.basename(f)}>>$(INSTALLED_LIST)\n" end @@ -1574,7 +1786,7 @@ dirs << dir mfile.print "pre-install-rb#{sfx}: #{dir}\n" end - files.each do |f| + for f in files dest = "#{dir}/#{File.basename(f)}" mfile.print("install-rb#{sfx}: #{dest}\n") mfile.print("#{dest}: #{f}\n\t@-$(MAKEDIRS) $(@D#{sep})\n") @@ -1582,11 +1794,24 @@ if defined?($installed_list) and !$extout mfile.print("\t@echo #{dest}>>$(INSTALLED_LIST)\n") end + if $extout + mfile.print("clean-rb#{sfx}::\n") + mfile.print("\t@-$(RM) #{fseprepl[dest]}\n") + end end end + if $extout + dirs.uniq! + unless dirs.empty? + mfile.print("clean-rb#{sfx}::\n") + for dir in dirs.sort_by {|d| -d.count('/')} + mfile.print("\t@-$(RMDIRS) #{fseprepl[dir]}\n") + end + end + end end dirs.unshift(sodir) if target and !dirs.include?(sodir) - dirs.each {|dir| mfile.print "#{dir}:\n\t$(MAKEDIRS) $@\n"} + dirs.each {|d| mfile.print "#{d}:\n\t$(MAKEDIRS) $@\n"} mfile.print <<-SITEINSTALL @@ -1598,19 +1823,19 @@ return unless target - mfile.puts SRC_EXT.collect {|ext| ".path.#{ext} = $(VPATH)"} if $nmake == ?b + mfile.puts SRC_EXT.collect {|e| ".path.#{e} = $(VPATH)"} if $nmake == ?b mfile.print ".SUFFIXES: .#{SRC_EXT.join(' .')} .#{$OBJEXT}\n" mfile.print "\n" - CXX_EXT.each do |ext| + CXX_EXT.each do |e| COMPILE_RULES.each do |rule| - mfile.printf(rule, ext, $OBJEXT) + mfile.printf(rule, e, $OBJEXT) mfile.printf("\n\t%s\n\n", COMPILE_CXX) end end - %w[c].each do |ext| + %w[c].each do |e| COMPILE_RULES.each do |rule| - mfile.printf(rule, ext, $OBJEXT) + mfile.printf(rule, e, $OBJEXT) mfile.printf("\n\t%s\n\n", COMPILE_C) end end @@ -1619,12 +1844,15 @@ mfile.print "$(DLLIB): " mfile.print "$(DEFFILE) " if makedef mfile.print "$(OBJS) Makefile\n" - mfile.print "\t@-$(RM) $@\n" + mfile.print "\t@-$(RM) $(@#{sep})\n" mfile.print "\t@-$(MAKEDIRS) $(@D)\n" if $extout link_so = LINK_SO.gsub(/^/, "\t") + if srcs.any?(&%r"\.(?:#{CXX_EXT.join('|')})\z".method(:===)) + link_so = link_so.sub(/\bLDSHARED\b/, '\&XX') + end mfile.print link_so, "\n\n" unless $static.nil? - mfile.print "$(STATIC_LIB): $(OBJS)\n\t" + mfile.print "$(STATIC_LIB): $(OBJS)\n\t@-$(RM) $(@#{sep})\n\t" mfile.print "$(AR) #{config_string('ARFLAGS') || 'cru '}$@ $(OBJS)" config_string('RANLIB') do |ranlib| mfile.print "\n\t@-#{ranlib} $(DLLIB) 2> /dev/null || true" @@ -1638,63 +1866,14 @@ depend = File.join(srcdir, "depend") if File.exist?(depend) - suffixes = [] - depout = [] - open(depend, "r") do |dfile| - mfile.printf "###\n" - cont = implicit = nil - impconv = proc do - COMPILE_RULES.each {|rule| depout << (rule % implicit[0]) << implicit[1]} - implicit = nil - end - ruleconv = proc do |line| - if implicit - if /\A\t/ =~ line - implicit[1] << line - next - else - impconv[] - end - end - if m = /\A\.(\w+)\.(\w+)(?:\s*:)/.match(line) - suffixes << m[1] << m[2] - implicit = [[m[1], m[2]], [m.post_match]] - next - elsif RULE_SUBST and /\A(?!\s*\w+\s*=)[$\w][^#]*:/ =~ line - line.gsub!(%r"(\s)(?!\.)([^$(){}+=:\s\/\\,]+)(?=\s|\z)") {$1 + RULE_SUBST % $2} - end - depout << line - end - while line = dfile.gets() - line.gsub!(/\.o\b/, ".#{$OBJEXT}") - line.gsub!(/\$\((?:hdr|top)dir\)\/config.h/, $config_h) if $config_h - if /(?:^|[^\\])(?:\\\\)*\\$/ =~ line - (cont ||= []) << line - next - elsif cont - line = (cont << line).join - cont = nil - end - ruleconv.call(line) - end - if cont - ruleconv.call(cont.join) - elsif implicit - impconv.call - end - end - unless suffixes.empty? - mfile.print ".SUFFIXES: .", suffixes.uniq.join(" ."), "\n\n" - end - mfile.print "$(OBJS): $(RUBY_EXTCONF_H)\n\n" if $extconf_h - mfile.print depout + mfile.print("###\n", *depend_rules(File.read(depend))) else headers = %w[ruby.h defines.h] if RULE_SUBST - headers.each {|h| h.sub!(/.*/) {|*m| RULE_SUBST % m}} + headers.each {|h| h.sub!(/.*/, &RULE_SUBST.method(:%))} end - headers << $config_h if $config_h - headers << "$(RUBY_EXTCONF_H)" if $extconf_h + headers << $config_h + headers << '$(RUBY_EXTCONF_H)' if $extconf_h mfile.print "$(OBJS): ", headers.join(' '), "\n" end @@ -1728,11 +1907,12 @@ $LIBPATH = [] $INSTALLFILES = [] $NONINSTALLFILES = [/~\z/, /\A#.*#\z/, /\A\.#/, /\.bak\z/i, /\.orig\z/, /\.rej\z/, /\.l[ao]\z/, /\.o\z/] + $VPATH = %w[$(srcdir) $(topdir) $(hdrdir)] $objs = nil $srcs = nil $libs = "" - if $enable_shared or Config.expand(config["LIBRUBY"].dup) != Config.expand(config["LIBRUBY_A"].dup) + if $enable_shared or RbConfig.expand(config["LIBRUBY"].dup) != RbConfig.expand(config["LIBRUBY_A"].dup) $LIBRUBYARG = config['LIBRUBYARG'] end @@ -1741,6 +1921,7 @@ $cleanfiles = config_string('CLEANFILES') {|s| Shellwords.shellwords(s)} || [] $cleanfiles << "mkmf.log" $distcleanfiles = config_string('DISTCLEANFILES') {|s| Shellwords.shellwords(s)} || [] + $distcleandirs = config_string('DISTCLEANDIRS') {|s| Shellwords.shellwords(s)} || [] $extout ||= nil $extout_prefix ||= nil @@ -1783,20 +1964,20 @@ $nmake = ?b if /Borland/i =~ `#{make} -h` end -Config::CONFIG["srcdir"] = CONFIG["srcdir"] = +RbConfig::CONFIG["srcdir"] = CONFIG["srcdir"] = $srcdir = arg_config("--srcdir", File.dirname($0)) $configure_args["--topsrcdir"] ||= $srcdir if $curdir = arg_config("--curdir") - Config.expand(curdir = $curdir.dup) + RbConfig.expand(curdir = $curdir.dup) else curdir = $curdir = "." end -unless File.expand_path(Config::CONFIG["topdir"]) == File.expand_path(curdir) +unless File.expand_path(RbConfig::CONFIG["topdir"]) == File.expand_path(curdir) CONFIG["topdir"] = $curdir - Config::CONFIG["topdir"] = curdir + RbConfig::CONFIG["topdir"] = curdir end $configure_args["--topdir"] ||= $curdir -$ruby = arg_config("--ruby", File.join(Config::CONFIG["bindir"], CONFIG["ruby_install_name"])) +$ruby = arg_config("--ruby", File.join(RbConfig::CONFIG["bindir"], CONFIG["ruby_install_name"])) split = Shellwords.method(:shellwords).to_proc @@ -1809,15 +1990,15 @@ end end config_string('COMMON_HEADERS') do |s| - Shellwords.shellwords(s).each {|s| hdr << "#include <#{s}>"} + Shellwords.shellwords(s).each {|w| hdr << "#include <#{w}>"} end COMMON_HEADERS = hdr.join("\n") COMMON_LIBS = config_string('COMMON_LIBS', &split) || [] COMPILE_RULES = config_string('COMPILE_RULES', &split) || %w[.%s.%s:] RULE_SUBST = config_string('RULE_SUBST') -COMPILE_C = config_string('COMPILE_C') || '$(CC) $(INCFLAGS) $(CPPFLAGS) $(CFLAGS) -c $<' -COMPILE_CXX = config_string('COMPILE_CXX') || '$(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) -c $<' +COMPILE_C = config_string('COMPILE_C') || '$(CC) $(INCFLAGS) $(CPPFLAGS) $(CFLAGS) $(COUTFLAG)$@ -c $<' +COMPILE_CXX = config_string('COMPILE_CXX') || '$(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -c $<' TRY_LINK = config_string('TRY_LINK') || "$(CC) #{OUTFLAG}conftest $(INCFLAGS) $(CPPFLAGS) " \ "$(CFLAGS) $(src) $(LIBPATH) $(LDFLAGS) $(ARCH_FLAG) $(LOCAL_LIBS) $(LIBS)" @@ -1832,15 +2013,24 @@ RPATHFLAG = config_string('RPATHFLAG') || '' LIBARG = config_string('LIBARG') || '-l%s' MAIN_DOES_NOTHING = config_string('MAIN_DOES_NOTHING') || 'int main() {return 0;}' +UNIVERSAL_INTS = config_string('UNIVERSAL_INTS') {|s| Shellwords.shellwords(s)} || + %w[int short long long\ long] -sep = config_string('BUILD_FILE_SEPARATOR') {|sep| ":/=#{sep}" if sep != "/"} || "" +sep = config_string('BUILD_FILE_SEPARATOR') {|s| ":/=#{s}" if s != "/"} || "" CLEANINGS = " -clean: -\t@-$(RM) $(CLEANLIBS#{sep}) $(CLEANOBJS#{sep}) $(CLEANFILES#{sep}) +clean-rb-default:: +clean-rb:: +clean-so:: +clean: clean-so clean-rb-default clean-rb +\t\t@-$(RM) $(CLEANLIBS#{sep}) $(CLEANOBJS#{sep}) $(CLEANFILES#{sep}) -distclean: clean -\t@-$(RM) Makefile $(RUBY_EXTCONF_H) conftest.* mkmf.log -\t@-$(RM) core ruby$(EXEEXT) *~ $(DISTCLEANFILES#{sep}) +distclean-rb-default:: +distclean-rb:: +distclean-so:: +distclean: clean distclean-so distclean-rb-default distclean-rb +\t\t@-$(RM) Makefile $(RUBY_EXTCONF_H) conftest.* mkmf.log +\t\t@-$(RM) core ruby$(EXEEXT) *~ $(DISTCLEANFILES#{sep}) +\t\t@-$(RMDIRS) $(DISTCLEANDIRS#{sep}) realclean: distclean " -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/