Skip to content
Browse files

Add a configure script

configure creates config.rb, which sets up a number of build variables
that rake uses.
  • Loading branch information...
1 parent 621d091 commit 7153156623a229d9484e1d0bc6ae65f70e893461 Evan Phoenix committed Sep 30, 2009
Showing with 242 additions and 68 deletions.
  1. +1 −0 .gitignore
  2. +148 −0 configure
  3. +48 −0 rakelib/build.rb
  4. +13 −6 rakelib/configuration.rb
  5. +32 −62 rakelib/vm.rake
View
1 .gitignore
@@ -30,6 +30,7 @@ TAGS
autom4te.cache
code-cache
coverage
+config.rb
cscope.files
cscope.out
rakelib/ryan.rake
View
148 configure
@@ -0,0 +1,148 @@
+#!/usr/bin/env ruby
+
+root = File.expand_path File.dirname(__FILE__)
+
+require File.join(root, "kernel", "delta", "options")
+
+class Configure
+
+ def initialize(root)
+ @config = File.join(root, "config.rb")
+
+ @llvm = :none
+ @llvm_path = nil
+ @prefix = nil
+
+ @llvm_svn_dir = File.join(root, "vm", "external_libs", "llvm")
+
+ o = Rubinius::Options.new "Usage: configure [options]", 40
+
+ o.on "-h", "--help", "Display this help" do
+ puts o
+ exit 1
+ end
+
+ o.on("--enable-llvm", "[MODE]",
+ "Build with LLVM") do |which|
+ @llvm = (which || "auto").to_sym
+ end
+
+ o.on "--llvm-path", "PATH", "Where to find LLVM" do |dir|
+ @llvm_path = dir
+ end
+
+ o.on "--prefix", "PATH", "Where to install Rubinius" do |dir|
+ @prefix = dir
+ end
+
+ @options = o
+ end
+
+ def parse(ary)
+ @options.parse ary
+ end
+
+ LLVM_SVN_DIR = %w!vm external_libs llvm!
+ LLVM_SVN_URL = "http://llvm.org/svn/llvm-project/llvm/branches/release_26/"
+
+ def setup_svn
+ unless File.directory?(@llvm_svn_dir)
+ print " Checking out LLVM from svn: #{LLVM_SVN_URL}"
+ system "svn co #{LLVM_SVN_URL} #{@llvm_svn_dir}"
+ end
+
+ unless File.exists?(File.join(@llvm_svn_dir, "include"))
+ puts " Code in #{@llvm_svn_dir} doesn't appear to be proper LLVM tree!"
+ exit 1
+ end
+ end
+
+ def setup_auto
+ print " Checking for existing LLVM tree: "
+ if File.directory?(@llvm_svn_dir)
+ puts "found!"
+ @llvm = :svn
+ return
+ else
+ puts "not found."
+ end
+
+ return if setup_config
+
+ @llvm = :svn
+ setup_svn
+ end
+
+ def setup_config
+ print " Checking for 'llvm-config': "
+ which = ENV['PATH'].split(":").find do |path|
+ File.exists? File.join(path, "llvm-config")
+ end
+
+ if which
+ config = File.join(which, "llvm-config")
+ version = `#{config} --version`.strip
+ parts = version.sub(/svn$/, "").split(".").map { |i| i.to_i }
+ if parts[0] < 2 or parts[1] < 6
+ puts "too old of a version"
+ else
+ puts "found! (version #{version})"
+ @llvm = :config
+ return true
+ end
+ else
+ puts "not found"
+ end
+
+ false
+ end
+
+ def process
+ print "Using LLVM: "
+ case @llvm
+ when :svn
+ puts "svn"
+ setup_svn
+ when :auto
+ puts "auto"
+ setup_auto
+ when :config
+ puts "config"
+ exit 1 unless setup_config
+ when :no
+ puts "no"
+ else
+ puts "unknown value '#{@llvm}'"
+ end
+ end
+
+ def arch
+ `./rakelib/config.guess`.strip
+ end
+
+ def compiler
+ ENV['CC'] || "gcc"
+ end
+
+ def write_config
+ File.open @config, "w" do |f|
+ f.puts "module Rubinius"
+ f.puts "BUILD_CONFIG = {"
+ f.puts " :llvm => :#{@llvm},"
+ f.puts " :llvm_path => '#{@llvm_path}',"
+ f.puts " :arch => '#{arch()}',"
+ f.puts " :prefix => #{@prefix.inspect},"
+ f.puts " :compiler => '#{compiler}'"
+ f.puts "}"
+ f.puts "end"
+ end
+ end
+
+end
+
+STDOUT.sync = true
+
+c = Configure.new(root)
+c.parse ARGV
+c.process
+c.write_config
View
48 rakelib/build.rb
@@ -0,0 +1,48 @@
+def llvm_configure
+ case Rubinius::BUILD_CONFIG[:llvm]
+ when :svn
+ "vm/external_libs/llvm/Release/bin/llvm-config"
+ when :config
+ "llvm-config"
+ else
+ raise "Tried to use LLVM unconfigure!"
+ end
+end
+
+def llvm_flags
+ return [] unless LLVM_ENABLE
+
+ return @llvm_flags if defined?(@llvm_flags)
+
+ if Rubinius::BUILD_CONFIG[:llvm] == :svn
+ @llvm_flags = ["-Ivm/external_libs/llvm/include"]
+ else
+ @llvm_flags = []
+ end
+
+ @llvm_flags += `#{llvm_configure} --cflags`.split(/\s+/)
+ @llvm_flags.delete_if { |e| e.index("-O") == 0 }
+ @llvm_flags
+end
+
+def llvm_link_flags
+ return [] unless LLVM_ENABLE
+
+ `#{llvm_configure} --ldflags`.strip
+end
+
+def llvm_lib_files
+ return [] unless LLVM_ENABLE
+
+ files = `#{llvm_configure} --libfiles all`.split(/\s+/)
+ files.select { |f| File.file? f }
+end
+
+def host_triple
+ Rubinius::BUILD_CONFIG[:arch]
+end
+
+def llvm_config_flags
+ "--build=#{host_triple} --host=#{host_triple} " \
+ "--enable-optimized --enable-targets=host-only"
+end
View
19 rakelib/configuration.rb
@@ -1,6 +1,14 @@
# configuration for Rubinius
-RBX_DTRACE = ENV['DTRACE']
+config_path = File.join(File.dirname(__FILE__), "..", "config.rb")
+unless File.file?(config_path)
+ STDERR.puts "Please run ./configure first"
+ exit 1
+end
+
+load config_path
+
+RBX_DTRACE = nil
RBX_RUBY_ENGINE = 'rbx'
RBX_RUBY_VERSION = '1.8.7'
RBX_RUBY_PATCHLEVEL = 174
@@ -9,15 +17,14 @@
RBX_VERSION = "#{RBX_LIBVER}.0-dev"
RBX_HOST = `./rakelib/config.guess`.chomp
RBX_BUILDREV = `git rev-list --all | head -n1`.chomp
-RBX_CC = ENV['CC'] || 'gcc'
+RBX_CC = Rubinius::BUILD_CONFIG[:compiler]
# There are two ways to build Rubinius: development and install.
-# We assume that if ENV['RBX_PREFIX'] is set, we are building in
+# We assume that if prefix is set, we are building in
# install mode, otherwise development mode. For more details,
# see doc/build_system.txt.
-install = ! Rake.application.top_level_tasks.grep(/install/).empty?
-if install || ENV['RBX_PREFIX']
- RBX_PREFIX = ENV['RBX_PREFIX'] || "/usr/local"
+if prefix = Rubinius::BUILD_CONFIG[:prefix]
+ RBX_PREFIX = prefix
RBX_BINPATH = "#{RBX_PREFIX}/bin"
RBX_LIBPATH = "#{RBX_PREFIX}/lib"
RBX_BASE_PATH = "#{RBX_PREFIX}/lib/rubinius/#{RBX_LIBVER}"
View
94 rakelib/vm.rake
@@ -1,6 +1,7 @@
require 'tmpdir'
require 'rakelib/rubinius'
require 'rakelib/configuration'
+require 'rakelib/build'
require 'ostruct'
require 'lib/ffi/generator_task.rb'
@@ -17,20 +18,14 @@ task :vm => 'vm/vm'
############################################################
# Files, Flags, & Constants
+ENV.delete 'CDPATH' # confuses llvm_config
+
if CONFIG.compile_with_llvm
ENV['CC'] = "llvm-gcc"
end
-if ENV['LLVM_DEBUG']
- LLVM_STYLE = "Debug"
-else
- LLVM_STYLE = "Release"
-end
+LLVM_ENABLE = Rubinius::BUILD_CONFIG[:llvm]
-LLVM_ENABLE = !!ENV['RBX_LLVM']
-
-ENV.delete 'CDPATH' # confuses llvm_config
-LLVM_CONFIG = "vm/external_libs/llvm/#{LLVM_STYLE}/bin/llvm-config"
if ENV['TESTS_ONLY']
tests = FileList[ENV['TESTS_ONLY']]
@@ -71,7 +66,7 @@ end
EX_INC = %w[ libtommath libgdtoa onig libffi/include
libbstring libcchash libmquark libmpa
- libltdl libev llvm/include
+ libltdl libev
].map { |f| "vm/external_libs/#{f}" }
INSN_GEN = %w[ vm/gen/iseq_instruction_names.cpp
@@ -151,22 +146,7 @@ EXTERNALS = %W[ vm/external_libs/libmpa/libptr_array.a
vm/external_libs/libev/.libs/libev.a ]
-if LLVM_ENABLE
- LLVM_A = "vm/external_libs/llvm/#{LLVM_STYLE}/lib/libLLVMSystem.a"
- EXTERNALS << LLVM_A
-else
- LLVM_A = ""
-end
-
-OPTIONS = {
- LLVM_A => "--enable-targets=host-only --enable-bindings=none"
- }
-
-if LLVM_STYLE == "Release"
- OPTIONS[LLVM_A] << " --enable-optimized"
-end
-
-INCLUDES = EX_INC + %w[/usr/local/include vm/test/cxxtest vm . vm/assembler vm/assembler/udis86-1.7]
+INCLUDES = EX_INC + %w[vm/test/cxxtest vm . vm/assembler vm/assembler/udis86-1.7]
INCLUDES.map! { |f| "-I#{f}" }
# Default build options
@@ -186,11 +166,14 @@ end
if LLVM_ENABLE
FLAGS << "-DENABLE_LLVM"
+ STDERR.puts "LLVM inclusion enabled."
+=begin
llvm_flags = `#{LLVM_CONFIG} --cflags`.split(/\s+/)
llvm_flags.delete_if { |e| e.index("-O") == 0 }
FLAGS.concat llvm_flags
FLAGS << '-D__STDC_LIMIT_MACROS' unless FLAGS.include? '-D__STDC_LIMIT_MACROS'
FLAGS << '-D__STDC_CONSTANT_MACROS' unless FLAGS.include? '-D__STDC_CONSTANT_MACROS'
+=end
end
BUILD_PRETASKS = []
@@ -204,7 +187,7 @@ CC = ENV['CC'] || "gcc"
CXX = ENV["CXX"] || "g++"
def compile_c(obj, src, output_kind="c")
- flags = INCLUDES + FLAGS
+ flags = INCLUDES + FLAGS + llvm_flags
if CONFIG.compile_with_llvm
flags << "-emit-llvm"
@@ -220,7 +203,6 @@ def compile_c(obj, src, output_kind="c")
flags.delete_if { |f| f == '-Wno-deprecated' }
end
-
flags = flags.join(" ")
if $verbose
@@ -232,14 +214,10 @@ def compile_c(obj, src, output_kind="c")
end
def ld(t)
- if LLVM_ENABLE
- $link_opts ||= `#{LLVM_CONFIG} --ldflags`.split(/\s+/).join(' ')
- else
- $link_opts ||= ""
- end
+ link_opts = llvm_link_flags()
- $link_opts += ' -Wl,--export-dynamic' if RUBY_PLATFORM =~ /linux/i
- $link_opts += ' -rdynamic' if RUBY_PLATFORM =~ /bsd/
+ link_opts += ' -Wl,--export-dynamic' if RUBY_PLATFORM =~ /linux/i
+ link_opts += ' -rdynamic' if RUBY_PLATFORM =~ /bsd/
ld = ENV['LD'] || 'g++'
@@ -263,10 +241,10 @@ def ld(t)
l = ex_libs.join(' ')
if $verbose
- sh "#{ld} #{$link_opts} -o #{t.name} #{o} #{l}"
+ sh "#{ld} #{link_opts} -o #{t.name} #{o} #{l}"
else
puts "LD #{t.name}"
- sh "#{ld} #{$link_opts} -o #{t.name} #{o} #{l}", :verbose => false
+ sh "#{ld} #{link_opts} -o #{t.name} #{o} #{l}", :verbose => false
end
end
@@ -308,9 +286,19 @@ namespace :build do
import dep_file
+ desc "Build LLVM"
+ task :llvm do
+ if LLVM_ENABLE and Rubinius::BUILD_CONFIG[:llvm] == :svn
+ unless File.file?("vm/external_libs/llvm/Release/bin/llvm-config")
+ sh "cd vm/external_libs/llvm; ./configure #{llvm_config_flags} && make"
+ end
+ end
+ end
+
# Issue the actual build commands. NEVER USE DIRECTLY.
task :build => BUILD_PRETASKS +
%w[
+ build:llvm
vm
kernel:build
lib/rbconfig.rb
@@ -590,24 +578,15 @@ namespace :vm do
task :coverage do
Dir.mkdir "vm/test/coverage" unless File.directory? "vm/test/coverage"
- if LLVM_ENABLE and !defined? $llvm_c then
- $llvm_c = `#{LLVM_CONFIG} --cflags`.split(/\s+/)
- $llvm_c.delete_if { |e| e.index("-O") == 0 }
- end
+ link_opts = llvm_link_flags()
- if LLVM_ENABLE
- $link_opts ||= `#{LLVM_CONFIG} --ldflags`.split(/\s+/).join(' ')
- else
- $link_opts ||= ""
- end
-
- flags = (INCLUDES + FLAGS + $llvm_c).join(' ')
+ flags = (INCLUDES + FLAGS + llvm_flags).join(' ')
puts "CC/LD vm/test/coverage/runner"
begin
path = "vm/gen/instructions.cpp"
ruby 'vm/codegen/rubypp.rb', "vm/template/instructions.cpp", path
- sh "#{CXX} -fprofile-arcs -ftest-coverage #{flags} -o vm/test/coverage/runner vm/test/runner.cpp vm/*.cpp vm/builtin/*.cpp #{path} #{$link_opts} #{(ex_libs + EXTERNALS).join(' ')}"
+ sh "#{CXX} -fprofile-arcs -ftest-coverage #{flags} -o vm/test/coverage/runner vm/test/runner.cpp vm/*.cpp vm/builtin/*.cpp #{path} #{link_opts} #{(ex_libs + EXTERNALS).join(' ')}"
puts "RUN vm/test/coverage/runner"
sh "vm/test/coverage/runner"
@@ -680,10 +659,9 @@ require 'rake/loaders/makefile'
generated = (TYPE_GEN + INSN_GEN).select { |f| f =~ /pp$/ }
file dep_file => EXTERNALS + srcs + hdrs + vm_srcs + generated + %w[vm/gen/instructions.cpp] do |t|
- includes = INCLUDES.join ' '
+ includes = "-I. -Ivm" # includes = INCLUDES.join ' '
flags = FLAGS.join ' '
- flags << " -D__STDC_LIMIT_MACROS -D__STDC_CONSTANT_MACROS"
flags.slice!(/-Wno-deprecated/)
Dir.mkdir "vm/.deps" unless File.directory? "vm/.deps"
@@ -696,8 +674,9 @@ file dep_file => EXTERNALS + srcs + hdrs + vm_srcs + generated + %w[vm/gen/instr
f.puts File.read(file_deps)
else
object_file = file.sub(/((c(pp)?)|S)$/, 'o')
- cmd = "gcc -MM -MT \"#{object_file}\" #{includes} #{flags} #{file} 2>&1"
+ cmd = "gcc -nostdinc -nostdinc++ -MM -MT \"#{object_file}\" #{includes} #{flags} #{file} 2>&1"
data = `#{cmd}`
+ puts cmd
if $?.exitstatus == 0
data.strip!
@@ -724,16 +703,7 @@ def ex_libs # needs to be method to delay running of llvm_config
$ex_libs << "-lcrypt -L/usr/local/lib -lexecinfo" if RUBY_PLATFORM =~ /bsd/
$ex_libs << "-lrt -lcrypt" if RUBY_PLATFORM =~ /linux/
- if LLVM_ENABLE
- llvm_libfiles = `#{LLVM_CONFIG} --libfiles all`.split(/\s+/)
- llvm_libfiles = llvm_libfiles.select { |f| File.file? f }
- else
- llvm_libfiles = []
- end
-
- pwd = File.join Dir.pwd, '' # add /
- llvm_libfiles = llvm_libfiles.map { |f| f.sub pwd, '' }
- $ex_libs += llvm_libfiles
+ $ex_libs += llvm_lib_files
end
$ex_libs
end

0 comments on commit 7153156

Please sign in to comment.
Something went wrong with that request. Please try again.