Class: FFI::Generators::Platform
- Inherits:
-
Object
- Object
- FFI::Generators::Platform
- Defined in:
- lib/ffi2/generators.rb
Instance Method Summary collapse
- #compile(include_dirs, source, target) ⇒ Object
- #compiler ⇒ Object
- #defines ⇒ Object
- #executable_ext ⇒ Object
-
#initialize(kind = :c) ⇒ Platform
constructor
TODO: Make these configurable to enable cross-compiling.
- #language ⇒ Object
- #source_ext ⇒ Object
- #windows? ⇒ Boolean
Constructor Details
#initialize(kind = :c) ⇒ Platform
TODO: Make these configurable to enable cross-compiling
102 103 104 |
# File 'lib/ffi2/generators.rb', line 102 def initialize(kind=:c) @kind = kind end |
Instance Method Details
#compile(include_dirs, source, target) ⇒ Object
156 157 158 159 160 161 |
# File 'lib/ffi2/generators.rb', line 156 def compile(include_dirs, source, target) includes = include_dirs.map { |i| "-I#{i}" }.join(" ") = "#{defines} -x #{language} #{includes} -Wall -Werror" "#{compiler} #{} #{source} -o #{target} 2>&1" end |
#compiler ⇒ Object
134 135 136 137 138 139 140 141 142 143 |
# 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 ⇒ Object
119 120 121 122 123 124 125 126 127 128 |
# 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 ⇒ Object
115 116 117 |
# File 'lib/ffi2/generators.rb', line 115 def executable_ext windows? ? ".exe" : "" end |
#language ⇒ Object
145 146 147 148 149 150 151 152 153 154 |
# File 'lib/ffi2/generators.rb', line 145 def language case @kind when :c "c" when :cpp, :cxx "c++" else "c" end end |
#source_ext ⇒ Object
106 107 108 109 110 111 112 113 |
# File 'lib/ffi2/generators.rb', line 106 def source_ext case @kind when :c ".c" when :cpp ".cpp" end end |
#windows? ⇒ Boolean
130 131 132 |
# File 'lib/ffi2/generators.rb', line 130 def windows? RUBY_PLATFORM =~ /mswin|mingw/ end |