Skip to content

Commit

Permalink
Configure checks for readline, curses.
Browse files Browse the repository at this point in the history
  • Loading branch information
Brian Ford committed Nov 5, 2010
1 parent 545162a commit 7b1cb48
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 4 deletions.
50 changes: 48 additions & 2 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,8 @@ class Configure

default_on = RUBY_PLATFORM !~ /openbsd/i
feature "execinfo", default_on
feature "C-readline", true
feature "ruby-readline", false

o.doc "\n Help!"

Expand Down Expand Up @@ -509,15 +511,23 @@ class Configure
ENV[which] || ""
end

def check_program(run=true)
def check_program(run=true, link_libs=[])
begin
basename = "rbx-configure-test"
source = basename + ".cpp"
File.open source, "w" do |f|
yield f
end

`#{@cxx} #{env('CFLAGS')} -lstdc++ -lm -o #{basename} #{source} >>#{@log.path} 2>&1`
if link_libs.empty?
libs = ""
else
libs = link_libs.map { |l| "-l#{l}" }.join(" ")
end

cmd = "#{@cxx} #{env('CFLAGS')} -lstdc++ -lm #{libs} -o #{basename} #{source} >>#{@log.path} 2>&1"
@log.log cmd
system cmd
return $?.exitstatus unless run

unless $?.exitstatus == 0
Expand Down Expand Up @@ -577,6 +587,31 @@ int main() { X x; return 0; }
@log.write @tr1_hash ? "found" : "not found"
end

def detect_curses
@log.print "Checking curses library: "

src = <<-EOP
#include <curses.h>
#include <term.h>
int main() { return tgetnum(""); }
EOP

["curses", "ncurses", "termcap"].each do |lib|
status = check_program(false, [lib]) do |f|
f.puts src
@log.log src
end

if status == 0
@curses = lib
break
end
end

@log.write @curses ? @curses : "not found"
end

def has_function(name, includes=[])
@log.print "Checking for function '#{name}': "
tf = Tempfile.new("rbx-test")
Expand Down Expand Up @@ -610,6 +645,15 @@ int main() { X x; return 0; }
if @features["execinfo"] and has_function("backtrace", ["execinfo.h"])
@defines << "HAS_EXECINFO"
end

if @features["ruby-readline"]
@defines << "USE_RB_READLINE"
end

if @features["C-readline"] and
has_function("readline", ["stdio.h", "stdlib.h", "readline/readline.h"])
@defines << "HAS_READLINE"
end
end

def process
Expand All @@ -626,6 +670,7 @@ int main() { X x; return 0; }
detect_endian
detect_tr1_hash
detect_features
detect_curses
end

def which_ruby
Expand Down Expand Up @@ -680,6 +725,7 @@ module Rubinius
:cc => "#{@cc}",
:cxx => "#{@cxx}",
:defines => #{@defines.inspect},
:curses => #{@curses.inspect},
:host => "#{@host}",
:cpu => "#{@cpu}",
:vendor => "#{@vendor}",
Expand Down
4 changes: 3 additions & 1 deletion lib/ext/readline/Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ else
end

add_shared_lib "readline"
add_shared_lib "curses"
if lib = Rubinius::BUILD_CONFIG[:curses]
add_shared_lib lib
end

readline = "readline.#{$DLEXT}"

Expand Down
3 changes: 2 additions & 1 deletion rakelib/extensions.rake
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,10 @@ def compile_ext(name, opts={})
task task_name do
ext_helper = File.expand_path "../ext_helper.rb", __FILE__
dep_grapher = File.expand_path "../dependency_grapher.rb", __FILE__
build_config = File.expand_path "../../config.rb", __FILE__
Dir.chdir ext_dir do
if File.exists? "Rakefile"
sh "#{BUILD_CONFIG[:build_ruby]} -S #{BUILD_CONFIG[:build_rake]} #{'-t' if $verbose} -r #{ext_helper} -r #{dep_grapher} #{ext_task_name}"
sh "#{BUILD_CONFIG[:build_ruby]} -S #{BUILD_CONFIG[:build_rake]} #{'-t' if $verbose} -r #{build_config} -r #{ext_helper} -r #{dep_grapher} #{ext_task_name}"
else
build_extconf name, opts
end
Expand Down

0 comments on commit 7b1cb48

Please sign in to comment.