Class: Daedalus::Compiler
- Inherits:
-
Object
- Object
- Daedalus::Compiler
- Defined in:
- lib/daedalus.rb
Instance Attribute Summary collapse
-
#cc ⇒ Object
readonly
Returns the value of attribute cc.
-
#cflags ⇒ Object
readonly
Returns the value of attribute cflags.
-
#cxx ⇒ Object
readonly
Returns the value of attribute cxx.
-
#cxxflags ⇒ Object
readonly
Returns the value of attribute cxxflags.
-
#ldflags ⇒ Object
readonly
Returns the value of attribute ldflags.
-
#ldshared ⇒ Object
readonly
Returns the value of attribute ldshared.
-
#ldsharedxx ⇒ Object
readonly
Returns the value of attribute ldsharedxx.
-
#log ⇒ Object
readonly
Returns the value of attribute log.
-
#mtime_only ⇒ Object
Returns the value of attribute mtime_only.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #add_library(lib) ⇒ Object
- #ar(library, objects) ⇒ Object
- #c_compile(source, object) ⇒ Object
- #calculate_deps(path) ⇒ Object
- #compile(source, object) ⇒ Object
- #cxx_compile(source, object) ⇒ Object
- #header_directories ⇒ Object
-
#initialize(cc, cxx, ldshared, ldsharedxx, logger, blueprint) ⇒ Compiler
constructor
A new instance of Compiler.
- #link(path, files) ⇒ Object
- #link_shared(library, objects) ⇒ Object
- #mtime(path) ⇒ Object
- #sha1(path) ⇒ Object
Constructor Details
#initialize(cc, cxx, ldshared, ldsharedxx, logger, blueprint) ⇒ Compiler
Returns a new instance of Compiler.
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 |
# File 'lib/daedalus.rb', line 141 def initialize(cc, cxx, ldshared, ldsharedxx, logger, blueprint) @cc = cc @cxx = cxx @ldshared = ldshared @ldsharedxx = ldsharedxx @cflags = [] @cxxflags = [] @ldflags = [] @libraries = [] @log = logger @blueprint = blueprint @mod_times = Hash.new do |h,k| h[k] = (File.exists?(k) ? File.mtime(k) : Time.at(0)) end @sha1_mtimes = {} @sha1s = Hash.new do |h,k| if File.exists?(k) @log.verbose "computing SHA1: #{k}" @sha1_mtimes[k] = File.mtime(k) h[k] = Digest::SHA1.file(k).hexdigest else h[k] = "" end end @mtime_only = false end |
Instance Attribute Details
#cc ⇒ Object (readonly)
Returns the value of attribute cc.
185 186 187 |
# File 'lib/daedalus.rb', line 185 def cc @cc end |
#cflags ⇒ Object (readonly)
Returns the value of attribute cflags.
185 186 187 |
# File 'lib/daedalus.rb', line 185 def cflags @cflags end |
#cxx ⇒ Object (readonly)
Returns the value of attribute cxx.
185 186 187 |
# File 'lib/daedalus.rb', line 185 def cxx @cxx end |
#cxxflags ⇒ Object (readonly)
Returns the value of attribute cxxflags.
185 186 187 |
# File 'lib/daedalus.rb', line 185 def cxxflags @cxxflags end |
#ldflags ⇒ Object (readonly)
Returns the value of attribute ldflags.
185 186 187 |
# File 'lib/daedalus.rb', line 185 def ldflags @ldflags end |
#ldshared ⇒ Object (readonly)
Returns the value of attribute ldshared.
185 186 187 |
# File 'lib/daedalus.rb', line 185 def ldshared @ldshared end |
#ldsharedxx ⇒ Object (readonly)
Returns the value of attribute ldsharedxx.
185 186 187 |
# File 'lib/daedalus.rb', line 185 def ldsharedxx @ldsharedxx end |
#log ⇒ Object (readonly)
Returns the value of attribute log.
185 186 187 |
# File 'lib/daedalus.rb', line 185 def log @log end |
#mtime_only ⇒ Object
Returns the value of attribute mtime_only.
171 172 173 |
# File 'lib/daedalus.rb', line 171 def mtime_only @mtime_only end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
185 186 187 |
# File 'lib/daedalus.rb', line 185 def path @path end |
Instance Method Details
#add_library(lib) ⇒ Object
187 188 189 190 191 192 193 194 195 196 197 |
# File 'lib/daedalus.rb', line 187 def add_library(lib) if f = lib.cflags @cflags = f + @cflags @cflags.uniq! end if f = lib.ldflags @ldflags = f + @ldflags @ldflags.uniq! end end |
#ar(library, objects) ⇒ Object
236 237 238 239 240 |
# File 'lib/daedalus.rb', line 236 def ar(library, objects) @log.show "AR", library @log.command "ar rv #{library} #{objects.join(' ')}" @log.command "ranlib #{library}" end |
#c_compile(source, object) ⇒ Object
221 222 223 224 |
# File 'lib/daedalus.rb', line 221 def c_compile(source, object) @log.show "CC", source @log.command "#{@cc} #{@cflags.join(' ')} -c -o #{object} #{source}" end |
#calculate_deps(path) ⇒ Object
247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 |
# File 'lib/daedalus.rb', line 247 def calculate_deps(path) dirs = header_directories() + ["/usr/include"] flags = @cflags.join(' ') begin dep = DependencyGrapher.new @cc, [path], dirs, flags dep.process # This is a quick work-around for a craptastic bug that I can't figure # out. Sometimes this raises an exception saying it can't find a file # which is pretty obviously there. I've been unable to figure out # what causes this and thus how to fix. # # So as a temporary measure, if an exception is raised, I'm going to # just do it again. Previous results have shown that this should # work the 2nd time even though the first time failed. # # I know this sounds silly, but we need some fix for this. rescue Exception dep = DependencyGrapher.new @cc, [path], dirs, flags dep.process end dep.sources.first.dependencies.sort end |
#compile(source, object) ⇒ Object
213 214 215 216 217 218 219 |
# File 'lib/daedalus.rb', line 213 def compile(source, object) if source =~ /\.cpp$/ cxx_compile(source, object) else c_compile(source, object) end end |
#cxx_compile(source, object) ⇒ Object
226 227 228 229 |
# File 'lib/daedalus.rb', line 226 def cxx_compile(source, object) @log.show "CXX", source @log.command "#{@cxx} #{@cflags.join(' ')} #{@cxxflags.join(' ')} -c -o #{object} #{source}" end |
#header_directories ⇒ Object
173 174 175 176 177 178 179 180 181 182 183 |
# File 'lib/daedalus.rb', line 173 def header_directories dirs = [] @cflags.each do |fl| fl.split(/\s+/).each do |part| if part.index("-I") == 0 dirs << part[2..-1] end end end dirs end |
#link(path, files) ⇒ Object
231 232 233 234 |
# File 'lib/daedalus.rb', line 231 def link(path, files) @log.show "LD", path @log.command "#{@cxx} -o #{path} #{files.join(' ')} #{@libraries.join(' ')} #{@ldflags.join(' ')}" end |
#link_shared(library, objects) ⇒ Object
242 243 244 245 |
# File 'lib/daedalus.rb', line 242 def link_shared(library, objects) @log.show "LDSHARED", library @log.command "#{@ldsharedxx} #{objects.join(' ')} -o #{library}" end |
#mtime(path) ⇒ Object
199 200 201 |
# File 'lib/daedalus.rb', line 199 def mtime(path) @mod_times[path] end |
#sha1(path) ⇒ Object
203 204 205 206 207 208 209 210 211 |
# File 'lib/daedalus.rb', line 203 def sha1(path) if @sha1s.key?(path) if File.mtime(path) > @sha1_mtimes[path] @sha1s.delete(path) end end @sha1s[path] end |