Class: Rbind::GeneratorC
- Inherits:
-
Object
- Object
- Rbind::GeneratorC
- Defined in:
- lib/rbind/generator_c.rb
Defined Under Namespace
Classes: CMakeListsHelper, ConstsHelper, ConversionsHelper, ConversionsHelperHDR, HelperBase, OperationsHDRHelper, OperationsHelper, TypesHelper, TypesHelperHDR
Instance Attribute Summary collapse
-
#generate_cmake ⇒ Object
Returns the value of attribute generate_cmake.
-
#includes ⇒ Object
Returns the value of attribute includes.
-
#library_name ⇒ Object
Returns the value of attribute library_name.
-
#libs ⇒ Object
Returns the value of attribute libs.
-
#output_path ⇒ Object
Returns the value of attribute output_path.
-
#pkg_config ⇒ Object
Returns the value of attribute pkg_config.
Instance Method Summary collapse
- #generate(path = @output_path) ⇒ Object
-
#initialize(root, library_name) ⇒ GeneratorC
constructor
A new instance of GeneratorC.
Constructor Details
#initialize(root, library_name) ⇒ GeneratorC
292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 |
# File 'lib/rbind/generator_c.rb', line 292 def initialize(root,library_name) raise "wrong type #{root}" unless root.is_a? RNamespace @root = root @erb_types_hdr = ERB.new(File.open(File.join(File.dirname(__FILE__),"templates","c","types.h")).read) @erb_types = ERB.new(File.open(File.join(File.dirname(__FILE__),"templates","c","types.cc")).read) @erb_consts = ERB.new(File.open(File.join(File.dirname(__FILE__),"templates","c","consts.h")).read) @erb_operations = ERB.new(File.open(File.join(File.dirname(__FILE__),"templates","c","operations.cc")).read) @erb_operations_hdr = ERB.new(File.open(File.join(File.dirname(__FILE__),"templates","c","operations.h")).read) @erb_conversions = ERB.new(File.open(File.join(File.dirname(__FILE__),"templates","c","conversions.cc")).read) @erb_conversions_hdr = ERB.new(File.open(File.join(File.dirname(__FILE__),"templates","c","conversions.hpp")).read) @erb_cmakelists = ERB.new(File.open(File.join(File.dirname(__FILE__),"templates","c","CMakeLists.txt")).read) @erb_find_package = ERB.new(File.open(File.join(File.dirname(__FILE__),"templates","c","find_package.txt")).read) @erb_pkg_config = ERB.new(File.open(File.join(File.dirname(__FILE__),"templates","c","rbind.pc.in")).read) @includes = Array.new @pkg_config= Array.new @library_name = library_name @generate_cmake = true @libs = [] end |
Instance Attribute Details
#generate_cmake ⇒ Object
Returns the value of attribute generate_cmake.
289 290 291 |
# File 'lib/rbind/generator_c.rb', line 289 def generate_cmake @generate_cmake end |
#includes ⇒ Object
Returns the value of attribute includes.
285 286 287 |
# File 'lib/rbind/generator_c.rb', line 285 def includes @includes end |
#library_name ⇒ Object
Returns the value of attribute library_name.
286 287 288 |
# File 'lib/rbind/generator_c.rb', line 286 def library_name @library_name end |
#libs ⇒ Object
Returns the value of attribute libs.
287 288 289 |
# File 'lib/rbind/generator_c.rb', line 287 def libs @libs end |
#output_path ⇒ Object
Returns the value of attribute output_path.
290 291 292 |
# File 'lib/rbind/generator_c.rb', line 290 def output_path @output_path end |
#pkg_config ⇒ Object
Returns the value of attribute pkg_config.
288 289 290 |
# File 'lib/rbind/generator_c.rb', line 288 def pkg_config @pkg_config end |
Instance Method Details
#generate(path = @output_path) ⇒ Object
312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 |
# File 'lib/rbind/generator_c.rb', line 312 def generate(path = @output_path) @output_path = path FileUtils.mkdir_p(path) if path && !File.directory?(path) file_types_hdr = File.new(File.join(path,"types.h"),"w") file_types = File.new(File.join(path,"types.cc"),"w") file_consts = File.new(File.join(path,"constants.h"),"w") file_operations = File.new(File.join(path,"operations.cc"),"w") file_operations_hdr = File.new(File.join(path,"operations.h"),"w") file_conversions = File.new(File.join(path,"conversions.cc"),"w") file_conversions_hdr = File.new(File.join(path,"conversions.hpp"),"w") rbind_pkgs = Rbind.rbind_pkgs(@pkg_config) types_hdr = TypesHelperHDR.new("_#{library_name.upcase}_TYPES_H_",@root) types_hdr.includes = rbind_pkgs.map do |p| "<#{p}/types.h>" end file_types_hdr.write @erb_types_hdr.result(types_hdr.binding) types = TypesHelper.new("types",@root) file_types.write @erb_types.result(types.binding) consts = ConstsHelper.new("_#{library_name.upcase}_CONSTS_H_",@root) consts.includes = rbind_pkgs.map do |p| "<#{p}/constants.h>" end file_consts.write @erb_consts.result(consts.binding) conversions_hdr = ConversionsHelperHDR.new("#{library_name.upcase}_CONVERSIONS_H_",@root) conversions_hdr.includes = rbind_pkgs.map do |p| "<#{p}/conversions.hpp>" end conversions_hdr.includes += includes file_conversions_hdr.write @erb_conversions_hdr.result(conversions_hdr.binding) conversions = ConversionsHelper.new("conversions",@root) file_conversions.write @erb_conversions.result(conversions.binding) operations_hdr = OperationsHDRHelper.new("_#{library_name.upcase}_OPERATIONS_H_",@root) file_operations_hdr.write @erb_operations_hdr.result(operations_hdr.binding) operations = OperationsHelper.new("operations",@root) file_operations.write @erb_operations.result(operations.binding) if generate_cmake && !File.exist?(File.join(path,"CMakeLists.txt")) file_cmakelists = File.new(File.join(path,"CMakeLists.txt"),"w") cmakelists = CMakeListsHelper.new(@library_name,@pkg_config,@libs) file_cmakelists.write @erb_cmakelists.result(cmakelists.binding) if !File.exist?(File.join(path,"rbind.pc.in")) file_pkg_config = File.new(File.join(path,"rbind.pc.in"),"w") file_pkg_config.write @erb_pkg_config.result(Kernel.binding) end end end |