Module: L::C
- Defined in:
- lib/rub/l/c.rb
Overview
C Library
Defined Under Namespace
Modules: Compiler, CompilerClang, CompilerGCC Classes: TargetCSource, TargetGeneratedHeader
Class Method Summary collapse
-
.compile(src) ⇒ Set<Pathname>
Compile source files.
- .compiler=(name) ⇒ Object
-
.compilers ⇒ Hash{Symbol=>Compiler}
All available compilers.
-
.debug ⇒ true, false
Default debug symbols setting.
-
.define ⇒ Hash{String=>String,true,nil}
A list of macros to define.
-
.generate_header(name, vals) ⇒ Object
Generate a header.
- .get_compiler(name) ⇒ Object
-
.include_dirs ⇒ Array<Pathname>
A list of directories to search for header files.
- .initialize_copy(s) ⇒ Object
-
.libs ⇒ Array<String,Pathname>
A list of libraries to link.
-
.optimize ⇒ Symbol
Default optimization level.
-
.optimize_for ⇒ Symbol
Default optimization goal.
-
.profile ⇒ true, false
Default profile symbols setting.
-
.program(src, name) ⇒ Pathname
Compile and link an executable.
- .to_c_identifier(s) ⇒ Object
Instance Method Summary collapse
-
#compiler ⇒ Object
Compiler.
Class Method Details
.compile(src) ⇒ Set<Pathname>
Compile source files.
271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 |
# File 'lib/rub/l/c.rb', line 271 def self.compile(src) src = R::Tool.make_set_paths src headers = Set.new src.keep_if do |s| if s.extname.match /[H]/i headers << s false else true end end src.map! do |s| out = R::Env.out_dir + 'l/c/' + C.unique_segment(self) + "#{s.basename}.o" R.find_target(s) or TargetCSource.new(self, s, headers) ::C.generator(s, compiler.compile_command(self, s, out), out, desc:"Compiling") end src.flatten! src end |
.compiler=(name) ⇒ Object
42 43 44 |
# File 'lib/rub/l/c.rb', line 42 def self.compiler=(name) @compiler = get_compiler name end |
.compilers ⇒ Hash{Symbol=>Compiler}
All available compilers.
32 |
# File 'lib/rub/l/c.rb', line 32 cattr_accessor :compilers |
.debug ⇒ true, false
Default debug symbols setting.
This determines if the compiler should produce debugging symbols.
85 |
# File 'lib/rub/l/c.rb', line 85 cattr_accessor :debug |
.define ⇒ Hash{String=>String,true,nil}
A list of macros to define. ‘nil` can be used to undefine a macro.
114 |
# File 'lib/rub/l/c.rb', line 114 cattr_accessor :define |
.generate_header(name, vals) ⇒ Object
Generate a header
Generates a header with information in it.
443 444 445 446 447 448 449 450 451 452 453 |
# File 'lib/rub/l/c.rb', line 443 def self.generate_header(name, vals) h = C.unique_path("#{name}.h", vals) c = C.unique_path("#{name}.c", vals) t = TargetGeneratedHeader.new(self, name, h, c, vals) t.register include_dirs << h.dirname t.output end |
.get_compiler(name) ⇒ Object
236 237 238 239 240 241 242 |
# File 'lib/rub/l/c.rb', line 236 def self.get_compiler(name) if name.is_a? Symbol compilers[name] else name end end |
.include_dirs ⇒ Array<Pathname>
A list of directories to search for header files.
These paths are searched in order.
102 |
# File 'lib/rub/l/c.rb', line 102 cattr_accessor :include_dirs |
.initialize_copy(s) ⇒ Object
469 470 471 472 473 474 475 |
# File 'lib/rub/l/c.rb', line 469 def self.initialize_copy(s) super self.include_dirs = s.include_dirs.dup self.libs = s.libs.dup self.define = s.define.dup end |
.libs ⇒ Array<String,Pathname>
A list of libraries to link.
108 |
# File 'lib/rub/l/c.rb', line 108 cattr_accessor :libs |
.optimize ⇒ Symbol
Default optimization level.
This takes one of four optimization levels. The actual optimization done is linker dependant. For example, some linker may not have any optimization so all levels will be equivalent.
One of the following:
:none
-
Perform no optimization. This should be fast and debuggable.
:some
-
Perform light optimization that is pretty fast.
:full
-
Perform a high level of optimization producing a fast binary. this may considerably slow down compilation.
:max
-
Perform all available optimizations. These may be experimental and very slow.
This value defaults to :full
if D:debug
is set, otherwise :none
.
64 |
# File 'lib/rub/l/c.rb', line 64 cattr_accessor :optimize |
.optimize_for ⇒ Symbol
Default optimization goal.
This determines what the compiler should optimize for if it has the option.
One of the following:
:size
-
The compiler should focus on creating a small binary.
:speed
-
The compiler should focus on creating a fast binary.
77 |
# File 'lib/rub/l/c.rb', line 77 cattr_accessor :optimize_for |
.profile ⇒ true, false
Default profile symbols setting.
This determines if the compiler should produce code suitable for profiling.
94 |
# File 'lib/rub/l/c.rb', line 94 cattr_accessor :profile |
.program(src, name) ⇒ Pathname
Compile and link an executable.
461 462 463 464 465 466 467 |
# File 'lib/rub/l/c.rb', line 461 def self.program(src, name) obj = compile(src) linker = L::LD.clone linker.set_linker compiler.linker linker.link(obj, libs, name, format: :exe) end |
.to_c_identifier(s) ⇒ Object
363 364 365 366 367 |
# File 'lib/rub/l/c.rb', line 363 def self.to_c_identifier(s) s.delete('`!@#$%^&*()+=[]{};"\'<>?') .gsub(/[\~\-\\\|\:\,\.\/]/, '_') .gsub(/^[0-9]/, '_\0') end |
Instance Method Details
#compiler ⇒ Object
Compiler
The compiler to use.
41 |
# File 'lib/rub/l/c.rb', line 41 cattr_reader :compiler |