Class: Project

Inherits:
Object
  • Object
show all
Defined in:
lib/simple-make/project.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name = nil) ⇒ Project

Returns a new instance of Project.



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/simple-make/project.rb', line 9

def initialize(name=nil)
  @name = name || default_name
  @app_path = "app"
  @test_path = "test"
  @prod_path = "prod"
  @output_path = "build"
  @source_folder_name = "src"
  @deps = []
  @includes = []
  @cc = "g++ -O0 -g3 -Wall"
  @link = "g++"
end

Instance Attribute Details

#name=(value) ⇒ Object (writeonly)

Sets the attribute name

Parameters:

  • value

    the value to set the attribute name to.



7
8
9
# File 'lib/simple-make/project.rb', line 7

def name=(value)
  @name = value
end

Instance Method Details

#compile_command_with_flag(cc) ⇒ Object



52
53
54
# File 'lib/simple-make/project.rb', line 52

def compile_command_with_flag cc
  @cc = cc
end

#default_nameObject



22
23
24
# File 'lib/simple-make/project.rb', line 22

def default_name
  File.absolute_path(".").split("/").last
end

#depend_on(*deps) ⇒ Object



26
27
28
29
# File 'lib/simple-make/project.rb', line 26

def depend_on(*deps)
  raise "depend_on only accept array of dependencies, use [] to wrap your dependency if there is only one" if !(deps.is_a? Array)
  @deps += deps.map{|depHash| Dependency.new(depHash)}
end

#generate_make_file(filename = "Makefile") ⇒ Object



60
61
62
63
64
65
# File 'lib/simple-make/project.rb', line 60

def generate_make_file(filename = "Makefile")
  makefile = ERB.new(File.open(File.expand_path(File.dirname(__FILE__) + "/../../template/makefile.erb")).read)
  File.open(filename, "w") do |f|
    f.write makefile.result(binding)
  end
end

#header_search_path(*paths) ⇒ Object



47
48
49
50
# File 'lib/simple-make/project.rb', line 47

def header_search_path *paths
  raise "search path only accept array of paths, use [] to wrap your search paths if there is only one" if !(paths.is_a? Array)
  @includes += paths.map{|path| SearchPath.new(path)}
end


56
57
58
# File 'lib/simple-make/project.rb', line 56

def link_command_with_flag link
  @link = link
end

#prod_srcsObject



39
40
41
# File 'lib/simple-make/project.rb', line 39

def prod_srcs
  all_sources_in(@prod_path)
end

#srcsObject



31
32
33
# File 'lib/simple-make/project.rb', line 31

def srcs
  all_sources_in(@app_path)
end

#sub_folders_in_target_folderObject



43
44
45
# File 'lib/simple-make/project.rb', line 43

def sub_folders_in_target_folder
  (all_output_dirs_related_to(@app_path) + all_output_dirs_related_to(@prod_path) + all_output_dirs_related_to(@test_path)).join(" \\\n")
end

#test_srcsObject



35
36
37
# File 'lib/simple-make/project.rb', line 35

def test_srcs
  all_sources_in(@test_path)
end