class FFI::Generators::Platform

Public Class Methods

new(kind=:c) click to toggle source

TODO: Make these configurable to enable cross-compiling

# File lib/ffi2/generators.rb, line 102
def initialize(kind=:c)
  @kind = kind
end

Public Instance Methods

compile(include_dirs, source, target) click to toggle source
# File lib/ffi2/generators.rb, line 156
def compile(include_dirs, source, target)
  includes = include_dirs.map { |i| "-I#{i}" }.join(" ")
  compile_options = "#{defines} -x #{language} #{includes} -Wall -Werror"

  "#{compiler} #{compile_options} #{source} -o #{target} 2>&1"
end
compiler() click to toggle source
# File lib/ffi2/generators.rb, line 134
def compiler
  case @kind
  when :c
    RbConfig::CONFIG["CC"]
  when :cpp, :cxx
    RbConfig::CONFIG["CXX"] || RbConfig::CONFIG["CC"]
  else
    RbConfig::CONFIG["CC"]
  end
end
defines() click to toggle source
# File lib/ffi2/generators.rb, line 119
def defines
  case @kind
  when :c
    RbConfig::CONFIG["CFLAGS"]
  when :cpp, :cxx
    RbConfig::CONFIG["CPPFLAGS"] || RbConfig["CXXFLAGS"]
  else
    RbConfig::CONFIG["CFLAGS"]
  end
end
executable_ext() click to toggle source
# File lib/ffi2/generators.rb, line 115
def executable_ext
  windows? ? ".exe" : ""
end
language() click to toggle source
# File lib/ffi2/generators.rb, line 145
def language
  case @kind
  when :c
    "c"
  when :cpp, :cxx
    "c++"
  else
    "c"
  end
end
source_ext() click to toggle source
# File lib/ffi2/generators.rb, line 106
def source_ext
  case @kind
  when :c
    ".c"
  when :cpp
    ".cpp"
  end
end
windows?() click to toggle source
# File lib/ffi2/generators.rb, line 130
def windows?
  RUBY_PLATFORM =~ /mswin|mingw/
end