Module: L::C::CompilerGCC

Defined in:
lib/rub/l/c/compiler/gcc.rb

Overview

GNU Compiler Collection

Constant Summary collapse

@@o_flags =
{
	:none=> D[:debug] ? '-Og' : '-O0',
	:some=>'-O1',
	:full=>'-O2',
	:max =>'-O3',
}
@@of_flags =
{
	nil=>[],
	:speed=>'-Ofast',
	:size=>'-Os',
}

Class Method Summary collapse

Class Method Details

.available?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/rub/l/c/compiler/gcc.rb', line 34

def self.available?
	!!find
end

.compile_command(opt, src, obj) ⇒ Object



81
82
83
# File 'lib/rub/l/c/compiler/gcc.rb', line 81

def self.compile_command(opt, src, obj)
	[find, '-c', *generate_flags(opt), "-o#{obj}", *src]
end

.do_compile_string(opt, str, obj) ⇒ Object



85
86
87
88
89
90
# File 'lib/rub/l/c/compiler/gcc.rb', line 85

def self.do_compile_string(opt, str, obj)
	c = R::Command.new [find, '-c', '-xc', *generate_flags(opt), '-o', obj, '-']
	c.stdin = str
	c.run
	c
end

.findObject



38
39
40
41
42
# File 'lib/rub/l/c/compiler/gcc.rb', line 38

def self.find
	@exe and return @exe

	@exe = ::C.find_command 'gcc'
end

.generate_flags(opt) ⇒ Object



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/rub/l/c/compiler/gcc.rb', line 60

def self.generate_flags(opt)
	f = []
	
	f << (@@o_flags[opt.optimize    ] || [])
	f << (@@o_flags[opt.optimize_for] || [])
	
	f << opt.include_dirs.map do |d|
		"-I#{d}"
	end
	f << opt.define.map do |k, v|
		if v
			# -Dk if v is true else -Dk=v.
			"-D#{k}#{v.eql?(true)?"":"=#{v}"}"
		else
			"-U#{k}"
		end
	end
	
	f.flatten!
end

.linkerObject



44
45
46
# File 'lib/rub/l/c/compiler/gcc.rb', line 44

def self.linker
	:gcc
end

.nameObject



30
31
32
# File 'lib/rub/l/c/compiler/gcc.rb', line 30

def self.name
	:gcc
end