summaryrefslogtreecommitdiff
path: root/lib/mkmf.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/mkmf.rb')
-rw-r--r--lib/mkmf.rb1018
1 files changed, 734 insertions, 284 deletions
diff --git a/lib/mkmf.rb b/lib/mkmf.rb
index 2d44b123d2..37ee4a70d9 100644
--- a/lib/mkmf.rb
+++ b/lib/mkmf.rb
@@ -1,4 +1,5 @@
# -*- coding: us-ascii -*-
+# frozen-string-literal: false
# module to create Makefile for extension modules
# invoke like: ruby -r mkmf extconf.rb
@@ -6,8 +7,7 @@ require 'rbconfig'
require 'fileutils'
require 'shellwords'
-# :stopdoc:
-class String
+class String # :nodoc:
# Wraps a string in escaped quotes if it contains whitespace.
def quote
/\s/ =~ self ? "\"#{self}\"" : "#{self}"
@@ -32,19 +32,35 @@ class String
end
end
-class Array
+class Array # :nodoc:
# Wraps all strings in escaped quotes if they contain whitespace.
def quote
map {|s| s.quote}
end
end
-# :startdoc:
##
-# mkmf.rb is used by Ruby C extensions to generate a Makefile which will
+# \Module \MakeMakefile is used by Ruby C extensions to generate a Makefile which will
# correctly compile and link the C extension to Ruby and a third-party
# library.
module MakeMakefile
+
+ target_rbconfig = nil
+ ARGV.delete_if do |arg|
+ opt = arg.delete_prefix("--target-rbconfig=")
+ unless opt == arg
+ target_rbconfig = opt
+ end
+ end
+ if target_rbconfig
+ # Load the RbConfig for the target platform into this module.
+ # Cross-compiling needs the same version of Ruby.
+ Kernel.load target_rbconfig, self
+ else
+ # The RbConfig for the target platform where the built extension runs.
+ RbConfig = ::RbConfig
+ end
+
#### defer until this module become global-state free.
# def self.extended(obj)
# obj.init_mkmf
@@ -60,6 +76,9 @@ module MakeMakefile
# The makefile configuration using the defaults from when Ruby was built.
CONFIG = RbConfig::MAKEFILE_CONFIG
+
+ ##
+ # The saved original value of +LIB+ environment variable
ORIG_LIBPATH = ENV['LIB']
##
@@ -68,10 +87,10 @@ module MakeMakefile
C_EXT = %w[c m]
##
- # Extensions for files complied with a C++ compiler
+ # Extensions for files compiled with a C++ compiler
CXX_EXT = %w[cc mm cxx cpp]
- if File::FNM_SYSCASE.zero?
+ unless File.exist?(File.join(*File.split(__FILE__).tap {|d, b| b.swapcase}))
CXX_EXT.concat(%w[C])
end
@@ -90,26 +109,16 @@ module MakeMakefile
unless defined? $configure_args
$configure_args = {}
- args = CONFIG["configure_args"]
- if ENV["CONFIGURE_ARGS"]
- args << " " << ENV["CONFIGURE_ARGS"]
+ args = CONFIG["configure_args"].shellsplit
+ if arg = ENV["CONFIGURE_ARGS"]
+ args.push(*arg.shellsplit)
end
- for arg in Shellwords::shellwords(args)
+ args.delete_if {|a| /\A--(?:top(?:src)?|src|cur)dir(?=\z|=)/ =~ a}
+ for arg in args.concat(ARGV)
arg, val = arg.split('=', 2)
next unless arg
arg.tr!('_', '-')
- if arg.sub!(/^(?!--)/, '--')
- val or next
- arg.downcase!
- end
- next if /^--(?:top|topsrc|src|cur)dir$/ =~ arg
- $configure_args[arg] = val || true
- end
- for arg in ARGV
- arg, val = arg.split('=', 2)
- next unless arg
- arg.tr!('_', '-')
- if arg.sub!(/^(?!--)/, '--')
+ if arg.sub!(/\A(?!--)/, '--')
val or next
arg.downcase!
end
@@ -128,12 +137,9 @@ module MakeMakefile
$vendorarchdir = CONFIG["vendorarchdir"]
$mswin = /mswin/ =~ RUBY_PLATFORM
- $bccwin = /bccwin/ =~ RUBY_PLATFORM
$mingw = /mingw/ =~ RUBY_PLATFORM
$cygwin = /cygwin/ =~ RUBY_PLATFORM
$netbsd = /netbsd/ =~ RUBY_PLATFORM
- $os2 = /os2/ =~ RUBY_PLATFORM
- $beos = /beos/ =~ RUBY_PLATFORM
$haiku = /haiku/ =~ RUBY_PLATFORM
$solaris = /solaris/ =~ RUBY_PLATFORM
$universal = /universal/ =~ RUBY_PLATFORM
@@ -177,7 +183,7 @@ module MakeMakefile
]
def install_dirs(target_prefix = nil)
- if $extout
+ if $extout and $extmk
dirs = [
['BINDIR', '$(extout)/bin'],
['RUBYCOMMONDIR', '$(extout)/common'],
@@ -203,8 +209,8 @@ module MakeMakefile
['RUBYCOMMONDIR', '$(vendordir)$(target_prefix)'],
['RUBYLIBDIR', '$(vendorlibdir)$(target_prefix)'],
['RUBYARCHDIR', '$(vendorarchdir)$(target_prefix)'],
- ['HDRDIR', '$(rubyhdrdir)/ruby$(target_prefix)'],
- ['ARCHHDRDIR', '$(rubyhdrdir)/$(arch)/ruby$(target_prefix)'],
+ ['HDRDIR', '$(vendorhdrdir)$(target_prefix)'],
+ ['ARCHHDRDIR', '$(vendorarchhdrdir)$(target_prefix)'],
]
else
dirs = [
@@ -212,8 +218,8 @@ module MakeMakefile
['RUBYCOMMONDIR', '$(sitedir)$(target_prefix)'],
['RUBYLIBDIR', '$(sitelibdir)$(target_prefix)'],
['RUBYARCHDIR', '$(sitearchdir)$(target_prefix)'],
- ['HDRDIR', '$(rubyhdrdir)/ruby$(target_prefix)'],
- ['ARCHHDRDIR', '$(rubyhdrdir)/$(arch)/ruby$(target_prefix)'],
+ ['HDRDIR', '$(sitehdrdir)$(target_prefix)'],
+ ['ARCHHDRDIR', '$(sitearchhdrdir)$(target_prefix)'],
]
end
dirs << ['target_prefix', (target_prefix ? "/#{target_prefix}" : "")]
@@ -243,7 +249,12 @@ module MakeMakefile
$topdir ||= RbConfig::CONFIG["topdir"]
$arch_hdrdir = "$(extout)/include/$(arch)"
else
- abort "mkmf.rb can't find header files for ruby at #{$hdrdir}/ruby.h"
+ abort <<MESSAGE
+mkmf.rb can't find header files for ruby at #{$hdrdir}/ruby.h
+
+You might have to install separate package for the ruby development
+environment, ruby-dev or ruby-devel for example.
+MESSAGE
end
CONFTEST = "conftest".freeze
@@ -251,14 +262,19 @@ module MakeMakefile
OUTFLAG = CONFIG['OUTFLAG']
COUTFLAG = CONFIG['COUTFLAG']
+ CSRCFLAG = CONFIG['CSRCFLAG']
CPPOUTFILE = config_string('CPPOUTFILE') {|str| str.sub(/\bconftest\b/, CONFTEST)}
+ # :startdoc:
+
+ # Removes _files_.
def rm_f(*files)
opt = (Hash === files.last ? [files.pop] : [])
FileUtils.rm_f(Dir[*files.flatten], *opt)
end
module_function :rm_f
+ # Removes _files_ recursively.
def rm_rf(*files)
opt = (Hash === files.last ? [files.pop] : [])
FileUtils.rm_rf(Dir[*files.flatten], *opt)
@@ -273,8 +289,11 @@ module MakeMakefile
t if times.all? {|n| n <= t}
end
+ # :stopdoc:
+
def split_libs(*strs)
- strs.map {|s| s.split(/\s+(?=-|\z)/)}.flatten
+ sep = $mswin ? /\s+/ : /\s+(?=-|\z)/
+ strs.flat_map {|s| s.lstrip.split(sep)}
end
def merge_libs(*libs)
@@ -375,40 +394,82 @@ module MakeMakefile
end
end
- def xsystem command, opts = nil
+ def expand_command(commands, envs = libpath_env)
varpat = /\$\((\w+)\)|\$\{(\w+)\}/
- if varpat =~ command
- vars = Hash.new {|h, k| h[k] = ENV[k]}
- command = command.dup
- nil while command.gsub!(varpat) {vars[$1||$2]}
+ vars = nil
+ expand = proc do |command|
+ case command
+ when Array
+ command.map(&expand)
+ when String
+ if varpat =~ command
+ vars ||= Hash.new {|h, k| h[k] = ENV[k]}
+ command = command.dup
+ nil while command.gsub!(varpat) {vars[$1||$2]}
+ end
+ command
+ else
+ command
+ end
end
+ if Array === commands
+ env, *commands = commands if Hash === commands.first
+ envs.merge!(env) if env
+ end
+
+ # disable ASAN leak reporting - conftest programs almost always don't bother
+ # to free their memory.
+ envs['LSAN_OPTIONS'] = "detect_leaks=0" unless ENV.key?('LSAN_OPTIONS')
+
+ return envs, expand[commands]
+ end
+
+ def env_quote(envs)
+ envs.map {|e, v| "#{e}=#{v.quote}"}
+ end
+
+ # :startdoc:
+
+ # call-seq:
+ # xsystem(command, werror: false) -> true or false
+ #
+ # Executes _command_ with expanding variables, and returns the exit
+ # status like as Kernel#system. If _werror_ is true and the error
+ # output is not empty, returns +false+. The output will logged.
+ def xsystem(command, werror: false)
+ env, command = expand_command(command)
Logging::open do
- puts command.quote
- if opts and opts[:werror]
+ puts [env_quote(env), command.quote].join(' ')
+ if werror
result = nil
Logging.postpone do |log|
- result = (system(libpath_env, command) and File.zero?(log.path))
- ""
+ output = IO.popen(env, command, &:read)
+ result = ($?.success? and File.zero?(log.path))
+ output
end
result
else
- system(libpath_env, command)
+ system(env, *command)
end
end
end
+ # Executes _command_ similarly to xsystem, but yields opened pipe.
def xpopen command, *mode, &block
+ env, commands = expand_command(command)
+ command = [env_quote(env), command].join(' ')
Logging::open do
case mode[0]
- when nil, /^r/
+ when nil, Hash, /^r/
puts "#{command} |"
else
puts "| #{command}"
end
- IO.popen(libpath_env, command, *mode, &block)
+ IO.popen(env, commands, *mode, &block)
end
end
+ # Logs _src_
def log_src(src, heading="checked program was")
src = src.split(/^/)
fmt = "%#{src.size.to_s.size}d: %s"
@@ -423,6 +484,15 @@ EOM
EOM
end
+ # Returns the language-dependent source file name for configuration
+ # checks.
+ def conftest_source
+ CONFTEST_C
+ end
+
+ # Creats temporary source file from +COMMON_HEADERS+ and _src_.
+ # Yields the created source string and uses the returned string as
+ # the source code, if the block is given.
def create_tmpsrc(src)
src = "#{COMMON_HEADERS}\n#{src}"
src = yield(src) if block_given?
@@ -431,7 +501,7 @@ EOM
src.sub!(/[^\n]\z/, "\\&\n")
count = 0
begin
- open(CONFTEST_C, "wb") do |cfile|
+ File.open(conftest_source, "wb") do |cfile|
cfile.print src
end
rescue Errno::EACCES
@@ -443,6 +513,8 @@ EOM
src
end
+ # :stopdoc:
+
def have_devel?
unless defined? $have_devel
$have_devel = true
@@ -451,7 +523,7 @@ EOM
$have_devel
end
- def try_do(src, command, *opts, &b)
+ def try_do(src, command, **opts, &b)
unless have_devel?
raise <<MSG
The compiler failed to generate an executable file.
@@ -460,17 +532,16 @@ MSG
end
begin
src = create_tmpsrc(src, &b)
- xsystem(command, *opts)
+ xsystem(command, **opts)
ensure
log_src(src)
- MakeMakefile.rm_rf "#{CONFTEST}.dSYM"
end
end
- def link_command(ldflags, opt="", libpath=$DEFLIBPATH|$LIBPATH)
+ def link_config(ldflags, opt="", libpath=$DEFLIBPATH|$LIBPATH)
librubyarg = $extmk ? $LIBRUBYARG_STATIC : "$(LIBRUBYARG)"
conf = RbConfig::CONFIG.merge('hdrdir' => $hdrdir.quote,
- 'src' => "#{CONFTEST_C}",
+ 'src' => "#{conftest_source}",
'arch_hdrdir' => $arch_hdrdir.quote,
'top_srcdir' => $top_srcdir.quote,
'INCFLAGS' => "#$INCFLAGS",
@@ -481,94 +552,112 @@ MSG
'LOCAL_LIBS' => "#$LOCAL_LIBS #$libs",
'LIBS' => "#{librubyarg} #{opt} #$LIBS")
conf['LIBPATH'] = libpathflag(libpath.map {|s| RbConfig::expand(s.dup, conf)})
+ conf
+ end
+
+ def link_command(ldflags, *opts)
+ conf = link_config(ldflags, *opts)
RbConfig::expand(TRY_LINK.dup, conf)
end
- def cc_command(opt="")
+ def cc_config(opt="")
conf = RbConfig::CONFIG.merge('hdrdir' => $hdrdir.quote, 'srcdir' => $srcdir.quote,
'arch_hdrdir' => $arch_hdrdir.quote,
'top_srcdir' => $top_srcdir.quote)
+ conf
+ end
+
+ def cc_command(opt="")
+ conf = cc_config(opt)
RbConfig::expand("$(CC) #$INCFLAGS #$CPPFLAGS #$CFLAGS #$ARCH_FLAG #{opt} -c #{CONFTEST_C}",
conf)
end
- def cpp_command(outfile, opt="")
- conf = RbConfig::CONFIG.merge('hdrdir' => $hdrdir.quote, 'srcdir' => $srcdir.quote,
- 'arch_hdrdir' => $arch_hdrdir.quote,
- 'top_srcdir' => $top_srcdir.quote)
+ def cpp_config(opt)
+ conf = cc_config(opt)
if $universal and (arch_flag = conf['ARCH_FLAG']) and !arch_flag.empty?
conf['ARCH_FLAG'] = arch_flag.gsub(/(?:\G|\s)-arch\s+\S+/, '')
end
+ conf
+ end
+
+ def cpp_command(outfile, opt="")
+ conf = cpp_config(opt)
RbConfig::expand("$(CPP) #$INCFLAGS #$CPPFLAGS #$CFLAGS #{opt} #{CONFTEST_C} #{outfile}",
conf)
end
def libpathflag(libpath=$DEFLIBPATH|$LIBPATH)
+ libpathflags = nil
libpath.map{|x|
case x
when "$(topdir)", /\A\./
LIBPATHFLAG
else
- LIBPATHFLAG+RPATHFLAG
+ libpathflags ||= [LIBPATHFLAG, RPATHFLAG].grep(/\S/).join(" ")
end % x.quote
- }.join
+ }.join(" ")
+ end
+
+ def werror_flag(opt = nil)
+ config_string("WERRORFLAG") {|flag| opt = opt && !opt.empty? ? "#{opt} #{flag}" : flag}
+ opt
end
def with_werror(opt, opts = nil)
- if opts
- if opts[:werror] and config_string("WERRORFLAG") {|flag| opt = opt ? "#{opt} #{flag}" : flag}
- (opts = opts.dup).delete(:werror)
- end
- yield(opt, opts)
- else
- yield(opt)
- end
+ opt = werror_flag(opt) if opts and (opts = opts.dup).delete(:werror)
+ yield(opt, opts)
end
- def try_link0(src, opt="", *opts, &b) # :nodoc:
- cmd = link_command("", opt)
+ def try_link0(src, opt = "", ldflags: "", **opts, &b) # :nodoc:
+ exe = CONFTEST+$EXEEXT
+ cmd = link_command(ldflags, opt)
if $universal
require 'tmpdir'
Dir.mktmpdir("mkmf_", oldtmpdir = ENV["TMPDIR"]) do |tmpdir|
begin
ENV["TMPDIR"] = tmpdir
- try_do(src, cmd, *opts, &b)
+ try_do(src, cmd, **opts, &b)
ensure
ENV["TMPDIR"] = oldtmpdir
end
end
else
- try_do(src, cmd, *opts, &b)
- end and File.executable?(CONFTEST+$EXEEXT)
+ try_do(src, cmd, **opts, &b)
+ end and File.executable?(exe) or return nil
+ exe
+ ensure
+ MakeMakefile.rm_rf(*Dir["#{CONFTEST}*"]-[exe])
end
# Returns whether or not the +src+ can be compiled as a C source and linked
# with its depending libraries successfully. +opt+ is passed to the linker
- # as options. Note that +$CFLAGS+ and +$LDFLAGS+ are also passed to the
- # linker.
+ # as options. Note that <tt>$CFLAGS</tt> and <tt>$LDFLAGS</tt> are also
+ # passed to the linker.
#
# If a block given, it is called with the source before compilation. You can
# modify the source in the block.
#
# [+src+] a String which contains a C source
# [+opt+] a String which contains linker options
- def try_link(src, opt="", *opts, &b)
- try_link0(src, opt, *opts, &b)
- ensure
- MakeMakefile.rm_f "#{CONFTEST}*", "c0x32*"
+ def try_link(src, opt = "", **opts, &b)
+ exe = try_link0(src, opt, **opts, &b) or return false
+ MakeMakefile.rm_f exe
+ true
end
# Returns whether or not the +src+ can be compiled as a C source. +opt+ is
- # passed to the C compiler as options. Note that +$CFLAGS+ is also passed to
- # the compiler.
+ # passed to the C compiler as options. Note that <tt>$CFLAGS</tt> is also
+ # passed to the compiler.
#
# If a block given, it is called with the source before compilation. You can
# modify the source in the block.
#
# [+src+] a String which contains a C source
# [+opt+] a String which contains compiler options
- def try_compile(src, opt="", *opts, &b)
- with_werror(opt, *opts) {|_opt, *_opts| try_do(src, cc_command(_opt), *_opts, &b)} and
+ def try_compile(src, opt = "", werror: nil, **opts, &b)
+ opt = werror_flag(opt) if werror
+ try_do(src, cc_command(opt), werror: werror, **opts, &b) and
File.file?("#{CONFTEST}.#{$OBJEXT}")
ensure
MakeMakefile.rm_f "#{CONFTEST}*"
@@ -576,21 +665,21 @@ MSG
# Returns whether or not the +src+ can be preprocessed with the C
# preprocessor. +opt+ is passed to the preprocessor as options. Note that
- # +$CFLAGS+ is also passed to the preprocessor.
+ # <tt>$CFLAGS</tt> is also passed to the preprocessor.
#
# If a block given, it is called with the source before preprocessing. You
# can modify the source in the block.
#
# [+src+] a String which contains a C source
# [+opt+] a String which contains preprocessor options
- def try_cpp(src, opt="", *opts, &b)
- try_do(src, cpp_command(CPPOUTFILE, opt), *opts, &b) and
+ def try_cpp(src, opt = "", **opts, &b)
+ try_do(src, cpp_command(CPPOUTFILE, opt), **opts, &b) and
File.file?("#{CONFTEST}.i")
ensure
MakeMakefile.rm_f "#{CONFTEST}*"
end
- alias_method :try_header, (config_string('try_header') || :try_cpp)
+ alias try_header try_compile
def cpp_include(header)
if header
@@ -601,48 +690,93 @@ MSG
end
end
+ # :startdoc:
+
+ # Sets <tt>$CPPFLAGS</tt> to _flags_ and yields. If the block returns a
+ # falsy value, <tt>$CPPFLAGS</tt> is reset to its previous value, remains
+ # set to _flags_ otherwise.
+ #
+ # [+flags+] a C preprocessor flag as a +String+
+ #
def with_cppflags(flags)
cppflags = $CPPFLAGS
- $CPPFLAGS = flags
+ $CPPFLAGS = flags.dup
ret = yield
ensure
$CPPFLAGS = cppflags unless ret
end
- def try_cppflags(flags)
- with_cppflags(flags) do
- try_header("int main() {return 0;}")
+ # :nodoc:
+ def try_cppflags(flags, werror: true, **opts)
+ try_header(MAIN_DOES_NOTHING, flags, werror: werror, **opts)
+ end
+
+ # Check whether each given C preprocessor flag is acceptable and append it
+ # to <tt>$CPPFLAGS</tt> if so.
+ #
+ # [+flags+] a C preprocessor flag as a +String+ or an +Array+ of them
+ #
+ def append_cppflags(flags, **opts)
+ Array(flags).each do |flag|
+ if checking_for("whether #{flag} is accepted as CPPFLAGS") {
+ try_cppflags(flag, **opts)
+ }
+ $CPPFLAGS << " " << flag
+ end
end
end
+ # Sets <tt>$CFLAGS</tt> to _flags_ and yields. If the block returns a falsy
+ # value, <tt>$CFLAGS</tt> is reset to its previous value, remains set to
+ # _flags_ otherwise.
def with_cflags(flags)
cflags = $CFLAGS
- $CFLAGS = flags
+ $CFLAGS = flags.dup
ret = yield
ensure
$CFLAGS = cflags unless ret
end
- def try_cflags(flags)
- with_cflags(flags) do
- try_compile("int main() {return 0;}")
- end
+ # :nodoc:
+ def try_cflags(flags, werror: true, **opts)
+ try_compile(MAIN_DOES_NOTHING, flags, werror: werror, **opts)
end
+ # Sets <tt>$LDFLAGS</tt> to _flags_ and yields. If the block returns a
+ # falsy value, <tt>$LDFLAGS</tt> is reset to its previous value, remains set
+ # to _flags_ otherwise.
def with_ldflags(flags)
ldflags = $LDFLAGS
- $LDFLAGS = flags
+ $LDFLAGS = flags.dup
ret = yield
ensure
$LDFLAGS = ldflags unless ret
end
- def try_ldflags(flags)
- with_ldflags(flags) do
- try_link("int main() {return 0;}")
+ # :nodoc:
+ def try_ldflags(flags, werror: $mswin, **opts)
+ try_link(MAIN_DOES_NOTHING, "", ldflags: flags, werror: werror, **opts)
+ end
+
+ # :startdoc:
+
+ # Check whether each given linker flag is acceptable and append it to
+ # <tt>$LDFLAGS</tt> if so.
+ #
+ # [+flags+] a linker flag as a +String+ or an +Array+ of them
+ #
+ def append_ldflags(flags, **opts)
+ Array(flags).each do |flag|
+ if checking_for("whether #{flag} is accepted as LDFLAGS") {
+ try_ldflags(flag, **opts)
+ }
+ $LDFLAGS << " " << flag
+ end
end
end
+ # :stopdoc:
+
def try_static_assert(expr, headers = nil, opt = "", &b)
headers = cpp_include(headers)
try_compile(<<SRC, opt, &b)
@@ -667,7 +801,6 @@ SRC
return nil
end
upper = 1
- lower = 0
until try_static_assert("#{const} <= #{upper}", headers, opt)
lower = upper
upper <<= 1
@@ -706,7 +839,7 @@ int main() {printf("%"PRI_CONFTEST_PREFIX"#{neg ? 'd' : 'u'}\\n", conftest_const
end
end
ensure
- MakeMakefile.rm_f "#{CONFTEST}*"
+ MakeMakefile.rm_f "#{CONFTEST}#{$EXEEXT}"
end
end
nil
@@ -720,11 +853,22 @@ int main() {printf("%"PRI_CONFTEST_PREFIX"#{neg ? 'd' : 'u'}\\n", conftest_const
# files.
def try_func(func, libs, headers = nil, opt = "", &b)
headers = cpp_include(headers)
+ prepare = String.new
case func
when /^&/
decltype = proc {|x|"const volatile void *#{x}"}
when /\)$/
- call = func
+ strvars = []
+ call = func.gsub(/""/) {
+ v = "s#{strvars.size + 1}"
+ strvars << v
+ v
+ }
+ unless strvars.empty?
+ prepare << "char " << strvars.map {|v| %[#{v}[1024] = ""]}.join(", ") << "; "
+ end
+ when nil
+ call = ""
else
call = "#{func}()"
decltype = proc {|x| "void ((*#{x})())"}
@@ -732,7 +876,7 @@ int main() {printf("%"PRI_CONFTEST_PREFIX"#{neg ? 'd' : 'u'}\\n", conftest_const
if opt and !opt.empty?
[[:to_str], [:join, " "], [:to_s]].each do |meth, *args|
if opt.respond_to?(meth)
- break opt = opt.send(meth, *args)
+ break opt = opt.__send__(meth, *args)
end
end
opt = "#{opt} #{libs}"
@@ -744,14 +888,15 @@ int main() {printf("%"PRI_CONFTEST_PREFIX"#{neg ? 'd' : 'u'}\\n", conftest_const
/*top*/
extern int t(void);
#{MAIN_DOES_NOTHING 't'}
-int t(void) { #{decltype["volatile p"]}; p = (#{decltype[]})#{func}; return 0; }
+int t(void) { #{decltype["volatile p"]}; p = (#{decltype[]})#{func}; return !p; }
SRC
call && try_link(<<"SRC", opt, &b)
#{headers}
/*top*/
extern int t(void);
#{MAIN_DOES_NOTHING 't'}
-int t(void) { #{call}; return 0; }
+#{"extern void #{call};" if decltype}
+int t(void) { #{prepare}#{call}; return 0; }
SRC
end
@@ -763,10 +908,12 @@ SRC
/*top*/
extern int t(void);
#{MAIN_DOES_NOTHING 't'}
-int t(void) { const volatile void *volatile p; p = &(&#{var})[0]; return 0; }
+int t(void) { const volatile void *volatile p; p = &(&#{var})[0]; return !p; }
SRC
end
+ # :startdoc:
+
# Returns whether or not the +src+ can be preprocessed with the C
# preprocessor and matches with +pat+.
#
@@ -784,20 +931,12 @@ SRC
xpopen(cpp_command('', opt)) do |f|
if Regexp === pat
puts(" ruby -ne 'print if #{pat.inspect}'")
- f.grep(pat) {|l|
+ !f.grep(pat) {|l|
puts "#{f.lineno}: #{l}"
- return true
- }
- false
+ }.empty?
else
puts(" egrep '#{pat}'")
- begin
- stdin = $stdin.dup
- $stdin.reopen(f)
- system("egrep", pat)
- ensure
- $stdin.reopen(stdin)
- end
+ system("egrep", pat, in: f)
end
end
ensure
@@ -805,6 +944,8 @@ SRC
log_src(src)
end
+ # :stopdoc:
+
# This is used internally by the have_macro? method.
def macro_defined?(macro, src, opt = "", &b)
src = src.sub(/[^\n]\z/, "\\&\n")
@@ -824,8 +965,8 @@ SRC
# * the linked file can be invoked as an executable
# * and the executable exits successfully
#
- # +opt+ is passed to the linker as options. Note that +$CFLAGS+ and
- # +$LDFLAGS+ are also passed to the linker.
+ # +opt+ is passed to the linker as options. Note that <tt>$CFLAGS</tt> and
+ # <tt>$LDFLAGS</tt> are also passed to the linker.
#
# If a block given, it is called with the source before compilation. You can
# modify the source in the block.
@@ -897,6 +1038,10 @@ SRC
format(LIBARG, lib) + " " + libs
end
+ # Prints messages to $stdout, if verbose mode.
+ #
+ # Internal use only.
+ #
def message(*s)
unless Logging.quiet and not $VERBOSE
printf(*s)
@@ -910,29 +1055,40 @@ SRC
# Internal use only.
#
def checking_for(m, fmt = nil)
- f = caller[0][/in `([^<].*)'$/, 1] and f << ": " #` for vim #'
+ if f = caller_locations(1, 1).first.base_label and /\A\w/ =~ f
+ f += ": "
+ else
+ f = ""
+ end
m = "checking #{/\Acheck/ =~ f ? '' : 'for '}#{m}... "
message "%s", m
a = r = nil
Logging::postpone do
r = yield
- a = (fmt ? "#{fmt % r}" : r ? "yes" : "no") << "\n"
- "#{f}#{m}-------------------- #{a}\n"
+ a = (fmt ? "#{fmt % r}" : r ? "yes" : "no")
+ "#{f}#{m}-------------------- #{a}\n\n"
end
- message(a)
+ message "%s\n", a
Logging::message "--------------------\n\n"
r
end
+ # Build a message for checking.
+ #
+ # Internal use only.
+ #
def checking_message(target, place = nil, opt = nil)
[["in", place], ["with", opt]].inject("#{target}") do |msg, (pre, noun)|
if noun
[[:to_str], [:join, ","], [:to_s]].each do |meth, *args|
if noun.respond_to?(meth)
- break noun = noun.send(meth, *args)
+ break noun = noun.__send__(meth, *args)
end
end
- msg << " #{pre} #{noun}" unless noun.empty?
+ unless noun.empty?
+ msg << " #{pre} " unless msg.empty?
+ msg << noun
+ end
end
msg
end
@@ -940,6 +1096,21 @@ SRC
# :startdoc:
+ # Check whether each given C compiler flag is acceptable and append it
+ # to <tt>$CFLAGS</tt> if so.
+ #
+ # [+flags+] a C compiler flag as a +String+ or an +Array+ of them
+ #
+ def append_cflags(flags, **opts)
+ Array(flags).each do |flag|
+ if checking_for("whether #{flag} is accepted as CFLAGS") {
+ try_cflags(flag, **opts)
+ }
+ $CFLAGS << " " << flag
+ end
+ end
+ end
+
# Returns whether or not +macro+ is defined either in the common header
# files or within any +headers+ you provide.
#
@@ -963,9 +1134,9 @@ SRC
# <code>--with-FOOlib</code> configuration option.
#
def have_library(lib, func = nil, headers = nil, opt = "", &b)
- func = "main" if !func or func.empty?
+ dir_config(lib)
lib = with_config(lib+'lib', lib)
- checking_for checking_message(func.funcall_style, LIBARG%lib, opt) do
+ checking_for checking_message(func && func.funcall_style, LIBARG%lib, opt) do
if COMMON_LIBS.include?(lib)
true
else
@@ -989,10 +1160,10 @@ SRC
# library paths searched and linked against.
#
def find_library(lib, func, *paths, &b)
- func = "main" if !func or func.empty?
+ dir_config(lib)
lib = with_config(lib+'lib', lib)
- paths = paths.collect {|path| path.split(File::PATH_SEPARATOR)}.flatten
- checking_for checking_message(func.funcall_style, LIBARG%lib) do
+ paths = paths.flat_map {|path| path.split(File::PATH_SEPARATOR)}
+ checking_for checking_message(func && func.funcall_style, LIBARG%lib) do
libpath = $LIBPATH
libs = append_library($libs, lib)
begin
@@ -1063,6 +1234,7 @@ SRC
# +HAVE_FOO_H+ preprocessor macro would be passed to the compiler.
#
def have_header(header, preheaders = nil, opt = "", &b)
+ dir_config(header[/.*?(?=\/)|.*?(?=\.)/])
checking_for header do
if try_header(cpp_include(preheaders)+cpp_include(header), opt, &b)
$defs.push(format("-DHAVE_%s", header.tr_cpp))
@@ -1093,11 +1265,11 @@ SRC
checking_for fw do
src = cpp_include("#{fw}/#{header}") << "\n" "int main(void){return 0;}"
opt = " -framework #{fw}"
- if try_link(src, "-ObjC#{opt}", &b)
+ if try_link(src, opt, &b) or (objc = try_link(src, "-ObjC#{opt}", &b))
$defs.push(format("-DHAVE_FRAMEWORK_%s", fw.tr_cpp))
# TODO: non-worse way than this hack, to get rid of separating
# option and its argument.
- $LDFLAGS << " -ObjC" unless /(\A|\s)-ObjC(\s|\z)/ =~ $LDFLAGS
+ $LDFLAGS << " -ObjC" if objc and /(\A|\s)-ObjC(\s|\z)/ !~ $LDFLAGS
$LIBS << opt
true
else
@@ -1166,6 +1338,7 @@ SRC
end
end
+ # :nodoc:
# Returns whether or not the static type +type+ is defined.
#
# See also +have_type+
@@ -1223,6 +1396,7 @@ SRC
end
end
+ # :nodoc:
# Returns whether or not the constant +const+ is defined.
#
# See also +have_const+
@@ -1266,8 +1440,10 @@ SRC
# :stopdoc:
STRING_OR_FAILED_FORMAT = "%s"
- def STRING_OR_FAILED_FORMAT.%(x) # :nodoc:
- x ? super : "failed"
+ class << STRING_OR_FAILED_FORMAT # :nodoc:
+ def %(x)
+ x ? super : "failed"
+ end
end
def typedef_expr(type, headers)
@@ -1301,7 +1477,7 @@ SRC
#
def check_sizeof(type, headers = nil, opts = "", &b)
typedef, member, prelude = typedef_expr(type, headers)
- prelude << "static #{typedef} *rbcv_ptr_;\n"
+ prelude << "#{typedef} *rbcv_ptr_;\n"
prelude = [prelude]
expr = "sizeof((*rbcv_ptr_)#{"." << member if member})"
fmt = STRING_OR_FAILED_FORMAT
@@ -1344,7 +1520,7 @@ SRC
# _convertible_ means actually the same type, or typedef'd from the same
# type.
#
- # If the +type+ is a integer type and the _convertible_ type is found,
+ # If the +type+ is an integer type and the _convertible_ type is found,
# the following macros are passed as preprocessor constants to the compiler
# using the +type+ name, in uppercase.
#
@@ -1380,7 +1556,7 @@ SRC
u = "unsigned " if signed > 0
prelude << "extern rbcv_typedef_ foo();"
compat = UNIVERSAL_INTS.find {|t|
- try_compile([prelude, "extern #{u}#{t} foo();"].join("\n"), opts, :werror=>true, &b)
+ try_compile([prelude, "extern #{u}#{t} foo();"].join("\n"), opts, werror: true, &b)
}
end
if compat
@@ -1404,7 +1580,7 @@ SRC
# Used internally by the what_type? method to determine if +type+ is a scalar
# pointer.
def scalar_ptr_type?(type, member = nil, headers = nil, &b)
- try_compile(<<"SRC", &b) # pointer
+ try_compile(<<"SRC", &b)
#{cpp_include(headers)}
/*top*/
volatile #{type} conftestval;
@@ -1417,7 +1593,7 @@ SRC
# Used internally by the what_type? method to determine if +type+ is a scalar
# pointer.
def scalar_type?(type, member = nil, headers = nil, &b)
- try_compile(<<"SRC", &b) # pointer
+ try_compile(<<"SRC", &b)
#{cpp_include(headers)}
/*top*/
volatile #{type} conftestval;
@@ -1439,6 +1615,10 @@ SRC
end
end
+ # :startdoc:
+
+ # Returns a string represents the type of _type_, or _member_ of
+ # _type_ if _member_ is not +nil+.
def what_type?(type, member = nil, headers = nil, &b)
m = "#{type}"
var = val = "*rbcv_var_"
@@ -1454,7 +1634,7 @@ SRC
prelude = [cpp_include(headers).split(/^/)]
prelude << ["typedef #{type} rbcv_typedef_;\n",
"extern rbcv_typedef_ *#{func};\n",
- "static rbcv_typedef_ #{var};\n",
+ "rbcv_typedef_ #{var};\n",
]
type = "rbcv_typedef_"
fmt = member && !(typeof = have_typeof?) ? "seems %s" : "%s"
@@ -1465,7 +1645,7 @@ SRC
type = "rbcv_mem_typedef_"
prelude[-1] << "typedef #{typeof}(#{val}) #{type};\n"
prelude[-1] << "extern #{type} *#{func};\n"
- prelude[-1] << "static #{type} #{var};\n"
+ prelude[-1] << "#{type} #{var};\n"
val = var
end
def fmt.%(x)
@@ -1488,7 +1668,7 @@ SRC
type = UNIVERSAL_INTS.find do |t|
pre = prelude
unless member
- pre += [["static #{unsigned} #{t} #{ptr}#{var};\n",
+ pre += [["#{unsigned} #{t} #{ptr}#{var};\n",
"extern #{unsigned} #{t} #{ptr}*#{func};\n"]]
end
try_static_assert("sizeof(#{ptr}#{val}) == sizeof(#{unsigned} #{t})", pre)
@@ -1498,6 +1678,8 @@ SRC
end
end
+ # :nodoc:
+ #
# This method is used internally by the find_executable method.
#
# Internal use only.
@@ -1527,6 +1709,7 @@ SRC
end
file = nil
path.each do |dir|
+ dir.sub!(/\A"(.*)"\z/m, '\1') if $mswin or $mingw
return file if executable_file.call(file = File.join(dir, bin))
if exts
exts.each {|ext| executable_file.call(ext = file + ext) and return ext}
@@ -1535,8 +1718,6 @@ SRC
nil
end
- # :startdoc:
-
# Searches for the executable +bin+ on +path+. The default path is your
# +PATH+ environment variable. If that isn't defined, it will resort to
# searching /usr/local/bin, /usr/ucb, /usr/bin and /bin.
@@ -1669,36 +1850,60 @@ SRC
hdr << "#endif\n"
hdr = hdr.join("")
log_src(hdr, "#{header} is")
- unless (IO.read(header) == hdr rescue false)
- open(header, "wb") do |hfile|
+ unless (File.read(header) == hdr rescue false)
+ File.open(header, "wb") do |hfile|
hfile.write(hdr)
end
end
$extconf_h = header
end
- # Sets a +target+ name that the user can then use to configure various
- # "with" options with on the command line by using that name. For example,
- # if the target is set to "foo", then the user could use the
- # <code>--with-foo-dir</code> command line option.
+ # call-seq:
+ # dir_config(target)
+ # dir_config(target, prefix)
+ # dir_config(target, idefault, ldefault)
+ #
+ # Sets a +target+ name that the user can then use to configure
+ # various "with" options with on the command line by using that
+ # name. For example, if the target is set to "foo", then the user
+ # could use the <code>--with-foo-dir=prefix</code>,
+ # <code>--with-foo-include=dir</code> and
+ # <code>--with-foo-lib=dir</code> command line options to tell where
+ # to search for header/library files.
#
- # You may pass along additional "include" or "lib" defaults via the
- # +idefault+ and +ldefault+ parameters, respectively.
+ # You may pass along additional parameters to specify default
+ # values. If one is given it is taken as default +prefix+, and if
+ # two are given they are taken as "include" and "lib" defaults in
+ # that order.
+ #
+ # In any case, the return value will be an array of determined
+ # "include" and "lib" directories, either of which can be nil if no
+ # corresponding command line option is given when no default value
+ # is specified.
#
# Note that dir_config only adds to the list of places to search for
# libraries and include files. It does not link the libraries into your
# application.
#
def dir_config(target, idefault=nil, ldefault=nil)
+ key = [target, idefault, ldefault].compact.join("\0")
+ if conf = $config_dirs[key]
+ return conf
+ end
+
if dir = with_config(target + "-dir", (idefault unless ldefault))
defaults = Array === dir ? dir : dir.split(File::PATH_SEPARATOR)
idefault = ldefault = nil
end
idir = with_config(target + "-include", idefault)
- $arg_config.last[1] ||= "${#{target}-dir}/include"
+ if conf = $arg_config.assoc("--with-#{target}-include")
+ conf[1] ||= "${#{target}-dir}/include"
+ end
ldir = with_config(target + "-lib", ldefault)
- $arg_config.last[1] ||= "${#{target}-dir}/#{_libdir_basename}"
+ if conf = $arg_config.assoc("--with-#{target}-lib")
+ conf[1] ||= "${#{target}-dir}/#{_libdir_basename}"
+ end
idirs = idir ? Array === idir ? idir.dup : idir.split(File::PATH_SEPARATOR) : []
if defaults
@@ -1720,59 +1925,109 @@ SRC
end
$LIBPATH = ldirs | $LIBPATH
- [idir, ldir]
+ $config_dirs[key] = [idir, ldir]
end
- # Returns compile/link information about an installed library in a
- # tuple of <code>[cflags, ldflags, libs]</code>, by using the
- # command found first in the following commands:
+ # Returns compile/link information about an installed library in a tuple of <code>[cflags,
+ # ldflags, libs]</code>, by using the command found first in the following commands:
#
# 1. If <code>--with-{pkg}-config={command}</code> is given via
- # command line option: <code>{command} {option}</code>
- #
- # 2. <code>{pkg}-config {option}</code>
- #
- # 3. <code>pkg-config {option} {pkg}</code>
- #
- # Where {option} is, for instance, <code>--cflags</code>.
- #
- # The values obtained are appended to +$CFLAGS+, +$LDFLAGS+ and
- # +$libs+.
- #
- # If an <code>option</code> argument is given, the config command is
- # invoked with the option and a stripped output string is returned
- # without modifying any of the global values mentioned above.
- def pkg_config(pkg, option=nil)
- if pkgconfig = with_config("#{pkg}-config") and find_executable0(pkgconfig)
- # iff package specific config command is given
- get = proc {|opt| `#{pkgconfig} --#{opt}`.strip}
- elsif ($PKGCONFIG ||=
- (pkgconfig = with_config("pkg-config", ("pkg-config" unless CROSS_COMPILING))) &&
- find_executable0(pkgconfig) && pkgconfig) and
- system("#{$PKGCONFIG} --exists #{pkg}")
- # default to pkg-config command
- get = proc {|opt| `#{$PKGCONFIG} --#{opt} #{pkg}`.strip}
- elsif find_executable0(pkgconfig = "#{pkg}-config")
+ # command line option: <code>{command} {options}</code>
+ #
+ # 2. <code>{pkg}-config {options}</code>
+ #
+ # 3. <code>pkg-config {options} {pkg}</code>
+ #
+ # Where +options+ is the option name without dashes, for instance <code>"cflags"</code> for the
+ # <code>--cflags</code> flag.
+ #
+ # The values obtained are appended to <code>$INCFLAGS</code>, <code>$CFLAGS</code>,
+ # <code>$LDFLAGS</code> and <code>$libs</code>.
+ #
+ # If one or more <code>options</code> argument is given, the config command is
+ # invoked with the options and a stripped output string is returned without
+ # modifying any of the global values mentioned above.
+ def pkg_config(pkg, *options)
+ fmt = "not found"
+ def fmt.%(x)
+ x ? x.inspect : self
+ end
+
+ checking_for "pkg-config for #{pkg}", fmt do
+ _, ldir = dir_config(pkg)
+ if ldir
+ pkg_config_path = "#{ldir}/pkgconfig"
+ if File.directory?(pkg_config_path)
+ Logging.message("PKG_CONFIG_PATH = %s\n", pkg_config_path)
+ envs = ["PKG_CONFIG_PATH"=>[pkg_config_path, ENV["PKG_CONFIG_PATH"]].compact.join(File::PATH_SEPARATOR)]
+ end
+ end
+ if pkgconfig = with_config("#{pkg}-config") and find_executable0(pkgconfig)
+ # if and only if package specific config command is given
+ elsif ($PKGCONFIG ||=
+ (pkgconfig = with_config("pkg-config") {config_string("PKG_CONFIG") || ENV["PKG_CONFIG"] || "pkg-config"}) &&
+ find_executable0(pkgconfig) && pkgconfig) and
+ xsystem([*envs, $PKGCONFIG, "--exists", pkg])
+ # default to pkg-config command
+ pkgconfig = $PKGCONFIG
+ args = [pkg]
+ elsif find_executable0(pkgconfig = "#{pkg}-config")
# default to package specific config command, as a last resort.
- get = proc {|opt| `#{pkgconfig} --#{opt}`.strip}
- end
- orig_ldflags = $LDFLAGS
- if get and option
- get[option]
- elsif get and try_ldflags(ldflags = get['libs'])
- cflags = get['cflags']
- libs = get['libs-only-l']
- ldflags = (Shellwords.shellwords(ldflags) - Shellwords.shellwords(libs)).quote.join(" ")
- $CFLAGS += " " << cflags
- $LDFLAGS = [orig_ldflags, ldflags].join(' ')
- $libs += " " << libs
- Logging::message "package configuration for %s\n", pkg
- Logging::message "cflags: %s\nldflags: %s\nlibs: %s\n\n",
- cflags, ldflags, libs
- [cflags, ldflags, libs]
- else
- Logging::message "package configuration for %s is not found\n", pkg
- nil
+ else
+ pkgconfig = nil
+ end
+ if pkgconfig
+ get = proc {|opts|
+ opts = Array(opts).map { |o| "--#{o}" }
+ opts = xpopen([*envs, pkgconfig, *opts, *args], err:[:child, :out], &:read)
+ Logging.open {puts opts.each_line.map{|s|"=> #{s.inspect}"}}
+ if $?.success?
+ opts = opts.strip
+ libarg, libpath = LIBARG, LIBPATHFLAG.strip
+ opts = opts.shellsplit.map { |s|
+ if s.start_with?('-l')
+ libarg % s[2..]
+ elsif s.start_with?('-L')
+ libpath % s[2..]
+ else
+ s
+ end
+ }.quote.join(" ")
+ opts
+ end
+ }
+ end
+ orig_ldflags = $LDFLAGS
+ if get and !options.empty?
+ get[options]
+ elsif get and try_ldflags(ldflags = get['libs'])
+ if incflags = get['cflags-only-I']
+ $INCFLAGS << " " << incflags
+ cflags = get['cflags-only-other']
+ else
+ cflags = get['cflags']
+ end
+ libs = get['libs-only-l']
+ if cflags
+ $CFLAGS += " " << cflags
+ $CXXFLAGS += " " << cflags
+ end
+ if libs
+ ldflags = (Shellwords.shellwords(ldflags) - Shellwords.shellwords(libs)).quote.join(" ")
+ else
+ libs, ldflags = Shellwords.shellwords(ldflags).partition {|s| s =~ /-l([^ ]+)/ }.map {|l|l.quote.join(" ")}
+ end
+ $libs += " " << libs
+
+ $LDFLAGS = [orig_ldflags, ldflags].join(' ')
+ Logging::message "package configuration for %s\n", pkg
+ Logging::message "incflags: %s\ncflags: %s\nldflags: %s\nlibs: %s\n\n",
+ incflags, cflags, ldflags, libs
+ [[incflags, cflags].join(' '), ldflags, libs]
+ else
+ Logging::message "package configuration for %s is not found\n", pkg
+ nil
+ end
end
end
@@ -1806,7 +2061,7 @@ SRC
path.sub!(/\A([A-Za-z]):(?=\/)/, '/\1')
path
end
- when 'cygwin'
+ when 'cygwin', 'msys'
if CONFIG['target_os'] != 'cygwin'
def mkintpath(path)
IO.popen(["cygpath", "-u", path], &:read).chomp
@@ -1822,24 +2077,27 @@ SRC
def configuration(srcdir)
mk = []
+ verbose = with_config('verbose') ? "1" : (CONFIG['MKMF_VERBOSE'] || "0")
vpath = $VPATH.dup
CONFIG["hdrdir"] ||= $hdrdir
mk << %{
SHELL = /bin/sh
# V=0 quiet, V=1 verbose. other values don't work.
-V = 0
+V = #{verbose}
+V0 = $(V:0=)
Q1 = $(V:1=)
Q = $(Q1:0=@)
-ECHO1 = $(V:1=@#{CONFIG['NULLCMD']})
-ECHO = $(ECHO1:0=@echo)
+ECHO1 = $(V:1=@ #{CONFIG['NULLCMD']})
+ECHO = $(ECHO1:0=@ echo)
+NULLCMD = #{CONFIG['NULLCMD']}
#### Start of system configuration section. ####
#{"top_srcdir = " + $top_srcdir.sub(%r"\A#{Regexp.quote($topdir)}/", "$(topdir)/") if $extmk}
srcdir = #{srcdir.gsub(/\$\((srcdir)\)|\$\{(srcdir)\}/) {mkintpath(CONFIG[$1||$2]).unspace}}
topdir = #{mkintpath(topdir = $extmk ? CONFIG["topdir"] : $topdir).unspace}
hdrdir = #{(hdrdir = CONFIG["hdrdir"]) == topdir ? "$(topdir)" : mkintpath(hdrdir).unspace}
-arch_hdrdir = #{$arch_hdrdir.quote}
+arch_hdrdir = #{mkintpath($arch_hdrdir).unspace}
PATH_SEPARATOR = #{CONFIG['PATH_SEPARATOR']}
VPATH = #{vpath.join(CONFIG['PATH_SEPARATOR'])}
}
@@ -1857,7 +2115,7 @@ VPATH = #{vpath.join(CONFIG['PATH_SEPARATOR'])}
end
CONFIG.each do |key, var|
next if /^abs_/ =~ key
- next if /^(?:src|top|hdr)dir$/ =~ key
+ next if /^(?:src|top(?:_src)?|build|hdr)dir$/ =~ key
next unless /dir$/ =~ key
mk << "#{key} = #{with_destdir(var)}\n"
end
@@ -1867,10 +2125,11 @@ VPATH = #{vpath.join(CONFIG['PATH_SEPARATOR'])}
else
sep = ""
end
- possible_command = (proc {|s| s if /top_srcdir/ !~ s} unless $extmk)
+ possible_command = (proc {|s| s if /top_srcdir|tooldir/ !~ s} unless $extmk)
extconf_h = $extconf_h ? "-DRUBY_EXTCONF_H=\\\"$(RUBY_EXTCONF_H)\\\" " : $defs.join(" ") << " "
headers = %w[
$(hdrdir)/ruby.h
+ $(hdrdir)/ruby/backward.h
$(hdrdir)/ruby/ruby.h
$(hdrdir)/ruby/defines.h
$(hdrdir)/ruby/missing.h
@@ -1878,6 +2137,7 @@ VPATH = #{vpath.join(CONFIG['PATH_SEPARATOR'])}
$(hdrdir)/ruby/st.h
$(hdrdir)/ruby/subst.h
]
+ headers += $headers
if RULE_SUBST
headers.each {|h| h.sub!(/.*/, &RULE_SUBST.method(:%))}
end
@@ -1885,6 +2145,7 @@ VPATH = #{vpath.join(CONFIG['PATH_SEPARATOR'])}
headers << '$(RUBY_EXTCONF_H)' if $extconf_h
mk << %{
+CC_WRAPPER = #{CONFIG['CC_WRAPPER']}
CC = #{CONFIG['CC']}
CXX = #{CONFIG['CXX']}
LIBRUBY = #{CONFIG['LIBRUBY']}
@@ -1894,25 +2155,30 @@ LIBRUBYARG_STATIC = #$LIBRUBYARG_STATIC
empty =
OUTFLAG = #{OUTFLAG}$(empty)
COUTFLAG = #{COUTFLAG}$(empty)
+CSRCFLAG = #{CSRCFLAG}$(empty)
RUBY_EXTCONF_H = #{$extconf_h}
cflags = #{CONFIG['cflags']}
+cxxflags = #{CONFIG['cxxflags']}
optflags = #{CONFIG['optflags']}
debugflags = #{CONFIG['debugflags']}
warnflags = #{$warnflags}
+cppflags = #{CONFIG['cppflags']}
CCDLFLAGS = #{$static ? '' : CONFIG['CCDLFLAGS']}
CFLAGS = $(CCDLFLAGS) #$CFLAGS $(ARCH_FLAG)
INCFLAGS = -I. #$INCFLAGS
DEFS = #{CONFIG['DEFS']}
CPPFLAGS = #{extconf_h}#{$CPPFLAGS}
-CXXFLAGS = $(CCDLFLAGS) #{CONFIG['CXXFLAGS']} $(ARCH_FLAG)
+CXXFLAGS = $(CCDLFLAGS) #$CXXFLAGS $(ARCH_FLAG)
ldflags = #{$LDFLAGS}
dldflags = #{$DLDFLAGS} #{CONFIG['EXTDLDFLAGS']}
ARCH_FLAG = #{$ARCH_FLAG}
DLDFLAGS = $(ldflags) $(dldflags) $(ARCH_FLAG)
LDSHARED = #{CONFIG['LDSHARED']}
LDSHAREDXX = #{config_string('LDSHAREDXX') || '$(LDSHARED)'}
+POSTLINK = #{config_string('POSTLINK', RbConfig::CONFIG)}
AR = #{CONFIG['AR']}
+LD = #{CONFIG['LD']}
EXEEXT = #{CONFIG['EXEEXT']}
}
@@ -1925,10 +2191,15 @@ sitearch = #{CONFIG['sitearch']}
ruby_version = #{RbConfig::CONFIG['ruby_version']}
ruby = #{$ruby.sub(%r[\A#{Regexp.quote(RbConfig::CONFIG['bindir'])}(?=/|\z)]) {'$(bindir)'}}
RUBY = $(ruby#{sep})
+BUILTRUBY = #{if defined?($builtruby) && $builtruby
+ $builtruby
+ else
+ File.join('$(bindir)', CONFIG["RUBY_INSTALL_NAME"] + CONFIG['EXEEXT'])
+ end}
ruby_headers = #{headers.join(' ')}
RM = #{config_string('RM', &possible_command) || '$(RUBY) -run -e rm -- -f'}
-RM_RF = #{'$(RUBY) -run -e rm -- -rf'}
+RM_RF = #{config_string('RMALL', &possible_command) || '$(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'}
@@ -1941,32 +2212,25 @@ TOUCH = exit >
preload = #{defined?($preload) && $preload ? $preload.join(' ') : ''}
}
- if $nmake == ?b
- mk.each do |x|
- x.gsub!(/^(MAKEDIRS|INSTALL_(?:PROG|DATA))+\s*=.*\n/) do
- "!ifndef " + $1 + "\n" +
- $& +
- "!endif\n"
- end
- end
- end
mk
end
def timestamp_file(name, target_prefix = nil)
- if target_prefix
- pat = []
- install_dirs.each do |n, d|
- pat << n if /\$\(target_prefix\)\z/ =~ d
- end
- name = name.gsub(/\$\((#{pat.join("|")})\)/) {$&+target_prefix}
- end
+ pat = {}
+ name = '$(RUBYARCHDIR)' if name == '$(TARGET_SO_DIR)'
+ install_dirs.each do |n, d|
+ pat[n] = $` if /\$\(target_prefix\)\z/ =~ d
+ end
+ name = name.gsub(/\$\((#{pat.keys.join("|")})\)/) {pat[$1]+target_prefix}
+ name.sub!(/(\$\((?:site)?arch\))\/*/, '')
+ arch = $1 || ''
+ name.chomp!('/')
name = name.gsub(/(\$[({]|[})])|(\/+)|[^-.\w]+/) {$1 ? "" : $2 ? ".-." : "_"}
- "$(TIMESTAMP_DIR)/.#{name}.time"
+ File.join("$(TIMESTAMP_DIR)", arch, "#{name.sub(/\A(?=.)/, '.')}.time")
end
# :startdoc:
- # creates a stub Makefile.
+ # Creates a stub Makefile.
#
def dummy_makefile(srcdir)
configuration(srcdir) << <<RULES << CLEANINGS
@@ -1974,6 +2238,7 @@ CLEANFILES = #{$cleanfiles.join(' ')}
DISTCLEANFILES = #{$distcleanfiles.join(' ')}
all install static install-so install-rb: Makefile
+ @$(NULLCMD)
.PHONY: all install static install-so install-rb
.PHONY: clean clean-so clean-static clean-rb
@@ -2020,7 +2285,10 @@ RULES
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}
+ line.sub!(/\s*\#.*$/, '')
+ comment = $&
+ line.gsub!(%r"(\s)(?!\.)([^$(){}+=:\s\\,]+)(?=\s|\z)") {$1 + RULE_SUBST % $2}
+ line = line.chomp + comment + "\n" if comment
end
depout << line
end
@@ -2028,7 +2296,6 @@ RULES
line.gsub!(/\.o\b/, ".#{$OBJEXT}")
line.gsub!(/\{\$\(VPATH\)\}/, "") unless $nmake
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:/=\\')
@@ -2050,7 +2317,10 @@ RULES
unless suffixes.empty?
depout.unshift(".SUFFIXES: ." + suffixes.uniq.join(" .") + "\n\n")
end
- depout.unshift("$(OBJS): $(RUBY_EXTCONF_H)\n\n") if $extconf_h
+ if $extconf_h
+ depout.unshift("$(OBJS): $(RUBY_EXTCONF_H)\n\n")
+ depout.unshift("$(OBJS): $(hdrdir)/ruby/win32.h\n\n") if $mswin or $mingw
+ end
depout.flatten!
depout
end
@@ -2108,13 +2378,26 @@ RULES
# directory, i.e. the current directory. It is included as part of the
# +VPATH+ and added to the list of +INCFLAGS+.
#
+ # Yields the configuration part of the makefile to be generated, as an array
+ # of strings, if the block is given. The returned value will be used the
+ # new configuration part.
+ #
+ # create_makefile('foo') {|conf|
+ # [
+ # *conf,
+ # "MACRO_YOU_NEED = something",
+ # ]
+ # }
+ #
+ # If "depend" file exist in the source directory, that content will be
+ # included in the generated makefile, with formatted by depend_rules method.
def create_makefile(target, srcprefix = nil)
$target = target
libpath = $DEFLIBPATH|$LIBPATH
message "creating Makefile\n"
MakeMakefile.rm_f "#{CONFTEST}*"
if CONFIG["DLEXT"] == $OBJEXT
- for lib in libs = $libs.split
+ for lib in libs = $libs.split(' ')
lib.sub!(/-l(.*)/, %%"lib\\1.#{$LIBEXT}"%)
end
$defs.push(format("-DEXTLIB='%s'", libs.join(",")))
@@ -2134,10 +2417,14 @@ RULES
orig_srcs = Dir[File.join(srcdir, "*.{#{SRC_EXT.join(%q{,})}}")]
if not $objs
srcs = $srcs || orig_srcs
- objs = srcs.inject(Hash.new {[]}) {|h, f| h[File.basename(f, ".*") << ext] <<= f; h}
- $objs = objs.keys
+ $objs = []
+ objs = srcs.inject(Hash.new {[]}) {|h, f|
+ h.key?(o = File.basename(f, ".*") << ext) or $objs << o
+ h[o] <<= f
+ h
+ }
unless objs.delete_if {|b, f| f.size == 1}.empty?
- dups = objs.sort.map {|b, f|
+ dups = objs.map {|b, f|
"#{b[/.*\./]}{#{f.collect {|n| n[/([^.]+)\z/]}.join(',')}}"
}
abort "source files duplication - #{dups.join(", ")}"
@@ -2156,10 +2443,10 @@ RULES
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 = %{$(RUBY) -pe "$$_.sub!(/^(?=\\w)/,'#{EXPORT_PREFIX}') unless 1../^EXPORTS$/i" #{deffile}}
end
else
- makedef = %{-e "puts 'EXPORTS', '$(TARGET_ENTRY)'"}
+ makedef = %{(echo EXPORTS && echo $(TARGET_ENTRY))}
end
if makedef
$cleanfiles << '$(DEFFILE)'
@@ -2170,7 +2457,7 @@ RULES
origdef ||= ''
if $extout and $INSTALLFILES
- $cleanfiles.concat($INSTALLFILES.collect {|files, dir|File.join(dir, files.sub(/\A\.\//, ''))})
+ $cleanfiles.concat($INSTALLFILES.collect {|files, dir|File.join(dir, files.delete_prefix('./'))})
$distcleandirs.concat($INSTALLFILES.collect {|files, dir| dir})
end
@@ -2186,11 +2473,8 @@ RULES
dllib = target ? "$(TARGET).#{CONFIG['DLEXT']}" : ""
staticlib = target ? "$(TARGET).#$LIBEXT" : ""
- mfile = open("Makefile", "wb")
conf = configuration(srcprefix)
- conf = yield(conf) if block_given?
- mfile.puts(conf)
- mfile.print "
+ conf << "\
libpath = #{($DEFLIBPATH|$LIBPATH).join(" ")}
LIBPATH = #{libpath}
DEFFILE = #{deffile}
@@ -2208,28 +2492,47 @@ ORIG_SRCS = #{orig_srcs.collect(&File.method(:basename)).join(' ')}
SRCS = $(ORIG_SRCS) #{(srcs - orig_srcs).collect(&File.method(:basename)).join(' ')}
OBJS = #{$objs.join(" ")}
HDRS = #{hdrs.map{|h| '$(srcdir)/' + File.basename(h)}.join(' ')}
+LOCAL_HDRS = #{$headers.join(' ')}
TARGET = #{target}
TARGET_NAME = #{target && target[/\A\w+/]}
TARGET_ENTRY = #{EXPORT_PREFIX || ''}Init_$(TARGET_NAME)
DLLIB = #{dllib}
EXTSTATIC = #{$static || ""}
STATIC_LIB = #{staticlib unless $static.nil?}
-#{!$extout && defined?($installed_list) ? "INSTALLED_LIST = #{$installed_list}\n" : ""}
-TIMESTAMP_DIR = #{$extout ? '$(extout)/.timestamp' : '.'}
+#{!$extout && defined?($installed_list) ? %[INSTALLED_LIST = #{$installed_list}\n] : ""}
+TIMESTAMP_DIR = #{$extout && $extmk ? '$(extout)/.timestamp' : '.'}
" #"
# 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)#{deffile ? '-$(arch)': ''}")} if target} *.bak
+ install_dirs.each {|d| conf << ("%-14s= %s\n" % d) if /^[[:upper:]]/ =~ d[0]}
+ sodir = $extout ? '$(TARGET_SO_DIR)' : '$(RUBYARCHDIR)'
+ n = '$(TARGET_SO_DIR)$(TARGET)'
+ cleanobjs = ["$(OBJS)"]
+ cleanlibs = []
+ if $extmk
+ %w[bc i s].each {|ex| cleanobjs << "$(OBJS:.#{$OBJEXT}=.#{ex})"}
+ end
+ if target
+ config_string('cleanobjs') {|t| cleanobjs << t.gsub(/\$\*/, "$(TARGET)#{deffile ? '-$(arch)': ''}")}
+ cleanlibs << '$(TARGET_SO)'
+ end
+ config_string('cleanlibs') {|t| cleanlibs << t.gsub(/\$\*/) {n}}
+ conf << "\
+TARGET_SO_DIR =#{$extout ? " $(RUBYARCHDIR)/" : ''}
+TARGET_SO = $(TARGET_SO_DIR)$(DLLIB)
+CLEANLIBS = #{cleanlibs.join(' ')}
+CLEANOBJS = #{cleanobjs.join(' ')} *.bak
+TARGET_SO_DIR_TIMESTAMP = #{timestamp_file(sodir, target_prefix)}
+" #"
+ conf = yield(conf) if block_given?
+ mfile = File.open("Makefile", "wb")
+ mfile.puts(conf)
+ mfile.print "
all: #{$extout ? "install" : target ? "$(DLLIB)" : "Makefile"}
-static: $(STATIC_LIB)#{$extout ? " install-rb" : ""}
+static: #{$extmk && !$static ? "all" : %[$(STATIC_LIB)#{$extout ? " install-rb" : ""}]}
.PHONY: all install static install-so install-rb
.PHONY: clean clean-so clean-static clean-rb
-"
+" #"
mfile.print CLEANINGS
fsep = config_string('BUILD_FILE_SEPARATOR') {|s| s unless s == "/"}
if fsep
@@ -2237,7 +2540,7 @@ static: $(STATIC_LIB)#{$extout ? " install-rb" : ""}
fseprepl = proc {|s|
s = s.gsub("/", fsep)
s = s.gsub(/(\$\(\w+)(\))/) {$1+sep+$2}
- s = s.gsub(/(\$\{\w+)(\})/) {$1+sep+$2}
+ s.gsub(/(\$\{\w+)(\})/) {$1+sep+$2}
}
rsep = ":#{fsep}=/"
else
@@ -2247,18 +2550,20 @@ static: $(STATIC_LIB)#{$extout ? " install-rb" : ""}
end
dirs = []
mfile.print "install: install-so install-rb\n\n"
- sodir = (dir = "$(RUBYARCHDIR)").dup
+ dir = sodir.dup
mfile.print("install-so: ")
if target
f = "$(DLLIB)"
- dest = "#{dir}/#{f}"
+ dest = "$(TARGET_SO)"
+ stamp = '$(TARGET_SO_DIR_TIMESTAMP)'
if $extout
mfile.puts dest
mfile.print "clean-so::\n"
- mfile.print "\t-$(Q)$(RM) #{fseprepl[dest]}\n"
+ mfile.print "\t-$(Q)$(RM) #{fseprepl[dest]} #{fseprepl[stamp]}\n"
+ mfile.print "\t-$(Q)$(RM_RF) #{fseprepl['$(CLEANLIBS)']}\n"
mfile.print "\t-$(Q)$(RMDIRS) #{fseprepl[dir]}#{$ignore_error}\n"
else
- mfile.print "#{f} #{timestamp_file(dir, target_prefix)}\n"
+ mfile.print "#{f} #{stamp}\n"
mfile.print "\t$(INSTALL_PROG) #{fseprepl[f]} #{dir}\n"
if defined?($installed_list)
mfile.print "\t@echo #{dir}/#{File.basename(f)}>>$(INSTALLED_LIST)\n"
@@ -2269,10 +2574,12 @@ static: $(STATIC_LIB)#{$extout ? " install-rb" : ""}
else
mfile.puts "Makefile"
end
- mfile.print("install-rb: pre-install-rb install-rb-default\n")
- mfile.print("install-rb-default: pre-install-rb-default\n")
+ mfile.print("install-rb: pre-install-rb do-install-rb install-rb-default\n")
+ mfile.print("install-rb-default: pre-install-rb-default do-install-rb-default\n")
mfile.print("pre-install-rb: Makefile\n")
mfile.print("pre-install-rb-default: Makefile\n")
+ mfile.print("do-install-rb:\n")
+ mfile.print("do-install-rb-default:\n")
for sfx, i in [["-default", [["lib/**/*.rb", "$(RUBYLIBDIR)", "lib"]]], ["", $INSTALLFILES]]
files = install_files(mfile, i, nil, srcprefix) or next
for dir, *files in files
@@ -2282,9 +2589,9 @@ static: $(STATIC_LIB)#{$extout ? " install-rb" : ""}
end
for f in files
dest = "#{dir}/#{File.basename(f)}"
- mfile.print("install-rb#{sfx}: #{dest}\n")
+ mfile.print("do-install-rb#{sfx}: #{dest}\n")
mfile.print("#{dest}: #{f} #{timestamp_file(dir, target_prefix)}\n")
- mfile.print("\t$(Q) $(#{$extout ? 'COPY' : 'INSTALL_DATA'}) #{f} $(@D#{sep})\n")
+ mfile.print("\t$(Q) $(#{$extout ? 'COPY' : 'INSTALL_DATA'}) #{f} $@\n")
if defined?($installed_list) and !$extout
mfile.print("\t@echo #{dest}>>$(INSTALLED_LIST)\n")
end
@@ -2295,18 +2602,32 @@ static: $(STATIC_LIB)#{$extout ? " install-rb" : ""}
end
end
mfile.print "pre-install-rb#{sfx}:\n"
- mfile.print("\t$(ECHO) installing#{sfx.sub(/^-/, " ")} #{target} libraries\n")
+ if files.empty?
+ mfile.print("\t@$(NULLCMD)\n")
+ else
+ q = "$(MAKE) -q do-install-rb#{sfx}"
+ if $nmake
+ mfile.print "!if \"$(Q)\" == \"@\"\n\t@#{q} || \\\n!endif\n\t"
+ else
+ mfile.print "\t$(Q1:0=@#{q} || )"
+ end
+ mfile.print "$(ECHO1:0=echo) installing#{sfx.sub(/^-/, " ")} #{target} libraries\n"
+ end
if $extout
dirs.uniq!
unless dirs.empty?
mfile.print("clean-rb#{sfx}::\n")
for dir in dirs.sort_by {|d| -d.count('/')}
+ stamp = timestamp_file(dir, target_prefix)
+ mfile.print("\t-$(Q)$(RM) #{fseprepl[stamp]}\n")
mfile.print("\t-$(Q)$(RMDIRS) #{fseprepl[dir]}#{$ignore_error}\n")
end
end
end
end
- dirs.unshift(sodir) if target and !dirs.include?(sodir)
+ if target and !dirs.include?(sodir)
+ mfile.print "$(TARGET_SO_DIR_TIMESTAMP):\n\t$(Q) $(MAKEDIRS) $(@D) #{sodir}\n\t$(Q) $(TOUCH) $@\n"
+ end
dirs.each do |d|
t = timestamp_file(d, target_prefix)
mfile.print "#{t}:\n\t$(Q) $(MAKEDIRS) $(@D) #{d}\n\t$(Q) $(TOUCH) $@\n"
@@ -2322,29 +2643,35 @@ site-install-rb: install-rb
return unless target
- mfile.puts SRC_EXT.collect {|e| ".path.#{e} = $(VPATH)"} if $nmake == ?b
- mfile.print ".SUFFIXES: .#{SRC_EXT.join(' .')} .#{$OBJEXT}\n"
+ mfile.print ".SUFFIXES: .#{(SRC_EXT + [$OBJEXT, $ASMEXT]).compact.join(' .')}\n"
mfile.print "\n"
compile_command = "\n\t$(ECHO) compiling $(<#{rsep})\n\t$(Q) %s\n\n"
+ command = compile_command % COMPILE_CXX
+ asm_command = compile_command.sub(/compiling/, 'translating') % ASSEMBLE_CXX
CXX_EXT.each do |e|
each_compile_rules do |rule|
mfile.printf(rule, e, $OBJEXT)
- mfile.printf(compile_command, COMPILE_CXX)
+ mfile.print(command)
+ mfile.printf(rule, e, $ASMEXT)
+ mfile.print(asm_command)
end
end
+ command = compile_command % COMPILE_C
+ asm_command = compile_command.sub(/compiling/, 'translating') % ASSEMBLE_C
C_EXT.each do |e|
each_compile_rules do |rule|
mfile.printf(rule, e, $OBJEXT)
- mfile.printf(compile_command, COMPILE_C)
+ mfile.print(command)
+ mfile.printf(rule, e, $ASMEXT)
+ mfile.print(asm_command)
end
end
- mfile.print "$(RUBYARCHDIR)/" if $extout
- mfile.print "$(DLLIB): "
+ mfile.print "$(TARGET_SO): "
mfile.print "$(DEFFILE) " if makedef
mfile.print "$(OBJS) Makefile"
- mfile.print " #{timestamp_file('$(RUBYARCHDIR)', target_prefix)}" if $extout
+ mfile.print " $(TARGET_SO_DIR_TIMESTAMP)" if $extout
mfile.print "\n"
mfile.print "\t$(ECHO) linking shared-object #{target_prefix.sub(/\A\/(.*)/, '\1/')}$(DLLIB)\n"
mfile.print "\t-$(Q)$(RM) $(@#{sep})\n"
@@ -2358,14 +2685,14 @@ site-install-rb: install-rb
mfile.print "$(ECHO) linking static-library $(@#{rsep})\n\t$(Q) "
mfile.print "$(AR) #{config_string('ARFLAGS') || 'cru '}$@ $(OBJS)"
config_string('RANLIB') do |ranlib|
- mfile.print "\n\t-$(Q)#{ranlib} $(@) 2> /dev/null || true"
+ mfile.print "\n\t-$(Q)#{ranlib} $(@)#{$ignore_error}"
end
end
mfile.print "\n\n"
if makedef
mfile.print "$(DEFFILE): #{origdef}\n"
mfile.print "\t$(ECHO) generating $(@#{rsep})\n"
- mfile.print "\t$(Q) $(RUBY) #{makedef} #{origdef} > $@\n\n"
+ mfile.print "\t$(Q) #{makedef} > $@\n\n"
end
depend = File.join(srcdir, "depend")
@@ -2388,16 +2715,25 @@ site-install-rb: install-rb
$enable_shared = config['ENABLE_SHARED'] == 'yes'
$defs = []
$extconf_h = nil
+ $config_dirs = {}
+
if $warnflags = CONFIG['warnflags'] and CONFIG['GCC'] == 'yes'
# turn warnings into errors only for bundled extensions.
- config['warnflags'] = $warnflags.gsub(/(\A|\s)-Werror[-=]/, '\1-W')
+ config['warnflags'] = $warnflags.gsub(/(?:\A|\s)-W\Kerror[-=](?!implicit-function-declaration)/, '')
+ if /icc\z/ =~ config['CC']
+ config['warnflags'].gsub!(/(\A|\s)-W(?:division-by-zero|deprecated-declarations)/, '\1')
+ end
RbConfig.expand(rbconfig['warnflags'] = config['warnflags'].dup)
config.each do |key, val|
RbConfig.expand(rbconfig[key] = val.dup) if /warnflags/ =~ val
end
$warnflags = config['warnflags'] unless $extmk
end
+ if (w = rbconfig['CC_WRAPPER']) and !w.empty? and !File.executable?(w)
+ rbconfig['CC_WRAPPER'] = config['CC_WRAPPER'] = ''
+ end
$CFLAGS = with_config("cflags", arg_config("CFLAGS", config["CFLAGS"])).dup
+ $CXXFLAGS = (with_config("cxxflags", arg_config("CXXFLAGS", config["CXXFLAGS"]))||'').dup
$ARCH_FLAG = with_config("arch_flag", arg_config("ARCH_FLAG", config["ARCH_FLAG"])).dup
$CPPFLAGS = with_config("cppflags", arg_config("CPPFLAGS", config["CPPFLAGS"])).dup
$LDFLAGS = with_config("ldflags", arg_config("LDFLAGS", config["LDFLAGS"])).dup
@@ -2405,9 +2741,11 @@ site-install-rb: install-rb
$INCFLAGS << " -I$(hdrdir)/ruby/backward" unless $extmk
$INCFLAGS << " -I$(hdrdir) -I$(srcdir)"
$DLDFLAGS = with_config("dldflags", arg_config("DLDFLAGS", config["DLDFLAGS"])).dup
+ config_string("ADDITIONAL_DLDFLAGS") {|flags| $DLDFLAGS << " " << flags} unless $extmk
$LIBEXT = config['LIBEXT'].dup
$OBJEXT = config["OBJEXT"].dup
$EXEEXT = config["EXEEXT"].dup
+ $ASMEXT = config_string('ASMEXT', &:dup) || 'S'
$LIBS = "#{config['LIBS']} #{config['DLDLIBS']}"
$LIBRUBYARG = ""
$LIBRUBYARG_STATIC = config['LIBRUBYARG_STATIC']
@@ -2421,6 +2759,7 @@ site-install-rb: install-rb
$objs = nil
$srcs = nil
+ $headers = []
$libs = ""
if $enable_shared or RbConfig.expand(config["LIBRUBY"].dup) != RbConfig.expand(config["LIBRUBY_A"].dup)
$LIBRUBYARG = config['LIBRUBYARG']
@@ -2437,6 +2776,7 @@ site-install-rb: install-rb
$extout_prefix ||= nil
$arg_config.clear
+ $config_dirs.clear
dir_config("opt")
end
@@ -2472,7 +2812,8 @@ MESSAGE
src = src.sub(/\{/) do
$& +
"\n if (argc > 1000000) {\n" +
- refs.map {|n|" printf(\"%p\", &#{n});\n"}.join("") +
+ refs.map {|n|" int (* volatile #{n}p)(void)=(int (*)(void))&#{n};\n"}.join("") +
+ refs.map {|n|" printf(\"%d\", (*#{n}p)());\n"}.join("") +
" }\n"
end
end
@@ -2488,10 +2829,8 @@ MESSAGE
case
when $mswin
$nmake = ?m if /nmake/i =~ make
- when $bccwin
- $nmake = ?b if /Borland/i =~ `#{make} -h`
end
- $ignore_error = $nmake ? '' : ' 2> /dev/null || true'
+ $ignore_error = " 2> #{File::NULL} || #{$mswin ? 'exit /b0' : 'true'}"
RbConfig::CONFIG["srcdir"] = CONFIG["srcdir"] =
$srcdir = arg_config("--srcdir", File.dirname($0))
@@ -2514,6 +2853,9 @@ MESSAGE
split = Shellwords.method(:shellwords).to_proc
+ ##
+ # The prefix added to exported symbols automatically
+
EXPORT_PREFIX = config_string('EXPORT_PREFIX') {|s| s.strip}
hdr = ['#include "ruby.h"' "\n"]
@@ -2543,17 +2885,31 @@ MESSAGE
# make compile rules
COMPILE_RULES = config_string('COMPILE_RULES', &split) || %w[.%s.%s:]
+
+ ##
+ # Substitution in rules for NMake
+
RULE_SUBST = config_string('RULE_SUBST')
##
# Command which will compile C files in the generated Makefile
- COMPILE_C = config_string('COMPILE_C') || '$(CC) $(INCFLAGS) $(CPPFLAGS) $(CFLAGS) $(COUTFLAG)$@ -c $<'
+ COMPILE_C = config_string('COMPILE_C') || '$(CC) $(INCFLAGS) $(CPPFLAGS) $(CFLAGS) $(COUTFLAG)$@ -c $(CSRCFLAG)$<'
##
# Command which will compile C++ files in the generated Makefile
- COMPILE_CXX = config_string('COMPILE_CXX') || '$(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -c $<'
+ COMPILE_CXX = config_string('COMPILE_CXX') || '$(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -c $(CSRCFLAG)$<'
+
+ ##
+ # Command which will translate C files to assembler sources in the generated Makefile
+
+ ASSEMBLE_C = config_string('ASSEMBLE_C') || COMPILE_C.sub(/(?<=\s)-c(?=\s)/, '-S')
+
+ ##
+ # Command which will translate C++ files to assembler sources in the generated Makefile
+
+ ASSEMBLE_CXX = config_string('ASSEMBLE_CXX') || COMPILE_CXX.sub(/(?<=\s)-c(?=\s)/, '-S')
##
# Command which will compile a program in order to test linking a library
@@ -2577,7 +2933,11 @@ MESSAGE
##
# Argument which will add a library path to the linker
- LIBPATHFLAG = config_string('LIBPATHFLAG') || ' -L%s'
+ LIBPATHFLAG = config_string('LIBPATHFLAG') || '-L%s'
+
+ ##
+ # Argument which will add a runtime library path to the linker
+
RPATHFLAG = config_string('RPATHFLAG') || ''
##
@@ -2588,7 +2948,11 @@ MESSAGE
##
# A C main function which does no work
- MAIN_DOES_NOTHING = config_string('MAIN_DOES_NOTHING') || "int main(int argc, char **argv)\n{\n return 0;\n}"
+ MAIN_DOES_NOTHING = config_string('MAIN_DOES_NOTHING') || "int main(int argc, char **argv)\n{\n return !!argv[argc];\n}"
+
+ ##
+ # The type names for convertible_int
+
UNIVERSAL_INTS = config_string('UNIVERSAL_INTS') {|s| Shellwords.shellwords(s)} ||
%w[int short long long\ long]
@@ -2603,22 +2967,108 @@ clean-rb-default::
clean-rb::
clean-so::
clean: clean-so clean-static clean-rb-default clean-rb
-\t\t-$(Q)$(RM) $(CLEANLIBS#{sep}) $(CLEANOBJS#{sep}) $(CLEANFILES#{sep}) .*.time
+\t\t-$(Q)$(RM_RF) $(CLEANLIBS#{sep}) $(CLEANOBJS#{sep}) $(CLEANFILES#{sep}) .*.time
distclean-rb-default::
distclean-rb::
distclean-so::
distclean-static::
distclean: clean distclean-so distclean-static distclean-rb-default distclean-rb
-\t\t-$(Q)$(RM) Makefile $(RUBY_EXTCONF_H) #{CONFTEST}.* mkmf.log
+\t\t-$(Q)$(RM) Makefile $(RUBY_EXTCONF_H) #{CONFTEST}.* mkmf.log#{' exts.mk' if $extmk}
\t\t-$(Q)$(RM) core ruby$(EXEEXT) *~ $(DISTCLEANFILES#{sep})
\t\t-$(Q)$(RMDIRS) $(DISTCLEANDIRS#{sep})#{$ignore_error}
realclean: distclean
"
+
+ @lang = Hash.new(self)
+
+ ##
+ # Retrieves the module for _name_ language.
+ def self.[](name)
+ @lang.fetch(name)
+ end
+
+ ##
+ # Defines the module for _name_ language.
+ def self.[]=(name, mod)
+ @lang[name] = mod
+ end
+
+ ##
+ # The language that this module is for
+ LANGUAGE = -"C"
+
+ self[self::LANGUAGE] = self
+
+ cxx = Module.new do
+ # Module for C++
+
+ include MakeMakefile
+ extend self
+
+ # :stopdoc:
+
+ CONFTEST_CXX = "#{CONFTEST}.#{config_string('CXX_EXT') || CXX_EXT[0]}"
+
+ TRY_LINK_CXX = config_string('TRY_LINK_CXX') ||
+ ((cmd = TRY_LINK.gsub(/\$\(C(?:C|(FLAGS))\)/, '$(CXX\1)')) != TRY_LINK && cmd) ||
+ "$(CXX) #{OUTFLAG}#{CONFTEST}#{$EXEEXT} $(INCFLAGS) $(CPPFLAGS) " \
+ "$(CXXFLAGS) $(src) $(LIBPATH) $(LDFLAGS) $(ARCH_FLAG) $(LOCAL_LIBS) $(LIBS)"
+
+ def have_devel?
+ unless defined? @have_devel
+ @have_devel = true
+ @have_devel = try_link(MAIN_DOES_NOTHING)
+ end
+ @have_devel
+ end
+
+ def conftest_source
+ CONFTEST_CXX
+ end
+
+ def cc_command(opt="")
+ conf = cc_config(opt)
+ cxx_command(opt, conf)
+ RbConfig::expand("$(CXX) #$INCFLAGS #$CPPFLAGS #$CXXFLAGS #$ARCH_FLAG #{opt} -c #{CONFTEST_CXX}",
+ conf)
+ end
+
+ def cpp_command(outfile, opt="")
+ conf = cpp_config(opt)
+ cxx = cxx_command(opt, conf)
+ cpp = conf['CPP'].sub(/(\A|\s)#{Regexp.quote(conf['CC'])}(?=\z|\s)/) {
+ "#$1#{cxx}"
+ }
+ RbConfig::expand("#{cpp} #$INCFLAGS #$CPPFLAGS #$CXXFLAGS #{opt} #{CONFTEST_CXX} #{outfile}",
+ conf)
+ end
+
+ def link_command(ldflags, *opts)
+ conf = link_config(ldflags, *opts)
+ RbConfig::expand(TRY_LINK_CXX.dup, conf)
+ end
+
+ def cxx_command(opt="", conf = cc_config(opt))
+ cxx = conf['CXX']
+ raise Errno::ENOENT, "C++ compiler not found" if !cxx or cxx == 'false'
+ cxx
+ end
+
+ # :startdoc:
+ end
+
+ cxx::LANGUAGE = -"C++"
+ self[cxx::LANGUAGE] = cxx
end
-include MakeMakefile
+# MakeMakefile::Global = #
+m = Module.new {
+ include(MakeMakefile)
+ private(*MakeMakefile.public_instance_methods(false))
+}
+include m
if not $extmk and /\A(extconf|makefile).rb\z/ =~ File.basename($0)
END {mkmf_failed($0)}