Class: Makefile

Inherits:
Object
  • Object
show all
Defined in:
lib/rad/generators/makefile/makefile.rb

Class Method Summary collapse

Class Method Details

.board_configuration(arduino_root, board_name) ⇒ Object

match the mcu with the proper board configuration from the arduino board.txt file



40
41
42
43
44
45
46
47
48
49
# File 'lib/rad/generators/makefile/makefile.rb', line 40

def board_configuration(arduino_root, board_name)
  board_configuration = {}
  File.open("#{arduino_root}/hardware/boards.txt", "r") do |infile|
  	infile.each_line do |line|
  	  next unless line.chomp =~ /^#{board_name}\.([^=]*)=(.*)$/
  	  board_configuration[$1] = $2
  	end
  end
  board_configuration
end

.compose_for_sketch(build_dir) ⇒ Object

build the sketch Makefile for the given template based on the values in its software and hardware config files



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/rad/generators/makefile/makefile.rb', line 8

def compose_for_sketch(build_dir)
  params = hardware_params.merge software_params
  board_config = board_configuration(@software_params['arduino_root'], @hardware_params['mcu'])
  params = params.merge board_config
  params['target'] = build_dir.split("/").last
       
  params['libraries_root'] = "#{File.expand_path(RAD_ROOT)}/vendor/libraries"
  params['libraries'] = $load_libraries # load only libraries used 
  
  # needed along with ugly hack of including another copy of twi.h in wire, when using the Wire.h library
  params['twi_c'] = $load_libraries.include?("Wire") ? "#{params['arduino_root']}/hardware/libraries/Wire/utility/twi.c" : "" 
  
  params['asm_files'] = Dir.entries( File.expand_path(RAD_ROOT) + "/" + PROJECT_DIR_NAME ).select{|e| e =~ /\.S/}            
        
  e = ERB.new File.read("#{File.dirname(__FILE__)}/makefile.erb")
  
  File.open("#{build_dir}/Makefile", "w") do |f|
    f << e.result(binding)
  end
end

.hardware_paramsObject



29
30
31
32
# File 'lib/rad/generators/makefile/makefile.rb', line 29

def hardware_params
  return @hardware_params if @hardware_params
  return @hardware_params = YAML.load_file( "#{RAD_ROOT}/config/hardware.yml")
end

.software_paramsObject



34
35
36
37
# File 'lib/rad/generators/makefile/makefile.rb', line 34

def software_params
  return @software_params if @software_params
  return @software_params = YAML.load_file( "#{RAD_ROOT}/config/software.yml" )
end