Class: Workshop::Builder
- Inherits:
-
Object
- Object
- Workshop::Builder
- Includes:
- FileUtils
- Defined in:
- lib/workshop/builder.rb
Instance Attribute Summary collapse
-
#project ⇒ Object
Returns the value of attribute project.
-
#tools ⇒ Object
Returns the value of attribute tools.
Instance Method Summary collapse
- #all_source_files ⇒ Object
- #archive ⇒ Object
- #archive_command_for(filename) ⇒ Object
- #archive_file ⇒ Object
- #clean ⇒ Object
- #code_files_in_directory(directory) ⇒ Object
- #compile ⇒ Object
- #compile_command_for(filename) ⇒ Object
- #compiler_flags ⇒ Object
- #core_files ⇒ Object
- #create_build_directory ⇒ Object
- #create_eeprom ⇒ Object
- #create_hex ⇒ Object
- #eeprom_command ⇒ Object
- #eeprom_file ⇒ Object
- #eeprom_flags ⇒ Object
- #elf_file ⇒ Object
- #hex_command ⇒ Object
- #hex_file ⇒ Object
- #hex_flags ⇒ Object
- #include_directories ⇒ Object
- #include_flags ⇒ Object
-
#initialize(project) ⇒ Builder
constructor
A new instance of Builder.
- #link ⇒ Object
- #link_command ⇒ Object
- #linker_flags ⇒ Object
- #main_filename ⇒ Object
- #main_name ⇒ Object
- #main_output_file ⇒ Object
- #o_files_to_archive ⇒ Object
- #output_file(filename) ⇒ Object
- #source_files ⇒ Object
- #variant_files ⇒ Object
Constructor Details
Instance Attribute Details
#project ⇒ Object
Returns the value of attribute project.
4 5 6 |
# File 'lib/workshop/builder.rb', line 4 def project @project end |
#tools ⇒ Object
Returns the value of attribute tools.
4 5 6 |
# File 'lib/workshop/builder.rb', line 4 def tools @tools end |
Instance Method Details
#all_source_files ⇒ Object
43 44 45 |
# File 'lib/workshop/builder.rb', line 43 def all_source_files core_files + variant_files + source_files end |
#archive ⇒ Object
78 79 80 81 82 |
# File 'lib/workshop/builder.rb', line 78 def archive o_files_to_archive.each do |filename| sh archive_command_for(filename) end end |
#archive_command_for(filename) ⇒ Object
57 58 59 60 61 62 63 64 |
# File 'lib/workshop/builder.rb', line 57 def archive_command_for(filename) [ tools.avr_ar, 'rcs', archive_file, filename, ].join(' ') end |
#archive_file ⇒ Object
92 93 94 |
# File 'lib/workshop/builder.rb', line 92 def archive_file project.build_directory + '/core.a' end |
#clean ⇒ Object
27 28 29 |
# File 'lib/workshop/builder.rb', line 27 def clean FileUtils.rm_rf(project.build_directory) end |
#code_files_in_directory(directory) ⇒ Object
192 193 194 195 196 |
# File 'lib/workshop/builder.rb', line 192 def code_files_in_directory(directory) return [] unless directory Dir[directory + '/**/*.c'] + Dir[directory + '/**/*.cpp'] end |
#compile ⇒ Object
66 67 68 69 70 |
# File 'lib/workshop/builder.rb', line 66 def compile all_source_files.each do |filename| sh compile_command_for(filename) end end |
#compile_command_for(filename) ⇒ Object
47 48 49 50 51 52 53 54 55 |
# File 'lib/workshop/builder.rb', line 47 def compile_command_for(filename) [ tools.compiler(filename), compiler_flags, include_flags, filename, "-o #{output_file(filename)}" ].join(' ') end |
#compiler_flags ⇒ Object
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
# File 'lib/workshop/builder.rb', line 158 def compiler_flags [ '-c', '-g', '-Os', '-Wall', '-fno-exceptions', '-ffunction-sections', '-fdata-sections', ("-mmcu=#{project.build_mcu}" if project.build_mcu), ("-DF_CPU=#{project.build_f_cpu}" if project.build_f_cpu), '-MMD', ("-DUSB_VID=#{project.build_vid}" if project.build_vid), ("-DUSB_PID=#{project.build_pid}" if project.build_pid), ("-DARDUINO=#{project.build_arduino}" if project.build_arduino) ].join(' ') end |
#core_files ⇒ Object
31 32 33 |
# File 'lib/workshop/builder.rb', line 31 def core_files code_files_in_directory project.arduino_core_directory end |
#create_build_directory ⇒ Object
23 24 25 |
# File 'lib/workshop/builder.rb', line 23 def create_build_directory Dir.mkdir(project.build_directory) unless Dir.exists?(project.build_directory) end |
#create_eeprom ⇒ Object
141 142 143 |
# File 'lib/workshop/builder.rb', line 141 def create_eeprom sh eeprom_command end |
#create_hex ⇒ Object
154 155 156 |
# File 'lib/workshop/builder.rb', line 154 def create_hex sh hex_command end |
#eeprom_command ⇒ Object
132 133 134 135 136 137 138 139 |
# File 'lib/workshop/builder.rb', line 132 def eeprom_command [ tools.avr_objcopy, eeprom_flags, elf_file, eeprom_file, ].join(' ') end |
#eeprom_file ⇒ Object
100 101 102 |
# File 'lib/workshop/builder.rb', line 100 def eeprom_file project.build_directory + '/' + main_name + '.eep' end |
#eeprom_flags ⇒ Object
184 185 186 |
# File 'lib/workshop/builder.rb', line 184 def eeprom_flags '-O ihex -j .eeprom --set-section-flags=.eeprom=alloc,load --no-change-warnings --change-section-lma .eeprom=0' end |
#elf_file ⇒ Object
96 97 98 |
# File 'lib/workshop/builder.rb', line 96 def elf_file project.build_directory + '/' + main_name + '.elf' end |
#hex_command ⇒ Object
145 146 147 148 149 150 151 152 |
# File 'lib/workshop/builder.rb', line 145 def hex_command [ tools.avr_objcopy, hex_flags, elf_file, hex_file, ].join(' ') end |
#hex_file ⇒ Object
104 105 106 |
# File 'lib/workshop/builder.rb', line 104 def hex_file project.build_directory + '/' + main_name + '.hex' end |
#hex_flags ⇒ Object
188 189 190 |
# File 'lib/workshop/builder.rb', line 188 def hex_flags '-O ihex -R .eeprom' end |
#include_directories ⇒ Object
180 181 182 |
# File 'lib/workshop/builder.rb', line 180 def include_directories [project.arduino_core_directory, project.arduino_variant_directory] + project.includes end |
#include_flags ⇒ Object
176 177 178 |
# File 'lib/workshop/builder.rb', line 176 def include_flags include_directories.compact.map { |include| "-I#{File.(include)}"}.join(' ') end |
#link ⇒ Object
128 129 130 |
# File 'lib/workshop/builder.rb', line 128 def link sh link_command end |
#link_command ⇒ Object
116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/workshop/builder.rb', line 116 def link_command [ tools.avr_gcc, linker_flags, "-o #{elf_file}", main_output_file, archive_file, "-L #{project.build_directory}", '-lm' ].join(' ') end |
#linker_flags ⇒ Object
108 109 110 111 112 113 114 |
# File 'lib/workshop/builder.rb', line 108 def linker_flags [ '-Os', '-Wl,--gc-sections', "-mmcu=#{project.build_mcu}" ].join(' ') end |
#main_filename ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/workshop/builder.rb', line 15 def main_filename if project.main_filename project.app_directory + '/' + project.main_filename else source_files.first end end |
#main_name ⇒ Object
11 12 13 |
# File 'lib/workshop/builder.rb', line 11 def main_name project.name.parameterize.underscore end |
#main_output_file ⇒ Object
88 89 90 |
# File 'lib/workshop/builder.rb', line 88 def main_output_file project.build_directory + '/' + File.basename(main_filename) + '.o' end |
#o_files_to_archive ⇒ Object
72 73 74 75 76 |
# File 'lib/workshop/builder.rb', line 72 def o_files_to_archive all_source_files.reject do |filename| filename == main_output_file end.map { |filename| output_file(filename) } end |
#output_file(filename) ⇒ Object
84 85 86 |
# File 'lib/workshop/builder.rb', line 84 def output_file(filename) project.build_directory + '/' + File.basename(filename) + '.o' end |
#source_files ⇒ Object
39 40 41 |
# File 'lib/workshop/builder.rb', line 39 def source_files code_files_in_directory project.source_directory end |
#variant_files ⇒ Object
35 36 37 |
# File 'lib/workshop/builder.rb', line 35 def variant_files code_files_in_directory(project.arduino_variant_directory) end |