* ext/curses/extconf.rb: refactored.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@34747 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
akr 2012-02-22 12:45:04 +00:00
Родитель c01d52e8d9
Коммит 7c80d15165
2 изменённых файлов: 23 добавлений и 19 удалений

Просмотреть файл

@ -1,3 +1,7 @@
Wed Feb 22 21:44:29 2012 Tanaka Akira <akr@fsij.org>
* ext/curses/extconf.rb: refactored.
Wed Feb 22 20:42:28 2012 Tanaka Akira <akr@fsij.org>
* ext/curses/extconf.rb: try to distinguish curses_version is a

Просмотреть файл

@ -1,26 +1,24 @@
require 'mkmf'
def transact
def have_all(*args)
old_libs = $libs.dup
old_defs = $defs.dup
result = yield
if !result
$libs = old_libs
$defs = old_defs
end
result
end
def check_header_library(hdr, libs)
if !have_header(hdr)
return nil
end
libs.each {|lib|
if have_library(lib, "initscr")
return [hdr, lib]
result = []
begin
args.each {|arg|
r = arg.call(*result)
if !r
return nil
end
result << r
}
result
ensure
if result.length != args.length
$libs = old_libs
$defs = old_defs
end
}
nil
end
end
dir_config('curses')
@ -37,7 +35,9 @@ header_library = nil
["curses_colr/curses.h", ["cur_colr"]],
["curses.h", ["curses"]],
].each {|hdr, libs|
header_library = transact { check_header_library(hdr, libs) }
header_library = have_all(
lambda { have_header(hdr) && hdr },
lambda {|h| libs.find {|lib| have_library(lib, "initscr", h) } })
if header_library
break;
end