5 verbose(ENV['verbose'] == '1')
6 DEBUG = ENV['debug'] == '1'
7 TESTING = ENV['testing'] == '1'
10 Pathname(path).each_filename.to_a[1..-1]
14 File.join('src', pop_path(File.dirname(fn)), File.basename(fn).ext(e))
18 (/cygwin|mswin|mingw|bccwin|wince|emx/ =~ RUBY_PLATFORM) != nil
21 # Makefile .d file loader to be used with the import file loader.
22 # this emulates the -include $(DEPFILES) in a Makefile for the generated .d files
28 # Load the makefile dependencies in +fn+.
30 return if ! File.exists?(fn)
32 lines.gsub!(/\\ /, SPACE_MARK)
33 lines.gsub!(/#[^\n]*\n/m, "")
34 lines.gsub!(/\\\n/, ' ')
35 lines.each_line do |line|
42 # Process one logical line of makefile data.
43 def process_line(line)
44 file_tasks, args = line.split(':', 2)
46 dependents = args.split.map { |d| respace(d) }
47 file_tasks.scan(/\S+/) do |file_task|
48 file_task = respace(file_task)
49 file file_task => dependents
54 str.tr SPACE_MARK, ' '
59 Rake.application.add_loader('d', DfileLoader.new)
64 ARCHITECTURE = 'armv7-m'
66 MBED_DIR = './mbed/drop'
68 TOOLSBIN = './gcc-arm-none-eabi/bin/arm-none-eabi-'
70 CCPP = "#{TOOLSBIN}g++"
72 OBJCOPY = "#{TOOLSBIN}objcopy"
73 SIZE = "#{TOOLSBIN}size"
75 # include a defaults file if present
76 load 'rakefile.defaults' if File.exists?('rakefile.defaults')
82 ENABLE_DEBUG_MONITOR= '0'
86 BUILDTYPE= ENV['BUILDTYPE'] || 'Checked' unless defined? BUILDTYPE
87 puts "#{BUILDTYPE} build"
89 ENABLE_DEBUG_MONITOR = ENV['ENABLE_DEBUG_MONITOR'] || '0' unless defined? ENABLE_DEBUG_MONITOR
91 # set default baud rate
92 DEFAULT_SERIAL_BAUD_RATE= ENV['BAUDRATE'] || '115200' unless defined? DEFAULT_SERIAL_BAUD_RATE
94 # set to true to eliminate all the network code
95 unless defined? NONETWORK
96 NONETWORK= false || TESTING
99 # list of modules to exclude, include directory it is in
100 # e.g for a CNC machine
101 #EXCLUDE_MODULES = %w(tools/touchprobe tools/laser tools/temperaturecontrol tools/extruder)
103 # generate regex of modules to exclude and defines
104 exclude_defines, excludes = EXCLUDE_MODULES.collect { |e| [e.tr('/', '_').upcase, e.sub('/', '\/')] }.transpose
106 # see if network is enabled
107 if ENV['NONETWORK'] || NONETWORK
109 excludes << '\/libs\/Network\/'
110 puts "Excluding Network code"
118 excludes << 'panel\/screens\/3dprinter'
121 excludes << 'panel\/screens\/cnc'
126 # add modules to be tested here
127 TESTMODULES= %w(tools/temperatureswitch) unless defined? EXCLUDE_MODULES
128 puts "Modules under test: #{TESTMODULES}"
129 excludes << %w(Kernel.cpp main.cpp) # we replace these with mock versions in testframework
131 frameworkfiles= FileList['src/testframework/*.{c,cpp}', 'src/testframework/easyunit/*.{c,cpp}']
132 extrafiles= FileList['src/modules/communication/SerialConsole.cpp', 'src/modules/communication/utils/Gcode.cpp', 'src/modules/robot/Conveyor.cpp', 'src/modules/robot/Block.cpp']
133 testmodules= FileList['src/libs/**/*.{c,cpp}'].include(TESTMODULES.collect { |e| "src/modules/#{e}/**/*.{c,cpp}"}).include(TESTMODULES.collect { |e| "src/testframework/unittests/#{e}/*.{c,cpp}"}).exclude(/#{excludes.join('|')}/)
134 SRC = frameworkfiles + extrafiles + testmodules
136 excludes << %w(testframework)
137 SRC = FileList['src/**/*.{c,cpp}'].exclude(/#{excludes.join('|')}/)
138 puts "WARNING Excluding modules: #{EXCLUDE_MODULES.join(' ')}" unless exclude_defines.empty?
142 OBJ = SRC.collect { |fn| File.join(OBJDIR, pop_path(File.dirname(fn)), File.basename(fn).ext('o')) } +
143 %W(#{OBJDIR}/configdefault.o #{OBJDIR}/mbed_custom.o)
145 # list of header dependency files generated by compiler
146 DEPFILES = OBJ.collect { |fn| File.join(File.dirname(fn), File.basename(fn).ext('d')) }
148 # create destination directories
150 d= File.join(OBJDIR, pop_path(File.dirname(s)))
151 FileUtils.mkdir_p(d) unless Dir.exists?(d)
154 INCLUDE_DIRS = [Dir.glob(['./src/**/', './mri/**/'])].flatten
155 MBED_INCLUDE_DIRS = %W(#{MBED_DIR}/ #{MBED_DIR}/LPC1768/)
157 INCLUDE = (INCLUDE_DIRS+MBED_INCLUDE_DIRS).collect { |d| "-I#{d}" }.join(" ")
159 if ENABLE_DEBUG_MONITOR == '1'
160 # Can add MRI_UART_BAUD=115200 to next line if GDB fails to connect to MRI.
161 # Tends to happen on some Linux distros but not Windows and OS X.
162 MRI_UART = 'MRI_UART_0'
163 MRI_BREAK_ON_INIT = 1 unless defined? MRI_BREAK_ON_INIT
165 MRI_UART = 'MRI_UART_0 MRI_UART_SHARE'
166 MRI_BREAK_ON_INIT = 0 unless defined? MRI_BREAK_ON_INIT
169 # Configure MRI variables based on BUILD_TYPE build type variable.
170 case BUILDTYPE.downcase
174 MRI_SEMIHOST_STDIO = 0 unless defined? MRI_SEMIHOST_STDIO
178 MRI_SEMIHOST_STDIO = 1 unless defined? MRI_SEMIHOST_STDIO
182 MRI_SEMIHOST_STDIO = 1 unless defined? MRI_SEMIHOST_STDIO
186 MRI_SEMIHOST_STDIO = 0 unless defined? MRI_SEMIHOST_STDIO
189 MRI_ENABLE = 1 unless defined? MRI_ENABLE # set to 0 to disable MRI
190 MRI_LIB = MRI_ENABLE == 1 ? './mri/mri.ar' : ''
191 MBED_LIB = "#{MBED_DIR}/LPC1768/GCC_ARM/libmbed.a"
193 SYS_LIBS = '-lstdc++_s -lsupc++_s -lm -lgcc -lc_s -lgcc -lc_s -lnosys'
194 LIBS = [MBED_LIB, SYS_LIBS, MRI_LIB].join(' ')
196 MRI_DEFINES = %W(-DMRI_ENABLE=#{MRI_ENABLE} -DMRI_INIT_PARAMETERS='"#{MRI_UART}"' -DMRI_BREAK_ON_INIT=#{MRI_BREAK_ON_INIT} -DMRI_SEMIHOST_STDIO=#{MRI_SEMIHOST_STDIO})
198 defines = %w(-DCHECKSUM_USE_CPP -D__LPC17XX__ -DTARGET_LPC1768 -DWRITE_BUFFER_DISABLE=0 -DSTACK_SIZE=3072 -DCHECKSUM_USE_CPP)
199 defines += exclude_defines.collect{|d| "-DNO_#{d}"}
200 defines += MRI_DEFINES
201 defines << "-DDEFAULT_SERIAL_BAUD_RATE=#{DEFAULT_SERIAL_BAUD_RATE}"
202 defines << '-DDEBUG' if OPTIMIZATION == 0
203 defines << '-DNONETWORK' if nonetwork
204 defines << '-DCNC' if cnc
206 DEFINES= defines.join(' ')
208 # Compiler flags used to enable creation of header dependencies.
210 CFLAGS = DEPFLAGS + "-Wall -Wextra -Wno-unused-parameter -Wcast-align -Wpointer-arith -Wredundant-decls -Wcast-qual -Wcast-align -O#{OPTIMIZATION} -g3 -mcpu=cortex-m3 -mthumb -mthumb-interwork -ffunction-sections -fdata-sections -fno-delete-null-pointer-checks"
211 CPPFLAGS = CFLAGS + ' -fno-rtti -std=gnu++11 -fno-exceptions'
212 CXXFLAGS = CFLAGS + ' -fno-rtti -std=gnu++11 -fexceptions' # used for a .cxx file that needs to be compiled with exceptions
214 MRI_WRAPS = MRI_ENABLE == 1 ? ',--wrap=_read,--wrap=_write,--wrap=semihost_connected' : ''
216 # Linker script to be used. Indicates what code should be placed where in memory.
217 LSCRIPT = "#{MBED_DIR}/LPC1768/GCC_ARM/LPC1768.ld"
218 LDFLAGS = "-mcpu=cortex-m3 -mthumb -specs=./build/startfile.spec" +
219 " -Wl,-Map=#{OBJDIR}/smoothie.map,--cref,--gc-sections,--wrap=_isatty,--wrap=malloc,--wrap=realloc,--wrap=free" +
222 " -u _scanf_float -u _printf_float"
224 HTTPD_FSDATA = './src/libs/Network/uip/webserver/httpd-fsdata2.h'
228 # generate the header dependencies if they exist
232 FileUtils.rm_rf(OBJDIR)
235 task :realclean => [:clean] do
236 sh "cd ./mbed;make clean"
239 desc "Build the built-in web pages"
240 task :webui => [HTTPD_FSDATA]
242 task :default => [:build]
244 task :build => [MBED_LIB, :version, "#{PROG}.bin", :size]
248 VERSION = ' -D__GITVERSIONSTRING__=\"place-holder\"'
250 v1= `git symbolic-ref HEAD 2> /dev/null`
251 v2= `git log --pretty=format:%h -1`
252 VERSION = ' -D__GITVERSIONSTRING__=\"' + "#{v1[11..-1].chomp}-#{v2}".chomp + '\"'
253 FileUtils.touch './src/version.cpp' # we want it compiled everytime
257 desc "Upload via DFU"
259 sh "dfu-util -R -d 1d50:6015 -D #{OBJDIR}/#{PROG}.bin"
263 sh "#{SIZE} #{OBJDIR}/#{PROG}.elf"
266 # build internal web page
267 WEB_SOURCE_FILES= FileList['./src/libs/Network/uip/webserver/httpd-fs-src/**/*']
268 WEBDIR = './src/libs/Network/uip/webserver/httpd-fs'
269 file HTTPD_FSDATA => WEB_SOURCE_FILES do
270 FileUtils.rm_rf WEBDIR
271 FileUtils.mkdir WEBDIR
272 FileUtils.cp WEB_SOURCE_FILES, WEBDIR
273 # TODO minify some files
274 # sh 'java -jar yuicompressor-2.4.8.jar file -o file'
275 sh 'cd ./src/libs/Network/uip/webserver; perl makefsdata.pl'
280 puts "Building Mbed Using Make"
281 sh "cd ./mbed;make all"
284 file "#{OBJDIR}/mbed_custom.o" => ['./build/mbed_custom.cpp'] do |t|
285 puts "Compiling mbed_custom.cpp"
286 sh "#{CCPP} #{CPPFLAGS} #{INCLUDE} #{DEFINES} -c -o #{t.name} #{t.prerequisites[0]}"
289 file "#{OBJDIR}/configdefault.o" => 'src/config.default' do |t|
290 sh "cd ./src; ../#{OBJCOPY} -I binary -O elf32-littlearm -B arm --readonly-text --rename-section .data=.rodata.configdefault config.default ../#{OBJDIR}/configdefault.o"
293 file "#{PROG}.bin" => ["#{PROG}.elf"] do
294 sh "#{OBJCOPY} -O binary #{OBJDIR}/#{PROG}.elf #{OBJDIR}/#{PROG}.bin"
297 file "#{PROG}.elf" => OBJ do |t|
299 sh "#{LD} #{LDFLAGS} #{OBJ} #{LIBS} -o #{OBJDIR}/#{t.name}"
302 #arm-none-eabi-objcopy -R .stack -O ihex ../LPC1768/main.elf ../LPC1768/main.hex
303 #arm-none-eabi-objdump -d -f -M reg-names-std --demangle ../LPC1768/main.elf >../LPC1768/main.disasm
305 rule '.o' => lambda{ |objfile| obj2src(objfile, 'cpp') } do |t|
306 puts "Compiling #{t.source}"
307 sh "#{CCPP} #{CPPFLAGS} #{INCLUDE} #{DEFINES} #{VERSION} -c -o #{t.name} #{t.source}"
310 rule '.o' => lambda{ |objfile| obj2src(objfile, 'cxx') } do |t|
311 puts "Compiling #{t.source}"
312 sh "#{CCPP} #{CXXFLAGS} #{INCLUDE} #{DEFINES} #{VERSION} -c -o #{t.name} #{t.source}"
315 rule '.o' => lambda{ |objfile| obj2src(objfile, 'c') } do |t|
316 puts "Compiling #{t.source}"
317 sh "#{CC} #{CFLAGS} #{INCLUDE} #{DEFINES} #{VERSION} -c -o #{t.name} #{t.source}"