aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog19
-rw-r--r--configure.in3
-rw-r--r--lib/mkmf.rb57
-rw-r--r--win32/Makefile.sub4
4 files changed, 63 insertions, 20 deletions
diff --git a/ChangeLog b/ChangeLog
index 606cf291dd..9af75f0b22 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,22 @@
+Tue Dec 7 08:00:44 2010 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * 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.
+
Sun Dec 5 10:32:11 2010 Tanaka Akira <akr@fsij.org>
* cont.c: parenthesize macro arguments.
diff --git a/configure.in b/configure.in
index a80241b4e7..26ab9749aa 100644
--- a/configure.in
+++ b/configure.in
@@ -454,8 +454,7 @@ if test "$GCC:${warnflags+set}:no" = yes::no; then
fi
if test "$GCC" = yes; then
RUBY_TRY_CFLAGS(-fvisibility=hidden, [RUBY_APPEND_OPTION(XCFLAGS, -fvisibility=hidden)])
-fi
-if test "$GCC" = yes; then
+ AC_SUBST(WERRORFLAG, "-Werror")
if test "$visibility_option" = yes; then
RUBY_APPEND_OPTION(XCFLAGS, -fvisibility=hidden)
else
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|
diff --git a/win32/Makefile.sub b/win32/Makefile.sub
index 704d9609b3..134cd424c8 100644
--- a/win32/Makefile.sub
+++ b/win32/Makefile.sub
@@ -189,11 +189,12 @@ COMPILERFLAG = -Zm600
!endif
!if !defined(WARNFLAGS)
!if $(MSC_VER) >= 1400
-WARNFLAGS = -W2 -wd4996
+WARNFLAGS = -W2 -wd4996 -we4028 -we4142
!else
WARNFLAGS = -W2
!endif
!endif
+WERRORFLAG = -WX
!if !defined(CFLAGS)
CFLAGS = $(RUNTIMEFLAG) $(DEBUGFLAGS) $(WARNFLAGS) $(OPTFLAGS) $(PROCESSOR_FLAG) $(COMPILERFLAG)
!endif
@@ -679,6 +680,7 @@ s,@SHELL@,$$(COMSPEC),;t t
s,@BUILD_FILE_SEPARATOR@,\,;t t
s,@PATH_SEPARATOR@,;,;t t
s,@CFLAGS@,$(CFLAGS),;t t
+s,@WERRORFLAG@,$(WERRORFLAG),;t t
s,@DEFS@,$(DEFS),;t t
s,@CPPFLAGS@,$(CPPFLAGS),;t t
s,@CXXFLAGS@,$(CXXFLAGS),;t t