mkmf.rb: use kwargs
This commit is contained in:
parent
c06745fec9
commit
1817d644ee
73
lib/mkmf.rb
73
lib/mkmf.rb
@ -409,16 +409,16 @@ MESSAGE
|
|||||||
# :startdoc:
|
# :startdoc:
|
||||||
|
|
||||||
# call-seq:
|
# call-seq:
|
||||||
# xsystem(command, werror: false, **opts) -> true or false
|
# xsystem(command, werror: false) -> true or false
|
||||||
#
|
#
|
||||||
# Executes _command_ with expanding variables, and returns the exit
|
# Executes _command_ with expanding variables, and returns the exit
|
||||||
# status like as Kernel#system. If _werror_ is true and the error
|
# status like as Kernel#system. If _werror_ is true and the error
|
||||||
# output is not empty, returns +false+. The output will logged.
|
# output is not empty, returns +false+. The output will logged.
|
||||||
def xsystem command, opts = nil
|
def xsystem(command, werror: false)
|
||||||
env, command = expand_command(command)
|
env, command = expand_command(command)
|
||||||
Logging::open do
|
Logging::open do
|
||||||
puts [env_quote(env), command.quote].join(' ')
|
puts [env_quote(env), command.quote].join(' ')
|
||||||
if opts and opts[:werror]
|
if werror
|
||||||
result = nil
|
result = nil
|
||||||
Logging.postpone do |log|
|
Logging.postpone do |log|
|
||||||
output = IO.popen(env, command, &:read)
|
output = IO.popen(env, command, &:read)
|
||||||
@ -501,7 +501,7 @@ EOM
|
|||||||
$have_devel
|
$have_devel
|
||||||
end
|
end
|
||||||
|
|
||||||
def try_do(src, command, *opts, &b)
|
def try_do(src, command, **opts, &b)
|
||||||
unless have_devel?
|
unless have_devel?
|
||||||
raise <<MSG
|
raise <<MSG
|
||||||
The compiler failed to generate an executable file.
|
The compiler failed to generate an executable file.
|
||||||
@ -510,7 +510,7 @@ MSG
|
|||||||
end
|
end
|
||||||
begin
|
begin
|
||||||
src = create_tmpsrc(src, &b)
|
src = create_tmpsrc(src, &b)
|
||||||
xsystem(command, *opts)
|
xsystem(command, **opts)
|
||||||
ensure
|
ensure
|
||||||
log_src(src)
|
log_src(src)
|
||||||
end
|
end
|
||||||
@ -571,18 +571,17 @@ MSG
|
|||||||
}.join
|
}.join
|
||||||
end
|
end
|
||||||
|
|
||||||
def with_werror(opt, opts = nil)
|
def werror_flag(opt = nil)
|
||||||
if opts
|
config_string("WERRORFLAG") {|flag| opt = opt && !opt.empty? ? "#{opt} #{flag}" : flag}
|
||||||
if opts[:werror] and config_string("WERRORFLAG") {|flag| opt = opt ? "#{opt} #{flag}" : flag}
|
opt
|
||||||
(opts = opts.dup).delete(:werror)
|
|
||||||
end
|
|
||||||
yield(opt, opts)
|
|
||||||
else
|
|
||||||
yield(opt)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def try_link0(src, opt="", *opts, &b) # :nodoc:
|
def with_werror(opt, opts = nil)
|
||||||
|
opt = werror_flag(opt) if opts and (opts = opts.dup).delete(:werror)
|
||||||
|
yield(opt, opts)
|
||||||
|
end
|
||||||
|
|
||||||
|
def try_link0(src, opt = "", **opts, &b) # :nodoc:
|
||||||
exe = CONFTEST+$EXEEXT
|
exe = CONFTEST+$EXEEXT
|
||||||
cmd = link_command("", opt)
|
cmd = link_command("", opt)
|
||||||
if $universal
|
if $universal
|
||||||
@ -590,13 +589,13 @@ MSG
|
|||||||
Dir.mktmpdir("mkmf_", oldtmpdir = ENV["TMPDIR"]) do |tmpdir|
|
Dir.mktmpdir("mkmf_", oldtmpdir = ENV["TMPDIR"]) do |tmpdir|
|
||||||
begin
|
begin
|
||||||
ENV["TMPDIR"] = tmpdir
|
ENV["TMPDIR"] = tmpdir
|
||||||
try_do(src, cmd, *opts, &b)
|
try_do(src, cmd, **opts, &b)
|
||||||
ensure
|
ensure
|
||||||
ENV["TMPDIR"] = oldtmpdir
|
ENV["TMPDIR"] = oldtmpdir
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
try_do(src, cmd, *opts, &b)
|
try_do(src, cmd, **opts, &b)
|
||||||
end and File.executable?(exe) or return nil
|
end and File.executable?(exe) or return nil
|
||||||
exe
|
exe
|
||||||
ensure
|
ensure
|
||||||
@ -613,8 +612,8 @@ MSG
|
|||||||
#
|
#
|
||||||
# [+src+] a String which contains a C source
|
# [+src+] a String which contains a C source
|
||||||
# [+opt+] a String which contains linker options
|
# [+opt+] a String which contains linker options
|
||||||
def try_link(src, opt="", *opts, &b)
|
def try_link(src, opt = "", **opts, &b)
|
||||||
exe = try_link0(src, opt, *opts, &b) or return false
|
exe = try_link0(src, opt, **opts, &b) or return false
|
||||||
MakeMakefile.rm_f exe
|
MakeMakefile.rm_f exe
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
@ -628,8 +627,9 @@ MSG
|
|||||||
#
|
#
|
||||||
# [+src+] a String which contains a C source
|
# [+src+] a String which contains a C source
|
||||||
# [+opt+] a String which contains compiler options
|
# [+opt+] a String which contains compiler options
|
||||||
def try_compile(src, opt="", *opts, &b)
|
def try_compile(src, opt = "", werror: nil, **opts, &b)
|
||||||
with_werror(opt, *opts) {|_opt, *| try_do(src, cc_command(_opt), *opts, &b)} and
|
opt = werror_flag(opt) if werror
|
||||||
|
try_do(src, cc_command(opt), werror: werror, **opts, &b) and
|
||||||
File.file?("#{CONFTEST}.#{$OBJEXT}")
|
File.file?("#{CONFTEST}.#{$OBJEXT}")
|
||||||
ensure
|
ensure
|
||||||
MakeMakefile.rm_f "#{CONFTEST}*"
|
MakeMakefile.rm_f "#{CONFTEST}*"
|
||||||
@ -644,8 +644,8 @@ MSG
|
|||||||
#
|
#
|
||||||
# [+src+] a String which contains a C source
|
# [+src+] a String which contains a C source
|
||||||
# [+opt+] a String which contains preprocessor options
|
# [+opt+] a String which contains preprocessor options
|
||||||
def try_cpp(src, opt="", *opts, &b)
|
def try_cpp(src, opt = "", **opts, &b)
|
||||||
try_do(src, cpp_command(CPPOUTFILE, opt), *opts, &b) and
|
try_do(src, cpp_command(CPPOUTFILE, opt), **opts, &b) and
|
||||||
File.file?("#{CONFTEST}.i")
|
File.file?("#{CONFTEST}.i")
|
||||||
ensure
|
ensure
|
||||||
MakeMakefile.rm_f "#{CONFTEST}*"
|
MakeMakefile.rm_f "#{CONFTEST}*"
|
||||||
@ -679,8 +679,8 @@ MSG
|
|||||||
end
|
end
|
||||||
|
|
||||||
# :nodoc:
|
# :nodoc:
|
||||||
def try_cppflags(flags, opts = {})
|
def try_cppflags(flags, werror: true, **opts)
|
||||||
try_header(MAIN_DOES_NOTHING, flags, {:werror => true}.update(opts))
|
try_header(MAIN_DOES_NOTHING, flags, werror: werror, **opts)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Check whether each given C preprocessor flag is acceptable and append it
|
# Check whether each given C preprocessor flag is acceptable and append it
|
||||||
@ -688,10 +688,10 @@ MSG
|
|||||||
#
|
#
|
||||||
# [+flags+] a C preprocessor flag as a +String+ or an +Array+ of them
|
# [+flags+] a C preprocessor flag as a +String+ or an +Array+ of them
|
||||||
#
|
#
|
||||||
def append_cppflags(flags, *opts)
|
def append_cppflags(flags, **opts)
|
||||||
Array(flags).each do |flag|
|
Array(flags).each do |flag|
|
||||||
if checking_for("whether #{flag} is accepted as CPPFLAGS") {
|
if checking_for("whether #{flag} is accepted as CPPFLAGS") {
|
||||||
try_cppflags(flag, *opts)
|
try_cppflags(flag, **opts)
|
||||||
}
|
}
|
||||||
$CPPFLAGS << " " << flag
|
$CPPFLAGS << " " << flag
|
||||||
end
|
end
|
||||||
@ -710,8 +710,8 @@ MSG
|
|||||||
end
|
end
|
||||||
|
|
||||||
# :nodoc:
|
# :nodoc:
|
||||||
def try_cflags(flags, opts = {})
|
def try_cflags(flags, werror: true, **opts)
|
||||||
try_compile(MAIN_DOES_NOTHING, flags, {:werror => true}.update(opts))
|
try_compile(MAIN_DOES_NOTHING, flags, werror: werror, **opts)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Sets <tt>$LDFLAGS</tt> to _flags_ and yields. If the block returns a
|
# Sets <tt>$LDFLAGS</tt> to _flags_ and yields. If the block returns a
|
||||||
@ -726,9 +726,8 @@ MSG
|
|||||||
end
|
end
|
||||||
|
|
||||||
# :nodoc:
|
# :nodoc:
|
||||||
def try_ldflags(flags, opts = {})
|
def try_ldflags(flags, werror: $mswin, **opts)
|
||||||
opts = {:werror => true}.update(opts) if $mswin
|
try_link(MAIN_DOES_NOTHING, flags, werror: werror, **opts)
|
||||||
try_link(MAIN_DOES_NOTHING, flags, opts)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# :startdoc:
|
# :startdoc:
|
||||||
@ -738,10 +737,10 @@ MSG
|
|||||||
#
|
#
|
||||||
# [+flags+] a linker flag as a +String+ or an +Array+ of them
|
# [+flags+] a linker flag as a +String+ or an +Array+ of them
|
||||||
#
|
#
|
||||||
def append_ldflags(flags, *opts)
|
def append_ldflags(flags, **opts)
|
||||||
Array(flags).each do |flag|
|
Array(flags).each do |flag|
|
||||||
if checking_for("whether #{flag} is accepted as LDFLAGS") {
|
if checking_for("whether #{flag} is accepted as LDFLAGS") {
|
||||||
try_ldflags(flag, *opts)
|
try_ldflags(flag, **opts)
|
||||||
}
|
}
|
||||||
$LDFLAGS << " " << flag
|
$LDFLAGS << " " << flag
|
||||||
end
|
end
|
||||||
@ -1082,10 +1081,10 @@ SRC
|
|||||||
#
|
#
|
||||||
# [+flags+] a C compiler flag as a +String+ or an +Array+ of them
|
# [+flags+] a C compiler flag as a +String+ or an +Array+ of them
|
||||||
#
|
#
|
||||||
def append_cflags(flags, *opts)
|
def append_cflags(flags, **opts)
|
||||||
Array(flags).each do |flag|
|
Array(flags).each do |flag|
|
||||||
if checking_for("whether #{flag} is accepted as CFLAGS") {
|
if checking_for("whether #{flag} is accepted as CFLAGS") {
|
||||||
try_cflags(flag, *opts)
|
try_cflags(flag, **opts)
|
||||||
}
|
}
|
||||||
$CFLAGS << " " << flag
|
$CFLAGS << " " << flag
|
||||||
end
|
end
|
||||||
@ -1537,7 +1536,7 @@ SRC
|
|||||||
u = "unsigned " if signed > 0
|
u = "unsigned " if signed > 0
|
||||||
prelude << "extern rbcv_typedef_ foo();"
|
prelude << "extern rbcv_typedef_ foo();"
|
||||||
compat = UNIVERSAL_INTS.find {|t|
|
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
|
end
|
||||||
if compat
|
if compat
|
||||||
|
Loading…
x
Reference in New Issue
Block a user