module Take module Compiler class GCC < Base DEBUG_OPTIONS = { default: "0", normal: "1", more: "2", max: "3", debug: "g", fast: "fast", size: "s" }.freeze def self.on_platform? @_on_platform ||= begin runner = Command::Runner.new(command, "--version") runner.run.successful? end end def self.command "gcc".freeze end def initialize super @options[:libraries] = [] @options[:directories] = { include: [], quote: [], library: [] }.freeze @options[:defines] = {} @options[:optimize] = DEBUG_OPTIONS.fetch(:default) @options[:warnings] = ["all", "extra"] end def output=(file) @options[:output] = file end def language=(lang) @options[:lang] = lang || "none" end def standard=(standard) if standard @options[:std] = standard else @options.delete(:std) end end def optimize_mode=(mode) mode = :default unless mode @options[:optimize] = DEBUG_OPTIONS.fetch(mode) do DEBUG_OPTIONS.fetch(:default) end end def []=(key, value) @options[:extra][key] = value end def libraries @options[:libraries] end def directories @options[:directories] end def defines @options[:defines] end def warnings @options[:warnings] end def stop_after(stage = nil) case stage when :link @options[:stop] = "c" when :assemble @options[:stop] = "S" when :preprocess @options[:stop] = "E" else @options.delete(:stop) end end def object stop_after :link self end def run end private def compile_options compiled = "" if @options.key?(:std) compiled << "-std=#{@options[:std]} " end compiled << "-g#{@options[:optimize]} " compiled << @options[:warnings].map { |w| "-W#{w}" }.join(" ") compiled << "-fPIC " compiled << @options[:directories][:include].map { |i| "-I#{i}"} end end end end