aboutsummaryrefslogtreecommitdiffstats
path: root/lib/mkmf.rb
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-12-06 23:00:47 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-12-06 23:00:47 +0000
commite806b0fed77d94ea426bfc0269ab3b01feaf218c (patch)
tree5aa43038a1abc563e3c2d7d8c809d6ca1938a9c2 /lib/mkmf.rb
parent75877a30a49708d6bd2a883b1bb066aacb76f111 (diff)
downloadruby-e806b0fed77d94ea426bfc0269ab3b01feaf218c.tar.gz
* configure.in, win32/Makefile.sub (WERRORFLAG): flag to treat
warnings as errors. * lib/mkmf.rb (Logging.postpone): yield log file object. * lib/mkmf.rb (xsystem): add options, :werror only right now. * lib/mkmf.rb (with_werror): check as if warnings are errors. * lib/mkmf.rb (convertible_int): make declaration conflict warnings errors not to pass wrong type. [ruby-dev:42684] * lib/mkmf.rb (COMMON_MACROS): get rid of conflicts. * win32/Makefile.sub (WARNFLAGS): make declaration conflict warnings errors if possible. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@30107 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/mkmf.rb')
-rw-r--r--lib/mkmf.rb57
1 files changed, 40 insertions, 17 deletions
diff --git a/lib/mkmf.rb b/lib/mkmf.rb
index 02e0b4bc2b..3e02886f67 100644
--- a/lib/mkmf.rb
+++ b/lib/mkmf.rb
@@ -277,9 +277,9 @@ module Logging
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 if @log
+ @log.close if @log and not @log.closed?
File::open(tmplog) {|t| FileUtils.copy_stream(t, log)}
@log, @logfile, @orgout, @orgerr = log, *save
@postpone -= 1
@@ -293,7 +293,7 @@ module Logging
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]}
@@ -302,7 +302,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
@@ -360,7 +369,7 @@ 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 compiler failed to generate an executable file.
@@ -369,7 +378,7 @@ MSG
end
begin
src = create_tmpsrc(src, &b)
- xsystem(command)
+ xsystem(command, *opts)
ensure
log_src(src)
rm_rf 'conftest.dSYM'
@@ -419,21 +428,32 @@ def libpathflag(libpath=$DEFLIBPATH|$LIBPATH)
}.join
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
+end
+
# :nodoc:
-def try_link0(src, opt="", &b)
+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
@@ -447,8 +467,8 @@ end
#
# [+src+] a String which contains a C source
# [+opt+] a String which contains linker options
-def try_link(src, opt="", &b)
- try_link0(src, opt, &b)
+def try_link(src, opt="", *opts, &b)
+ try_link0(src, opt, *opts, &b)
ensure
rm_f "conftest*", "c0x32*"
end
@@ -462,8 +482,8 @@ end
#
# [+src+] a String which contains a C source
# [+opt+] a String which contains compiler options
-def try_compile(src, opt="", &b)
- try_do(src, cc_command(opt), &b)
+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
@@ -477,8 +497,8 @@ end
#
# [+src+] a String which contains a C source
# [+opt+] a String which contains preprocessor options
-def try_cpp(src, opt="", &b)
- try_do(src, cpp_command(CPPOUTFILE, opt), &b)
+def try_cpp(src, opt="", *opts, &b)
+ try_do(src, cpp_command(CPPOUTFILE, opt), *opts, &b)
ensure
rm_f "conftest*"
end
@@ -1185,7 +1205,7 @@ def convertible_int(type, headers = nil, opts = nil, &b)
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, &b)
+ try_compile([prelude, "extern #{u}#{t} foo();"].join("\n"), opts, :werror=>true, &b)
}
if compat
macname ||= type.sub(/_(?=t\z)/, '').tr_cpp
@@ -2184,7 +2204,10 @@ EXPORT_PREFIX = config_string('EXPORT_PREFIX') {|s| s.strip}
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|