-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathRakefile
236 lines (204 loc) · 5.12 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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
require "fileutils"
PICO_SDK_TAG = "2.1.0"
PICO_EXTRAS_TAG = "sdk-#{PICO_SDK_TAG}"
def mruby_config
case ENV['BOARD']&.downcase
when 'pico2'
'r2p2-cortex-m33'
when 'pico_wifi'
'r2p2_wifi-cortex-m0plus'
when 'pico_ble'
'r2p2_ble-cortex-m0plus'
else
'r2p2-cortex-m0plus'
end
end
def cmake_flags
flags = []
flags << (ENV['MSC']&.downcase == 'sd' ? "PICORUBY_MSC_SD=yes" : "PICORUBY_MSC_FLASH=yes")
case ENV['BOARD']&.downcase
when 'pico_wifi'
flags << "PICO_WIFI=yes"
when 'pico_ble'
flags << "PICO_BLE=yes"
when 'pico2'
flags << "PICO2=yes"
end
flags.join(" ")
end
def def_board
case ENV['BOARD']&.downcase
when 'pico2'
'-DPICO_PLATFORM=rp2350 -DPICO_BOARD=pico2'
when 'pico_wifi', 'pico_ble'
'-DPICO_PLATFORM=rp2040 -DPICO_BOARD=pico_w'
else
'-DPICO_PLATFORM=rp2040 -DPICO_BOARD=pico'
end
end
def build_dir
case ENV['BOARD']&.downcase
when 'pico2'
'build_pico2'
when 'pico_wifi'
'build_pico_wifi'
when 'pico_ble'
'build_pico_ble'
else
'build_pico'
end
end
task :default do
puts "Specify a task:"
puts " rake pico # build for RP2040"
puts " rake pico_wifi # build for RP2040 with CYW43 WiFi"
puts " rake pico_ble # build for RP2040 with CYW43 BLE"
puts " rake pico2 # build for RP2350"
end
desc "build for RP2040"
task :pico do
ENV['BOARD'] = 'pico'
sh "rake all"
end
desc "build for RP2040 with debug flags"
task :pico_debug do
ENV['BOARD'] = 'pico'
ENV['PICORUBY_DEBUG'] = '1'
sh "rake debug"
end
desc "build for RP2040 with CYW43 WiFi"
task :pico_wifi do
ENV['BOARD'] = 'pico_wifi'
sh "rake all"
end
desc "build for RP2040 with CYW43 WiFi with debug flags"
task :pico_wifi_debug do
ENV['BOARD'] = 'pico_wifi'
ENV['PICORUBY_DEBUG'] = '1'
sh "rake debug"
end
desc "build for RP2040 with CYW43 BLE"
task :pico_ble do
ENV['BOARD'] = 'pico_ble'
sh "rake all"
end
desc "build for RP2040 with CYW43 BLE with debug flags"
task :pico_ble_debug do
ENV['BOARD'] = 'pico_ble'
ENV['PICORUBY_DEBUG'] = '1'
sh "rake debug"
end
desc "build for RP2350"
task :pico2 do
ENV['BOARD'] = 'pico2'
sh "rake all"
end
desc "build for RP2350 with debug flags"
task :pico2_debug do
ENV['BOARD'] = 'pico2'
ENV['PICORUBY_DEBUG'] = '1'
sh "rake debug"
end
desc "clean built for RP2xxx"
task clean_all: [:clean_pico, :clean_pico_wifi, :clean_pico_ble, :clean_pico2]
desc "clean built for RP2040"
task :clean_pico do
ENV['BOARD'] = 'pico'
sh "rake clean"
sh "cmake --build build_pico --target clean"
end
desc "clean built for RP2040 with CYW43 WiFi"
task :clean_pico_wifi do
ENV['BOARD'] = 'pico_wifi'
sh "rake clean"
sh "cmake --build build_pico_wifi --target clean"
end
desc "clean built for RP2040 with CYW43 BLE"
task :clean_pico_ble do
ENV['BOARD'] = 'pico_ble'
sh "rake clean"
sh "cmake --build build_pico_ble --target clean"
end
desc "clean built for RP2350"
task :clean_pico2 do
ENV['BOARD'] = 'pico2'
sh "rake clean"
sh "cmake --build build_pico2 --target clean"
end
task :setup do
sh "git submodule update --init"
FileUtils.cd "lib/picoruby" do
sh "bundle install"
end
end
desc "build production"
task :all => [:libmruby, :cmake_production, :build]
desc "clean then build debug"
task :debug => [:libmruby, :cmake_debug, :build]
file "lib/picoruby" do
## sh "git submodule update --init --recursive"
end
task :libmruby => "lib/picoruby" do
FileUtils.cd "lib/picoruby" do
sh "rake test"
sh "MRUBY_CONFIG=#{mruby_config} rake"
end
end
def cmake_cmd(env)
"#{cmake_flags} cmake #{def_board} -DCMAKE_BUILD_TYPE=#{env} -B #{build_dir}"
end
task :cmake_debug do
sh cmake_cmd("Debug")
end
task :cmake_production do
sh cmake_cmd("Release")
end
task :check_pico_sdk => :check_pico_sdk_path do
FileUtils.cd ENV['PICO_SDK_PATH'] do
if `git describe --tags --exact-match`.chomp != PICO_SDK_TAG
raise <<~MSG
pico-sdk #{PICO_SDK_TAG} is not checked out!\n
Tips for dealing with:\n
cd $PICO_SDK_PATH && git pull && git checkout #{PICO_SDK_TAG} && git submodule update --recursive\n
MSG
end
end
FileUtils.cd ENV['PICO_EXTRAS_PATH'] do
if `git describe --tags --exact-match`.chomp != PICO_EXTRAS_TAG
raise <<~MSG
pico-extras #{PICO_EXTRAS_TAG} is not checked out!\n
Tips for dealing with:\n
cd $PICO_EXTRAS_PATH && git pull && git checkout #{PICO_EXTRAS_TAG} && git submodule update --recursive\n
MSG
end
end
end
task :check_pico_sdk_path do
%w(PICO_SDK_PATH PICO_EXTRAS_PATH).each do |env|
unless ENV[env]
raise <<~MSG
Environment variable `#{env}` does not exist!
MSG
end
end
end
desc "build without cmake preparation"
task :build => :check_pico_sdk do
sh "cmake --build #{build_dir}"
end
BUILD_DIRS = %w(build_pico build_pico_wifi build_pico_ble build_pico2)
desc "deep clean built"
task :deep_clean do
FileUtils.cd "lib/picoruby" do
sh "MRUBY_CONFIG=#{mruby_config} rake deep_clean"
end
BUILD_DIRS.each do |dir|
FileUtils.rm_rf "#{dir}/*"
end
end
desc "clean built"
task :clean do
FileUtils.cd "lib/picoruby" do
sh "MRUBY_CONFIG=#{mruby_config} rake clean"
end
end