Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Updated mkmf.rb to 1.9.3p0.

  • Loading branch information...
commit 6eef7ad843c46e5d3b54988e863faa55abb4084f 1 parent 43fc76b
@brixen brixen authored
Showing with 315 additions and 94 deletions.
  1. +315 −94 lib/19/mkmf.rb
View
409 lib/19/mkmf.rb
@@ -9,13 +9,14 @@
CONFIG = RbConfig::MAKEFILE_CONFIG
ORIG_LIBPATH = ENV['LIB']
-CXX_EXT = %w[cc cxx cpp]
+C_EXT = %w[c m]
+CXX_EXT = %w[cc mm cxx cpp]
if File::FNM_SYSCASE.zero?
CXX_EXT.concat(%w[C])
end
-SRC_EXT = %w[c m].concat(CXX_EXT)
+SRC_EXT = C_EXT + CXX_EXT
$static = nil
-$config_h = '$(hdrdir)/config.h'
+$config_h = '$(arch_hdrdir)/ruby/config.h'
$default_static = $static
unless defined? $configure_args
@@ -187,7 +188,7 @@ def quote
# Generates a string used as cpp macro name.
def tr_cpp
- strip.upcase.tr_s("^A-Z0-9_", "_")
+ strip.upcase.tr_s("^A-Z0-9_*", "_").tr_s("*", "P")
end
end
class Array
@@ -267,6 +268,10 @@ def self::message(*s)
def self::logfile file
@logfile = file
+ log_close
+ end
+
+ def self::log_close
if @log and not @log.closed?
@log.flush
@log.close
@@ -280,10 +285,10 @@ def self::postpone
log, *save = @log, @logfile, @orgout, @orgerr
@log, @logfile, @orgout, @orgerr = nil, tmplog, log, log
begin
- log.print(open {yield})
+ log.print(open {yield @log})
ensure
- @log.close
- File::open(tmplog) {|t| FileUtils.copy_stream(t, log)}
+ @log.close if @log and not @log.closed?
+ File::open(tmplog) {|t| FileUtils.copy_stream(t, log)} if File.exist?(tmplog)
@log, @logfile, @orgout, @orgerr = log, *save
@postpone -= 1
rm_f tmplog
@@ -296,7 +301,7 @@ class << self
end
end
-def xsystem command
+def xsystem command, opts = nil
varpat = /\$\((\w+)\)|\$\{(\w+)\}/
if varpat =~ command
vars = Hash.new {|h, k| h[k] = ''; ENV[k]}
@@ -305,7 +310,16 @@ def xsystem command
end
Logging::open do
puts command.quote
- system(command)
+ if opts and opts[:werror]
+ result = nil
+ Logging.postpone do |log|
+ result = (system(command) and File.zero?(log.path))
+ ""
+ end
+ result
+ else
+ system(command)
+ end
end
end
@@ -363,16 +377,16 @@ def have_devel?
$have_devel
end
-def try_do(src, command, &b)
+def try_do(src, command, *opts, &b)
unless have_devel?
raise <<MSG
-The complier failed to generate an executable file.
+The compiler failed to generate an executable file.
You have to install development tools first.
MSG
end
begin
src = create_tmpsrc(src, &b)
- xsystem(command)
+ xsystem(command, *opts)
ensure
log_src(src)
rm_rf 'conftest.dSYM'
@@ -380,35 +394,36 @@ def try_do(src, command, &b)
end
def link_command(ldflags, opt="", libpath=$DEFLIBPATH|$LIBPATH)
+ librubyarg = $extmk ? $LIBRUBYARG_STATIC : "$(LIBRUBYARG)"
conf = RbConfig::CONFIG.merge('hdrdir' => $hdrdir.quote,
'src' => "#{CONFTEST_C}",
- 'arch_hdrdir' => "#$arch_hdrdir",
+ 'arch_hdrdir' => $arch_hdrdir.quote,
'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")
+ 'LIBS' => "#{librubyarg} #{opt} #$LIBS")
+ conf['LIBPATH'] = libpathflag(libpath.map {|s| RbConfig::expand(s.dup, conf)})
RbConfig::expand(TRY_LINK.dup, conf)
end
def cc_command(opt="")
conf = RbConfig::CONFIG.merge('hdrdir' => $hdrdir.quote, 'srcdir' => $srcdir.quote,
- 'arch_hdrdir' => "#$arch_hdrdir",
+ 'arch_hdrdir' => $arch_hdrdir.quote,
'top_srcdir' => $top_srcdir.quote)
RbConfig::expand("$(CC) #$INCFLAGS #$CPPFLAGS #$CFLAGS #$ARCH_FLAG #{opt} -c #{CONFTEST_C}",
- conf)
+ conf)
end
def cpp_command(outfile, opt="")
conf = RbConfig::CONFIG.merge('hdrdir' => $hdrdir.quote, 'srcdir' => $srcdir.quote,
- 'arch_hdrdir' => "#$arch_hdrdir",
+ 'arch_hdrdir' => $arch_hdrdir.quote,
'top_srcdir' => $top_srcdir.quote)
RbConfig::expand("$(CPP) #$INCFLAGS #$CPPFLAGS #$CFLAGS #{opt} #{CONFTEST_C} #{outfile}",
- conf)
+ conf)
end
def libpathflag(libpath=$DEFLIBPATH|$LIBPATH)
@@ -422,37 +437,77 @@ def libpathflag(libpath=$DEFLIBPATH|$LIBPATH)
}.join
end
-def try_link0(src, opt="", &b)
+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
+end
+
+# :nodoc:
+def try_link0(src, opt="", *opts, &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)
+ try_do(src, cmd, *opts, &b)
ensure
ENV["TMPDIR"] = oldtmpdir
end
end
else
- try_do(src, cmd, &b)
+ try_do(src, cmd, *opts, &b)
end
end
-def try_link(src, opt="", &b)
- try_link0(src, opt, &b)
+# 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.
+#
+# 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
rm_f "conftest*", "c0x32*"
end
-def try_compile(src, opt="", &b)
- try_do(src, cc_command(opt), &b)
+# 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.
+#
+# 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)}
ensure
rm_f "conftest*"
end
-def try_cpp(src, opt="", &b)
- try_do(src, cpp_command(CPPOUTFILE, opt), &b)
+# 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.
+#
+# 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)
ensure
rm_f "conftest*"
end
@@ -550,15 +605,28 @@ def try_constant(const, headers = nil, opt = "", &b)
nil
end
+# You should use +have_func+ rather than +try_func+.
+#
+# [+func+] a String which contains a symbol name
+# [+libs+] a String which contains library names.
+# [+headers+] a String or an Array of strings which contains
+# names of header files.
def try_func(func, libs, headers = nil, &b)
headers = cpp_include(headers)
+ case func
+ when /^&/
+ decltype = proc {|x|"const volatile void *#{x}"}
+ else
+ call = true
+ decltype = proc {|x| "void ((*#{x})())"}
+ end
try_link(<<"SRC", libs, &b) or
#{headers}
/*top*/
#{MAIN_DOES_NOTHING}
-int t() { void ((*volatile p)()); p = (void ((*)()))#{func}; return 0; }
+int t() { #{decltype["volatile p"]}; p = (#{decltype[]})#{func}; return 0; }
SRC
- try_link(<<"SRC", libs, &b)
+ call && try_link(<<"SRC", libs, &b)
#{headers}
/*top*/
#{MAIN_DOES_NOTHING}
@@ -566,6 +634,7 @@ def try_func(func, libs, headers = nil, &b)
SRC
end
+# You should use +have_var+ rather than +try_var+.
def try_var(var, headers = nil, &b)
headers = cpp_include(headers)
try_compile(<<"SRC", &b)
@@ -576,24 +645,37 @@ def try_var(var, headers = nil, &b)
SRC
end
+# Returns whether or not the +src+ can be preprocessed with the C preprocessor and
+# matches with +pat+.
+#
+# If a block given, it is called with the source before compilation. You can
+# modify the source in the block.
+#
+# [+pat+] a Regexp or a String
+# [+src+] a String which contains a C source
+# [+opt+] a String which contains preprocessor options
+#
+# Note:
+# When pat is a Regexp the matching will be checked in process,
+# otherwise egrep(1) will be invoked to check it.
def egrep_cpp(pat, src, opt = "", &b)
src = create_tmpsrc(src, &b)
xpopen(cpp_command('', opt)) do |f|
if Regexp === pat
puts(" ruby -ne 'print if #{pat.inspect}'")
f.grep(pat) {|l|
- puts "#{f.lineno}: #{l}"
- return true
+ puts "#{f.lineno}: #{l}"
+ return true
}
false
else
puts(" egrep '#{pat}'")
begin
- stdin = $stdin.dup
- $stdin.reopen(f)
- system("egrep", pat)
+ stdin = $stdin.dup
+ $stdin.reopen(f)
+ system("egrep", pat)
ensure
- $stdin.reopen(stdin)
+ $stdin.reopen(stdin)
end
end
end
@@ -614,6 +696,22 @@ def macro_defined?(macro, src, opt = "", &b)
SRC
end
+# Returns whether or not
+# * the +src+ can be compiled as a C source,
+# * the result object can be linked with its depending libraries successfully,
+# * 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.
+#
+# 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
+#
+# @return true when the executable exits successfully, false when it fails, or
+# nil when preprocessing, compilation or link fails.
def try_run(src, opt = "", &b)
if try_link0(src, opt, &b)
xsystem("./conftest")
@@ -774,11 +872,11 @@ def find_library(lib, func, *paths, &b)
libs = append_library($libs, lib)
begin
until r = try_func(func, libs, &b) or paths.empty?
- $LIBPATH = libpath | [paths.shift]
+ $LIBPATH = libpath | [paths.shift]
end
if r
- $libs = libs
- libpath = nil
+ $libs = libs
+ libpath = nil
end
ensure
$LIBPATH = libpath if libpath
@@ -843,6 +941,26 @@ def have_header(header, preheaders = nil, &b)
end
end
+# Returns whether or not the given +framework+ can be found on your system.
+# If found, a macro is passed as a preprocessor constant to the compiler using
+# the framework name, in uppercase, prepended with 'HAVE_FRAMEWORK_'.
+#
+# For example, if have_framework('Ruby') returned true, then the HAVE_FRAMEWORK_RUBY
+# preprocessor macro would be passed to the compiler.
+#
+def have_framework(fw, &b)
+ checking_for fw do
+ src = cpp_include("#{fw}/#{fw}.h") << "\n" "int main(void){return 0;}"
+ if try_link(src, opt = "-framework #{fw}", &b)
+ $defs.push(format("-DHAVE_FRAMEWORK_%s", fw.tr_cpp))
+ $LDFLAGS << " " << opt
+ true
+ else
+ false
+ end
+ end
+end
+
# Instructs mkmf to search for the given +header+ in any of the +paths+
# provided, and returns whether or not it was found in those paths.
#
@@ -900,6 +1018,10 @@ def have_struct_member(type, member, headers = nil, &b)
end
end
+# Returns whether or not the static type +type+ is defined.
+#
+# See also +have_type+
+#
def try_type(type, headers = nil, opt = "", &b)
if try_compile(<<"SRC", opt, &b)
#{cpp_include(headers)}
@@ -953,6 +1075,10 @@ def fmt.%(x)
end
end
+# Returns whether or not the Constant +const+ is defined.
+#
+# See also +have_const+
+#
def try_const(const, headers = nil, opt = "", &b)
const, type = *const
if try_compile(<<"SRC", opt, &b)
@@ -995,6 +1121,23 @@ def have_const(const, headers = nil, opt = "", &b)
def STRING_OR_FAILED_FORMAT.%(x)
x ? super : "failed"
end
+
+def typedef_expr(type, headers)
+ typename, member = type.split('.', 2)
+ prelude = cpp_include(headers).split(/$/)
+ prelude << "typedef #{typename} rbcv_typedef_;\n"
+ return "rbcv_typedef_", member, prelude
+end
+
+def try_signedness(type, member, headers = nil, opts = nil, &b)
+ raise ArgumentError, "don't know how to tell signedness of members" if member
+ if try_static_assert("(#{type})-1 < 0", headers, opts)
+ return -1
+ elsif try_static_assert("(#{type})-1 > 0", headers, opts)
+ return +1
+ end
+end
+
# :startdoc:
# Returns the size of the given +type+. You may optionally specify additional
@@ -1008,22 +1151,13 @@ def STRING_OR_FAILED_FORMAT.%(x)
# SIZEOF_MYSTRUCT=12 preprocessor macro would be passed to the compiler.
#
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"
+ typedef, member, prelude = typedef_expr(type, headers)
+ prelude << "static #{typedef} *rbcv_ptr_;\n"
prelude = [prelude]
expr = "sizeof((*rbcv_ptr_)#{"." << member if member})"
fmt = STRING_OR_FAILED_FORMAT
checking_for checking_message("size of #{type}", headers), fmt do
- 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)
+ if size = try_constant(expr, prelude, opts, &b)
$defs.push(format("-DSIZEOF_%s=%s", type.tr_cpp, size))
size
end
@@ -1045,22 +1179,65 @@ def check_sizeof(type, headers = nil, opts = "", &b)
# compiler, and SIGNEDNESS_OF_INT=-1 if check_signedness('int') is
# done.
#
-def check_signedness(type, headers = nil)
+def check_signedness(type, headers = nil, opts = nil, &b)
+ typedef, member, prelude = typedef_expr(type, headers)
signed = nil
checking_for("signedness of #{type}", STRING_OR_FAILED_FORMAT) do
- if try_static_assert("(#{type})-1 < 0")
- signed = -1
- elsif try_static_assert("(#{type})-1 > 0")
- signed = +1
- else
- next nil
- end
+ signed = try_signedness(typedef, member, [prelude], opts, &b) or next nil
$defs.push("-DSIGNEDNESS_OF_%s=%+d" % [type.tr_cpp, signed])
signed < 0 ? "signed" : "unsigned"
end
signed
end
+# Returns the convertible integer type of the given +type+. You may
+# optionally specify additional +headers+ to search in for the +type+.
+# _Convertible_ means actually same type, or typedefed from same type.
+#
+# If the +type+ is a integer type and _convertible_ type is found,
+# following macros are passed as preprocessor constants to the
+# compiler using the +type+ name, in uppercase.
+#
+# * 'TYPEOF_', followed by the +type+ name, followed by '=X' where 'X'
+# is the found _convertible_ type name. * 'TYP2NUM' and 'NUM2TYP,
+# where 'TYP' is the +type+ name in uppercase with replacing '_t'
+# suffix with 'T', followed by '=X' where 'X' is the macro name to
+# convert +type+ to +Integer+ object, and vice versa.
+#
+# For example, if foobar_t is defined as unsigned long, then
+# convertible_int("foobar_t") would return "unsigned long", and define
+# macros:
+#
+# #define TYPEOF_FOOBAR_T unsigned long
+# #define FOOBART2NUM ULONG2NUM
+# #define NUM2FOOBART NUM2ULONG
+def convertible_int(type, headers = nil, opts = nil, &b)
+ type, macname = *type
+ checking_for("convertible type of #{type}", STRING_OR_FAILED_FORMAT) do
+ if UNIVERSAL_INTS.include?(type)
+ type
+ else
+ typedef, member, prelude = typedef_expr(type, headers, &b)
+ next unless signed = try_signedness(typedef, member, [prelude])
+ 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)
+ }
+ if compat
+ macname ||= type.sub(/_(?=t\z)/, '').tr_cpp
+ conv = (compat == "long long" ? "LL" : compat.upcase)
+ compat = "#{u}#{compat}"
+ $defs.push(format("-DTYPEOF_%s=%s", type.tr_cpp, compat.quote))
+ $defs.push(format("-DPRI_%s_PREFIX=PRI_%s_PREFIX", macname, conv))
+ conv = (u ? "U" : "") + conv
+ $defs.push(format("-D%s2NUM=%s2NUM", macname, conv))
+ $defs.push(format("-DNUM2%s=NUM2%s", macname, conv))
+ compat
+ end
+ end
+ end
+end
# :stopdoc:
# Used internally by the what_type? method to determine if +type+ is a scalar
@@ -1163,11 +1340,20 @@ def fmt.%(x)
# Internal use only.
#
def find_executable0(bin, path = nil)
+ executable_file = proc do |name|
+ begin
+ stat = File.stat(name)
+ rescue SystemCallError
+ else
+ next name if stat.file? and stat.executable?
+ end
+ end
+
exts = config_string('EXECUTABLE_EXTS') {|s| s.split} || config_string('EXEEXT') {|s| [s]}
if File.expand_path(bin) == bin
- return bin if File.executable?(bin)
+ return bin if executable_file.call(bin)
if exts
- exts.each {|ext| File.executable?(file = bin + ext) and return file}
+ exts.each {|ext| executable_file.call(file = bin + ext) and return file}
end
return nil
end
@@ -1178,9 +1364,9 @@ def find_executable0(bin, path = nil)
end
file = nil
path.each do |dir|
- return file if File.executable?(file = File.join(dir, bin))
+ return file if executable_file.call(file = File.join(dir, bin))
if exts
- exts.each {|ext| File.executable?(ext = file + ext) and return ext}
+ exts.each {|ext| executable_file.call(ext = file + ext) and return ext}
end
end
nil
@@ -1455,16 +1641,24 @@ def configuration(srcdir)
mk << %{
SHELL = /bin/sh
+# V=0 quiet, V=1 verbose. other values don't work.
+V = 0
+Q1 = $(V:1=)
+Q = $(Q1:0=@)
+n=$(NULLCMD)
+ECHO1 = $(V:1=@$n)
+ECHO = $(ECHO1:0=@echo)
+
#### 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])}.quote}
topdir = #{mkintpath($extmk ? CONFIG["topdir"] : $topdir).quote}
hdrdir = #{mkintpath(CONFIG["hdrdir"]).quote}
-arch_hdrdir = #{$arch_hdrdir}
+arch_hdrdir = #{$arch_hdrdir.quote}
VPATH = #{vpath.join(CONFIG['PATH_SEPARATOR'])}
}
if $extmk
- mk << "RUBYLIB = -\nRUBYOPT = -r$(top_srcdir)/ext/purelib.rb\n"
+ mk << "RUBYLIB =\n""RUBYOPT = -\n"
end
if destdir = CONFIG["prefix"][$dest_prefix_pattern, 1]
mk << "\nDESTDIR = #{destdir}\n"
@@ -1488,6 +1682,8 @@ def configuration(srcdir)
possible_command = (proc {|s| s if /top_srcdir/ !~ s} unless $extmk)
extconf_h = $extconf_h ? "-DRUBY_EXTCONF_H=\\\"$(RUBY_EXTCONF_H)\\\" " : $defs.join(" ") << " "
mk << %{
+NULLCMD = #{CONFIG['NULLCMD']}
+
CC = #{CONFIG['CC']}
CXX = #{CONFIG['CXX']}
LIBRUBY = #{CONFIG['LIBRUBY']}
@@ -1501,7 +1697,7 @@ def configuration(srcdir)
cflags = #{CONFIG['cflags']}
optflags = #{CONFIG['optflags']}
debugflags = #{CONFIG['debugflags']}
-warnflags = #{CONFIG['warnflags']}
+warnflags = #{$warnflags}
CFLAGS = #{$static ? '' : CONFIG['CCDLFLAGS']} #$CFLAGS #$ARCH_FLAG
INCFLAGS = -I. #$INCFLAGS
DEFS = #{CONFIG['DEFS']}
@@ -1542,7 +1738,7 @@ def configuration(srcdir)
x.gsub!(/^(MAKEDIRS|INSTALL_(?:PROG|DATA))+\s*=.*\n/) do
"!ifndef " + $1 + "\n" +
$& +
- "!endif\n"
+ "!endif\n"
end
end
end
@@ -1550,6 +1746,8 @@ def configuration(srcdir)
end
# :startdoc:
+# creates a stub Makefile.
+#
def dummy_makefile(srcdir)
configuration(srcdir) << <<RULES << CLEANINGS
CLEANFILES = #{$cleanfiles.join(' ')}
@@ -1562,6 +1760,11 @@ def dummy_makefile(srcdir)
RULES
end
+# Processes the data contents of the "depend" file.
+# Each line of this file is expected to be a file name.
+#
+# Returns the output of findings, in Makefile format.
+#
def depend_rules(depend)
suffixes = []
depout = []
@@ -1591,10 +1794,7 @@ def depend_rules(depend)
depend.each_line do |line|
line.gsub!(/\.o\b/, ".#{$OBJEXT}")
line.gsub!(/\$\((?:hdr|top)dir\)\/config.h/, $config_h)
- # MRI 1.9 puts all the header files in <include>/ruby/
- # Since we build both 1.9 and 1.8 extensions in 1.9 mode, leaving the
- # header files in 1.9 mode the same for now.
- # line.gsub!(%r"\$\(hdrdir\)/(?!ruby(?![^:;/\s]))(?=[-\w]+\.h)", '\&ruby/')
+ 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:/=\\')
@@ -1721,7 +1921,7 @@ def create_makefile(target, srcprefix = nil)
makedef = %{-pe "$_.sub!(/^(?=\\w)/,'#{EXPORT_PREFIX}') unless 1../^EXPORTS$/i"}
end
else
- makedef = %{-e "puts 'EXPORTS', '#{EXPORT_PREFIX}Init_$(TARGET)'"}
+ makedef = %{-e "puts 'EXPORTS', '#{EXPORT_PREFIX}' + 'Init_$(TARGET)'.sub(/\\..*\\z/,'')"}
end
if makedef
$cleanfiles << '$(DEFFILE)'
@@ -1792,9 +1992,11 @@ def create_makefile(target, srcprefix = nil)
s = s.gsub(/(\$\(\w+)(\))/) {$1+sep+$2}
s = s.gsub(/(\$\{\w+)(\})/) {$1+sep+$2}
}
+ rsep = ":#{fsep}=/"
else
fseprepl = proc {|s| s}
sep = ""
+ rsep = ""
end
dirs = []
mfile.print "install: install-so install-rb\n\n"
@@ -1807,12 +2009,12 @@ def create_makefile(target, srcprefix = nil)
if $extout
mfile.print "clean-so::\n"
mfile.print "\t@-$(RM) #{fseprepl[dest]}\n"
- mfile.print "\t@-$(RMDIRS) #{fseprepl[dir]}\n"
+ mfile.print "\t@-$(RMDIRS) #{fseprepl[dir]}#{$ignore_error}\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"
+ mfile.print "\t@echo #{dir}/#{File.basename(f)}>>$(INSTALLED_LIST)\n"
end
end
else
@@ -1826,35 +2028,37 @@ def create_makefile(target, srcprefix = nil)
files = install_files(mfile, i, nil, srcprefix) or next
for dir, *files in files
unless dirs.include?(dir)
- dirs << dir
- mfile.print "pre-install-rb#{sfx}: #{dir}\n"
+ dirs << dir
+ mfile.print "pre-install-rb#{sfx}: #{dir}\n"
end
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")
- mfile.print("\t$(#{$extout ? 'COPY' : 'INSTALL_DATA'}) #{f} $(@D#{sep})\n")
- if defined?($installed_list) and !$extout
- mfile.print("\t@echo #{dest}>>$(INSTALLED_LIST)\n")
- end
+ dest = "#{dir}/#{File.basename(f)}"
+ mfile.print("install-rb#{sfx}: #{dest} #{dir}\n")
+ mfile.print("#{dest}: #{f}\n")
+ mfile.print("\t$(Q) $(#{$extout ? 'COPY' : 'INSTALL_DATA'}) #{f} $(@D#{sep})\n")
+ 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
+ mfile.print "pre-install-rb#{sfx}:\n"
+ mfile.print("\t$(ECHO) installing#{sfx.sub(/^-/, " ")} #{target} libraries\n")
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")
+ mfile.print("\t@-$(RMDIRS) #{fseprepl[dir]}#{$ignore_error}\n")
end
end
end
end
dirs.unshift(sodir) if target and !dirs.include?(sodir)
- dirs.each {|d| mfile.print "#{d}:\n\t$(MAKEDIRS) $@\n"}
+ dirs.each {|d| mfile.print "#{d}:\n\t$(Q) $(MAKEDIRS) $@\n"}
mfile.print <<-SITEINSTALL
@@ -1870,16 +2074,17 @@ def create_makefile(target, srcprefix = nil)
mfile.print ".SUFFIXES: .#{SRC_EXT.join(' .')} .#{$OBJEXT}\n"
mfile.print "\n"
+ compile_command = "\n\t$(ECHO) compiling $(<#{rsep})\n\t$(Q) %s\n\n"
CXX_EXT.each do |e|
COMPILE_RULES.each do |rule|
mfile.printf(rule, e, $OBJEXT)
- mfile.printf("\n\t%s\n\n", COMPILE_CXX)
+ mfile.printf(compile_command, COMPILE_CXX)
end
end
- %w[c].each do |e|
+ C_EXT.each do |e|
COMPILE_RULES.each do |rule|
mfile.printf(rule, e, $OBJEXT)
- mfile.printf("\n\t%s\n\n", COMPILE_C)
+ mfile.printf(compile_command, COMPILE_C)
end
end
@@ -1887,15 +2092,17 @@ def create_makefile(target, srcprefix = nil)
mfile.print "$(DLLIB): "
mfile.print "$(DEFFILE) " if makedef
mfile.print "$(OBJS) Makefile\n"
+ mfile.print "\t$(ECHO) linking shared-object #{target_prefix.sub(/\A\/(.*)/, '\1/')}$(DLLIB)\n"
mfile.print "\t@-$(RM) $(@#{sep})\n"
mfile.print "\t@-$(MAKEDIRS) $(@D)\n" if $extout
- link_so = LINK_SO.gsub(/^/, "\t")
+ link_so = LINK_SO.gsub(/^/, "\t$(Q) ")
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@-$(RM) $(@#{sep})\n\t"
+ 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@-#{ranlib} $(DLLIB) 2> /dev/null || true"
@@ -1904,7 +2111,8 @@ def create_makefile(target, srcprefix = nil)
mfile.print "\n\n"
if makedef
mfile.print "$(DEFFILE): #{origdef}\n"
- mfile.print "\t$(RUBY) #{makedef} #{origdef} > $@\n\n"
+ mfile.print "\t$(ECHO) generating $(@#{rsep})\n"
+ mfile.print "\t$(Q) $(RUBY) #{makedef} #{origdef} > $@\n\n"
end
depend = File.join(srcdir, "depend")
@@ -1927,12 +2135,21 @@ def create_makefile(target, srcprefix = nil)
# :stopdoc:
-def init_mkmf(config = CONFIG)
+def init_mkmf(config = CONFIG, rbconfig = RbConfig::CONFIG)
$makefile_created = false
$arg_config = []
$enable_shared = config['ENABLE_SHARED'] == 'yes'
$defs = []
$extconf_h = nil
+ 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')
+ 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
$CFLAGS = with_config("cflags", arg_config("CFLAGS", config["CFLAGS"])).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
@@ -1952,7 +2169,7 @@ def init_mkmf(config = CONFIG)
$LIBPATH = []
$INSTALLFILES = []
$NONINSTALLFILES = [/~\z/, /\A#.*#\z/, /\A\.#/, /\.bak\z/i, /\.orig\z/, /\.rej\z/, /\.l[ao]\z/, /\.o\z/]
- $VPATH = %w[$(srcdir) $(hdrdir) $(arch_hdrdir)/ruby $(hdrdir)/ruby]
+ $VPATH = %w[$(srcdir) $(arch_hdrdir)/ruby $(hdrdir)/ruby]
$objs = nil
$srcs = nil
@@ -2008,6 +2225,7 @@ def mkmf_failed(path)
when $bccwin
$nmake = ?b if /Borland/i =~ `#{make} -h`
end
+$ignore_error = $nmake ? '' : ' 2> /dev/null || true'
RbConfig::CONFIG["srcdir"] = CONFIG["srcdir"] =
$srcdir = arg_config("--srcdir", File.dirname($0))
@@ -2031,7 +2249,10 @@ def mkmf_failed(path)
hdr = ['#include "ruby.h"' "\n"]
config_string('COMMON_MACROS') do |s|
Shellwords.shellwords(s).each do |w|
- hdr << "#define " + w.split(/=/, 2).join(" ")
+ w, v = w.split(/=/, 2)
+ hdr << "#ifndef #{w}"
+ hdr << "#define #{[w, v].compact.join(" ")}"
+ hdr << "#endif /* #{w} */"
end
end
config_string('COMMON_HEADERS') do |s|
@@ -2075,7 +2296,7 @@ def mkmf_failed(path)
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})
+\t\t@-$(RMDIRS) $(DISTCLEANDIRS#{sep})#{$ignore_error}
realclean: distclean
"
Please sign in to comment.
Something went wrong with that request. Please try again.