module L::C

C Library

Constants

CompilerClang
#

This software is provided ‘as-is’, without any express or implied # warranty. In no event will the authors be held liable for any damages # arising from the use of this software. #

#

Permission is granted to anyone to use this software for any purpose, # including commercial applications, and to alter it and redistribute it # freely, subject to the following restrictions: #

#
  1. The origin of this software must not be misrepresented; you must not # claim that you wrote the original software. If you use this software in # a product, an acknowledgment in the product documentation would be # appreciated but is not required. #

    #
    
  2. Altered source versions must be plainly marked as such, and must not be # misrepresented as being the original software. #

    #
    
  3. This notice may not be removed or altered from any source distribution. #

    #
    
CompilerGCC
#

This software is provided ‘as-is’, without any express or implied # warranty. In no event will the authors be held liable for any damages # arising from the use of this software. #

#

Permission is granted to anyone to use this software for any purpose, # including commercial applications, and to alter it and redistribute it # freely, subject to the following restrictions: #

#
  1. The origin of this software must not be misrepresented; you must not # claim that you wrote the original software. If you use this software in # a product, an acknowledgment in the product documentation would be # appreciated but is not required. #

    #
    
  2. Altered source versions must be plainly marked as such, and must not be # misrepresented as being the original software. #

    #
    
  3. This notice may not be removed or altered from any source distribution. #

    #
    

Public Class Methods

compile(src) click to toggle source

Compile source files.

@param src [Set<Pathname,String>,Array<Pathname,String>,Pathname,String]

The source files to compile and generated headers.

@param opt [Options] An options object. @return [Set<Pathname>] The resulting object files.

# 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) click to toggle source
# File lib/rub/l/c.rb, line 42
def self.compiler=(name)
        @compiler = get_compiler name
end
generate_header(name, vals) click to toggle source

Generate a header

Generates a header with information in it.

# 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) click to toggle source
# File lib/rub/l/c.rb, line 236
def self.get_compiler(name)
        if name.is_a? Symbol
                compilers[name]
        else
                name
        end
end
initialize_copy(s) click to toggle source
Calls superclass method
# 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
program(src, name) click to toggle source

Compile and link an executable.

@param src [Set<Pathname,String>,Array<Pathname,String>,Pathname,String]

The source files to compile and generated headers.

@param name [Pathname,String] The basename of the output file. @return [Pathname] The resulting executable.

# 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) click to toggle source
# File lib/rub/l/c.rb, line 363
def self.to_c_identifier(s)
        s.delete('`!@#$%^&*()+=[]{};"\'<>?')
         .gsub(/[\~\-\\\|\:\,\.\/]/, '_')
         .gsub(/^[0-9]/, '_\0')
end