Class: Project
- Inherits:
-
Object
- Object
- Project
- Defined in:
- lib/rmake.rb
Class Method Summary collapse
Instance Method Summary collapse
- #add_include_path(paths) ⇒ Object
- #add_ld_library_path(paths) ⇒ Object
- #add_libs(libs) ⇒ Object
- #add_sources(files) ⇒ Object
- #chanage_source_to_obj(file) ⇒ Object
- #create_makefile_and_make ⇒ Object
- #gcc ⇒ Object
-
#host(platform) ⇒ Object
set options.
- #include_info ⇒ Object
-
#initialize(options = {}) ⇒ Project
constructor
A new instance of Project.
- #ld_info ⇒ Object
- #lib_info ⇒ Object
- #obj_files ⇒ Object
- #set(key, value) ⇒ Object
- #source_files ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Project
Returns a new instance of Project.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/rmake.rb', line 28 def initialize( = {}) @options = { makefile: 'Makefile', obj_files: 'build/tmp/objects', source_files: [], include_path: ['include', 'inc', './'], libs: [], ld_library_path: [], type: 'app', host: '', target: '', build_dir: 'build' }.merge() end |
Class Method Details
.all ⇒ Object
24 25 26 |
# File 'lib/rmake.rb', line 24 def self.all $projects.keys end |
.do(name) ⇒ Object
20 21 22 |
# File 'lib/rmake.rb', line 20 def self.do name $projects[name].create_makefile_and_make if $projects.has_key?(name) end |
.do_all ⇒ Object
16 17 18 |
# File 'lib/rmake.rb', line 16 def self.do_all $projects.values.each{|p| p.create_makefile_and_make } end |
Instance Method Details
#add_include_path(paths) ⇒ Object
92 93 94 |
# File 'lib/rmake.rb', line 92 def add_include_path paths @options[:include_path].concat paths end |
#add_ld_library_path(paths) ⇒ Object
96 97 98 |
# File 'lib/rmake.rb', line 96 def add_ld_library_path paths @options[:ld_library_path].concat paths end |
#add_libs(libs) ⇒ Object
100 101 102 |
# File 'lib/rmake.rb', line 100 def add_libs libs @options[:libs].concat libs end |
#add_sources(files) ⇒ Object
88 89 90 |
# File 'lib/rmake.rb', line 88 def add_sources files @options[:source_files].concat files end |
#chanage_source_to_obj(file) ⇒ Object
64 65 66 |
# File 'lib/rmake.rb', line 64 def chanage_source_to_obj file File.join(@options[:build_dir], 'obj', file.gsub(File.extname(file), '.o')) end |
#create_makefile_and_make ⇒ Object
72 73 74 75 76 77 |
# File 'lib/rmake.rb', line 72 def create_makefile_and_make open @options[:makefile], 'w' do |f| f << ERB.new(IO.read(File.join(__dir__, "../resources/makefile.#{@options[:type]}.erb"))).result(binding) end system("make") end |
#gcc ⇒ Object
55 56 57 58 |
# File 'lib/rmake.rb', line 55 def gcc return @options[:host] + '-g++' if @options[:host] != '' return 'g++' end |
#host(platform) ⇒ Object
set options
80 81 82 |
# File 'lib/rmake.rb', line 80 def host platform @options[:host] = platform end |
#include_info ⇒ Object
43 44 45 |
# File 'lib/rmake.rb', line 43 def include_info @options[:include_path].find_all{|path| File.directory?(path) }.map{|path| "-I" + path }.join(" ") end |
#ld_info ⇒ Object
47 48 49 |
# File 'lib/rmake.rb', line 47 def ld_info @options[:ld_library_path].find_all{|path| File.directory?(path) }.map{|path| "-L" + path }.join(" ") end |
#lib_info ⇒ Object
51 52 53 |
# File 'lib/rmake.rb', line 51 def lib_info @options[:libs].map{|path| "-l" + path }.join(" ") end |
#obj_files ⇒ Object
68 69 70 |
# File 'lib/rmake.rb', line 68 def obj_files source_files.map{|file| chanage_source_to_obj(file) } end |
#set(key, value) ⇒ Object
84 85 86 |
# File 'lib/rmake.rb', line 84 def set key, value @options[key] = value end |
#source_files ⇒ Object
60 61 62 |
# File 'lib/rmake.rb', line 60 def source_files source_files = @options[:source_files].size == 0 ? Dir["*/**/*.cpp"] + Dir["*/**/*.c"] : @options[:source_files] end |