Module: L::C::Compiler
- Defined in:
- lib/rub/l/c.rb
Overview
An Abstraction over different compilers.
Class Method Summary collapse
-
.available? ⇒ true, false
If the compiler is available on the current system.
-
.compile_command(opt, src, obj) ⇒ Pathname
Compile source files.
-
.do_compile_file(opt, f, obj) ⇒ R::Command
Compile a file.
-
.do_compile_string(opt, str, obj) ⇒ R::Command
Compile a string.
- .include_directories(opt) ⇒ Object
-
.linker ⇒ Object
Return the preferred linker.
-
.name ⇒ Symbol
The name of the compiler.
-
.test_compile(opt, src) ⇒ true, false
Peform a test compile.
-
.test_compile_string(opt, src) ⇒ true, false
Peform a test compile.
-
.test_macro(opt, name) ⇒ true, false
Check to see if a macro is defined.
Class Method Details
.available? ⇒ true, false
If the compiler is available on the current system.
137 138 139 |
# File 'lib/rub/l/c.rb', line 137 def self.available? false end |
.compile_command(opt, src, obj) ⇒ Pathname
Compile source files.
156 157 158 |
# File 'lib/rub/l/c.rb', line 156 def self.compile_command(opt, src, obj) raise "Not implemented!" end |
.do_compile_file(opt, f, obj) ⇒ R::Command
Compile a file.
164 165 166 167 168 |
# File 'lib/rub/l/c.rb', line 164 def self.do_compile_file(opt, f, obj) c = R::Command.new(compile_command(opt, f, obj)) c.run c end |
.do_compile_string(opt, str, obj) ⇒ R::Command
Compile a string.
176 177 178 179 180 181 182 183 |
# File 'lib/rub/l/c.rb', line 176 def self.do_compile_string(opt, str, obj) f = Tempfile.new(['rub.l.c.testcompile', '.c']) f.write(str) f.close c = do_compile_file(opt, f.path, obj) f.unlink c end |
.include_directories(opt) ⇒ Object
217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 |
# File 'lib/rub/l/c.rb', line 217 def self.include_directories(opt) @include_directories and return @include_directories.dup cmd = [C.find_command('cpp'), '-v', '-o', File::NULL, File::NULL] c = R::Command.new cmd c.run l = c.stderr.lines.map &:chomp #qb = l.find_index('#include "..." search starts here:') + 1 sb = l.find_index('#include <...> search starts here:') + 1 se = l.find_index 'End of search list.' @include_directories = l[sb...se].map{|d| Pathname.new d[1..-1] } @include_directories.dup end |
.linker ⇒ Object
Return the preferred linker.
Some compilers create objects that need to be linked with their linker. This allows the compiler to specify the linker is wishes to be used.
146 147 148 |
# File 'lib/rub/l/c.rb', line 146 def self.linker nil end |
.name ⇒ Symbol
The name of the compiler.
130 131 132 |
# File 'lib/rub/l/c.rb', line 130 def self.name :default end |
.test_compile(opt, src) ⇒ true, false
Peform a test compile.
189 190 191 192 193 |
# File 'lib/rub/l/c.rb', line 189 def self.test_compile(opt, src) c = do_compile_file(opt, src, File::NULL) #p c.success?, c.stdin, c.stdout, c.stderr c.success? end |
.test_compile_string(opt, src) ⇒ true, false
Peform a test compile.
199 200 201 202 203 |
# File 'lib/rub/l/c.rb', line 199 def self.test_compile_string(opt, src) c = do_compile_string(opt, src, File::NULL) #p c.success?, c.stdin, c.stdout, c.stderr c.success? end |
.test_macro(opt, name) ⇒ true, false
Check to see if a macro is defined.
209 210 211 212 213 214 215 |
# File 'lib/rub/l/c.rb', line 209 def self.test_macro(opt, name) test_compile_string opt, <<EOF #ifndef #{name} #error "#{name}Not Defined" #endif EOF end |