diff --git a/.gitignore b/.gitignore index a23260e6..0dc68c70 100644 --- a/.gitignore +++ b/.gitignore @@ -12,4 +12,5 @@ coverage/* doc/* .bundle -Gemfile.lock \ No newline at end of file +Gemfile.lock +lib/llvm/config.rb diff --git a/ext/ruby-llvm-support/Rakefile b/ext/ruby-llvm-support/Rakefile index b14108be..851880e0 100644 --- a/ext/ruby-llvm-support/Rakefile +++ b/ext/ruby-llvm-support/Rakefile @@ -1,9 +1,9 @@ -require 'rake/clean' require 'rubygems' +require 'rake/clean' require 'ffi' -# Change this when updating for a newer LLVM. -LLVM_VERSION = '3.2' +require File.expand_path('../../lib/llvm/version', File.dirname(__FILE__)) +include LLVM def check_llvm_config(name) actual_version = `#{name} --version` @@ -28,15 +28,42 @@ LLVM_CONFIG = invoke_llvm_config('--cxxflags --ldflags') CXX = "g++" SRC = "support.cpp" -OUTPUT = FFI.map_library_name("RubyLLVMSupport-#{LLVM_VERSION}") -CLEAN.include(OUTPUT) +SUPPORT_LIB = FFI.map_library_name("RubyLLVMSupport-#{LLVM_VERSION}") +CONFIG_MOD = File.expand_path('../../lib/llvm/config.rb', File.dirname(__FILE__)) + +CLEAN.include(SUPPORT_LIB, CONFIG_MOD) -task :default => [:build] +desc "Build the shared library and config module" +task :default => [SUPPORT_LIB, CONFIG_MOD] + +file SUPPORT_LIB => [SRC] do + sh "#{CXX} -shared -lLLVM-#{LLVM_VERSION} #{SRC} #{LLVM_CONFIG} -o #{SUPPORT_LIB}" +end -desc "Build the shared library" -task :build => [OUTPUT] +LLVM_CONFIG_OPTS = [ + ['COMPONENTS', :array, '--components'], + ['TARGETS_BUILT', :array, '--targets-built'], + ['HOST_TARGET', :string, '--host-target'], + ['BUILD_MODE', :string, '--build-mode'], +] -file OUTPUT => [SRC] do - sh "#{CXX} -shared -lLLVM-#{LLVM_VERSION} #{SRC} #{LLVM_CONFIG} -o #{OUTPUT}" +file CONFIG_MOD do + open(CONFIG_MOD, 'w') do |f| + f.puts '# Generated by ruby-llvm. Please do not change this file by hand.' + f.puts 'module LLVM' + f.puts ' module CONFIG' + + LLVM_CONFIG_OPTS.each do |(const, fmt, flag)| + case fmt + when :string + f.puts ' ' << const << ' = ' << invoke_llvm_config(flag).strip.inspect + when :array + f.puts ' ' << const << ' = ' << invoke_llvm_config(flag).strip.split.inspect + end + end + + f.puts ' end' + f.puts 'end' + end end diff --git a/lib/llvm/version.rb b/lib/llvm/version.rb index 9f8795c3..5f4b5d8f 100644 --- a/lib/llvm/version.rb +++ b/lib/llvm/version.rb @@ -1,23 +1,4 @@ -require 'find' - module LLVM LLVM_VERSION = "3.2" RUBY_LLVM_VERSION = "3.2.0.beta.1" - LLVM_CONFIG = begin - variants = %W(llvm-config-#{LLVM_VERSION} llvm-config) - llvm_config = nil - catch :done do - paths = ENV['PATH'].split(File::PATH_SEPARATOR).select(&File.method(:directory?)) - Find.find(*paths) do |path| - if variants.include?(File.basename(path)) - actual_version = `#{path} --version`.chomp - if LLVM_VERSION == actual_version - llvm_config = path - throw(:done) - end - end - end - end - llvm_config - end end