-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
118 lines (99 loc) · 3.18 KB
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
verbose(false)
PART = "STM32F429"
CC = "arm-none-eabi-gcc"
AR = "arm-none-eabi-ar"
CMSIS = "../STM32CubeF4/Drivers/CMSIS"
HAL = "../STM32CubeF4/Drivers/STM32F4xx_HAL_Driver"
BSP = "../STM32CubeF4/Drivers/BSP/STM32F429I-Discovery"
directory BUILD = 'build'
CFLAGS = "-D #{PART}xx -D USE_HAL_DRIVER -Wall " \
"-Os -nostdlib -fsigned-char -fno-inline -ffunction-sections " \
"-mthumb -mlittle-endian -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 "\
"-I./ -I#{HAL}/Inc -I#{CMSIS}/Include -I#{CMSIS}/Device/ST/STM32F4xx/Include "\
"-I#{BSP}"
# ---------- library common routine ----------
def libraryTask(output,input,taskSym)
object=[]
FileList["#{input}/*.c"].each do |src|
object << "#{BUILD}/#{src.pathmap("%n")}.o"
end
raise "No #{input} sources found for #{output}." unless not object.empty?
task taskSym => output
file output => [BUILD,*object] do
object.each do |obj|
puts "AR #{obj} -> #{output}"
sh "#{AR} -r #{output} #{obj}"
end
sh "#{AR} -s #{output}"
end
rule '.o' => ->(out){"#{input}/#{out.pathmap("%n")}.c"} do |obj|
puts "CC #{obj.source.pathmap("%f")} -> #{obj.name}"
sh "#{CC} #{CFLAGS} -c -o #{obj.name} #{obj.source}"
end
end
# ---------- library config header ----------
conf_h = "stm32f4xx_hal_conf.h"
template_h = "#{HAL}/Inc/stm32f4xx_hal_conf_template.h"
desc "Import generic hal library configuration header"
task :config => template_h
file conf_h => template_h do
cp template_h, conf_h
end
# ---------- libraries for cpu and kit ----------
desc "Build stm32f429 cpu hal library"
libraryTask("#{BUILD}/libstm32f4hal.a", "#{HAL}/Src", :hal)
desc "Build stm32f429i-disco kit bsp library"
libraryTask("#{BUILD}/libstm32f4bsp.a", "#{BSP}", :bsp)
# ---------- mruby library ----------
MRUBY = "../mruby"
raise "No #{MRUBY} directory found." unless File.exist?("#{MRUBY}")
desc "Build mruby library"
task :mruby => BUILD do
Dir.chdir("#{MRUBY}") do
sh 'rake MRUBY_CONFIG="../mruby-cube/build_config_mruby.rb"'
end
cp "#{MRUBY}/build/#{PART.downcase}/lib/libmruby.a", "#{BUILD}"
end
# ---------- clean up before a rebuild ----------
desc "Delete build outputs"
task :clean do
rm_rf "#{BUILD}"
Dir.chdir("#{MRUBY}") do
sh 'rake clean'
end
end
# ---------- default build everything ----------
desc "Build all"
task :default =>[conf_h, :hal, :bsp, :mruby]
# ---------- hack stmicro dos include paths ----------
desc "Fix dos-only stmicro include syntax"
task :slash do
slashed=[]
["#{BSP}",
"#{BSP}/../Components/l3gd20",
"#{BSP}/../Components/stmpe811",
"#{BSP}/../Components/ili9341"].each do |prefix|
FileList["#{prefix}/*.c","#{prefix}/*.h"].each do |src|
File.open(src,'r').each_line do |line|
if line.match(/\s*#\s*include.*\\.*/)
# make a list of files with problems
slashed << src
break
end
end
end
end
slashed.each do |src|
puts src
mv(src,src+'.bak')
File.open(src,'w') do |dest|
File.open(src+'.bak','r').each_line do |line|
if line.match(/\s*#\s*include.*\\.*/)
# replace backslashes within include lines
line.gsub!('\\','/')
end
dest.write(line)
end
end
end
end