module L::C::Compiler

An Abstraction over different compilers.

Public Class Methods

available?() click to toggle source

If the compiler is available on the current system.

@return [true,false]

# File lib/rub/l/c.rb, line 137
def self.available?
        false
end
compile_command(opt, src, obj) click to toggle source

Compile source files.

@param src [Set<Pathname>] The source files to link and generated headers. @param obj [Pathname] The path of the output file. @param opt [Options] An options object. @return [Pathname] The output file.

# 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) click to toggle source

Compile a file.

@param (see compile_command) @return [R::Command] the process that compiled the file.

# 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) click to toggle source

Compile a string.

@param str [String] A string containing the complete source to compile. @param obj [Pathname] The path of the output file. @param opt [Options] An options object. @return [R::Command] the process that compiled the string.

# 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) click to toggle source
# 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() click to toggle source

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.

# File lib/rub/l/c.rb, line 146
def self.linker
        nil
end
name() click to toggle source

The name of the compiler.

@return [Symbol]

# File lib/rub/l/c.rb, line 130
def self.name
        :default
end
test_compile(opt, src) click to toggle source

Peform a test compile.

@param (see do_compile_file) @return [true,false] true if the compilation succeeded.

# 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) click to toggle source

Peform a test compile.

@param (see do_compile_string) @return [true,false] true if the compilation succeeded.

# 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) click to toggle source

Check to see if a macro is defined.

@param name [String] macro identifier. @return [true,false] true if the macro is defined.

# 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