mkduino 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5d2ade613b46584cd90dbd376faef4987aa974ef
4
- data.tar.gz: e89abc2128f6b7f86a395e3f4b68450aab1488d8
3
+ metadata.gz: 11a2abcc1b68c38d34f5bf1763fd2cf5227a4e01
4
+ data.tar.gz: e89d95f2c2733d0aa92cd3d863808ad16eb5bfb2
5
5
  SHA512:
6
- metadata.gz: 254bc74e8c603664cc0c66967d6dc6019bbd1358ccec8891892dab4a5c1ac47a2ce55d9e0bbd6db096f2eee7d9d4633fe43c2adb503cbc2cd4c3a5a16929046b
7
- data.tar.gz: 79dbe0352efcd1c1857d4debc989ef80b5e0792a52a14b9ce388ee660a9880d3a2dac98b14d8f3c5dc77111cfe4c013312c7cab98f23547d6495ace741ae8580
6
+ metadata.gz: dc9e49b821fb7e42562fb9f56f005bfc172029b62b00c874199493b5c9dc286af0ac78ba80e53beb38acbea34b5df538b3160856d6e8f635651afbf991a23a02
7
+ data.tar.gz: 6f67a86c6b0936e9db46082e96246ce80f30b327bf8308964818f519f1c68e7fe76fe9a89efb4bb0b6b0943cbdb43352d0eb72cbfdcee0a1535bfc5e71cf9b6c
@@ -0,0 +1,281 @@
1
+ #
2
+ # Class that keeps up with the stuff needed for the Makefile.am file
3
+ # this is most of the stuff needed to generate the automake stuff
4
+ #
5
+
6
+ module Mkduino
7
+ class MakefileAm
8
+ attr_accessor :source_files, :header_files, :arduino_sources
9
+ attr_accessor :project_name, :project_author, :project_dir
10
+ attr_accessor :project_includes
11
+ # future stuff
12
+ attr_accessor :git_project
13
+ attr_accessor :board, :common_includes
14
+
15
+ def initialize
16
+ @project_dir = Dir.pwd
17
+ @project_name = File.basename @project_dir
18
+ @project_name.tr!('.-','__')
19
+ @source_files = []
20
+ @header_files = []
21
+ @project_includes = []
22
+ @arduino_sources = []
23
+ @arduino_includes = []
24
+ @arduino_libraries = []
25
+ @project_author = {}
26
+ @git_project = nil
27
+ @common_libraries = ['arduino', 'spi','wire']
28
+ @libraries_to_skip = {
29
+ 'standard' => ['Esplora','GSM','Robot_Control','Robot_Motor','TFT','robot']
30
+ }
31
+ @board='standard'
32
+ @project_author[:username] = ENV['USERNAME']
33
+ git_exists = `which git`.chomp
34
+ if git_exists && git_exists.length > 0
35
+ @project_author[:name] = `git config --get user.name`.chomp
36
+ @project_author[:email] = `git config --get user.email`.chomp
37
+ @git_project = `git remote show -n origin 2> /dev/null | grep 'Fetch URL:' | cut -f 5 -d ' '`.chomp
38
+ else
39
+ @project_author[:name] = @project_author[:username]
40
+ @project_author[:email]= @project_author[:username]
41
+ @git_project = "no_git_project"
42
+ end
43
+ end
44
+
45
+ #
46
+ # Add a source file that we found in this directory
47
+ #
48
+ def add_source_file(file)
49
+ @source_files << "../" + Pathname.new(file).relative_path_from(Pathname.new(@project_dir)).to_s
50
+ end
51
+ def add_header_file(file)
52
+ @header_files << "../" + Pathname.new(file).relative_path_from(Pathname.new(@project_dir)).to_s
53
+ end
54
+
55
+ def add_include_path file
56
+ pn = Pathname.new(file)
57
+ puts "!! ******** File #{file} not found ******** " unless pn.exist?
58
+ include_dir = pn.file? ? pn.dirname : file
59
+ @project_includes << include_dir.to_s unless @project_includes.include? include_dir.to_s
60
+ end
61
+
62
+
63
+ #
64
+ # As libraries are found, add them to our collection
65
+ # if they're not already there
66
+ #
67
+ def add_arduino_library library
68
+ @arduino_libraries << library if !arduino_library library
69
+ end
70
+
71
+ #
72
+ # fetch a library from our collection - nil if not there
73
+ #
74
+
75
+ def arduino_library library
76
+ @arduino_libraries.each do |l|
77
+ return l if l.name == library
78
+ end
79
+ nil
80
+ end
81
+
82
+ #
83
+ # output the Makefile.am macro needed for some include
84
+ # files from libraries that are apparently always needed
85
+ #
86
+ def common_includes
87
+ @arduino_libraries.collect do |l|
88
+ @common_libraries.include?(l.name) ? "$(lib#{l.name}_a_INCLUDES)" : nil
89
+ end.compact.join(' ')
90
+ end
91
+
92
+
93
+ def source_file_pattern
94
+ /\.([c])(pp|)$/
95
+ end
96
+
97
+ def header_file_pattern
98
+ /\.([h])(pp|)$/
99
+ end
100
+
101
+ #
102
+ # output a list of all the libraries that are needed here
103
+ # for Makefile.am. The project will depend on these
104
+ #
105
+ def arduino_library_names
106
+ @arduino_libraries.collect do |l|
107
+ l.library_name
108
+ end
109
+ end
110
+
111
+ #
112
+ # return the linker entries for all of the libraries that we
113
+ # know about
114
+ #
115
+ def arduino_linker_entries
116
+ @arduino_libraries.collect do |l|
117
+ "-l#{l.linker_name}"
118
+ end
119
+ end
120
+
121
+ #
122
+ # after finding all of the Arduino libraries, go through each
123
+ # one of them asking them to output themselves.
124
+ #
125
+
126
+ def output_arduino_libraries
127
+ output = @arduino_libraries.collect do |l|
128
+ l.makefile_am_output
129
+ end.join("\n")
130
+ #
131
+ # After all of the library compile lines are output, output
132
+ # a comprehensive list of all of the include directories associated
133
+ # with the libraries. Used for the source project
134
+ #
135
+ output += "\nLIBRARY_INCLUDES="
136
+ output += @arduino_libraries.collect do |l|
137
+ "$(lib#{l.name}_a_INCLUDES)"
138
+ end.join(' ')
139
+ end
140
+
141
+ def find_arduino_libraries libraries_dir
142
+ lib = nil
143
+ Find.find(libraries_dir) do |path|
144
+ if FileTest.directory?(path)
145
+ if File.basename(path)[0] == ?. || File.basename(path) == 'examples' ||
146
+ (@libraries_to_skip[@board] && @libraries_to_skip[@board].include?(File.basename(path)) )
147
+ Find.prune # Don't look any further into this directory.
148
+ else
149
+ if File.dirname(path) == libraries_dir
150
+ lib_name = path.split('/')[-1]
151
+ lib = arduino_library(lib_name) || ArduinoLibrary.new(lib_name)
152
+ add_arduino_library lib
153
+ end
154
+ next
155
+ end
156
+ elsif path =~ source_file_pattern
157
+ lib.add_source_file path
158
+ elsif path =~ header_file_pattern
159
+ lib.add_include_path path
160
+ end
161
+ end
162
+ end
163
+
164
+ def find_source_files
165
+ #
166
+ # Root around for some source file
167
+ # and add them to the Makefile.am
168
+ #
169
+ Find.find(Dir.pwd) do |path|
170
+ if FileTest.directory?(path)
171
+ if File.basename(path)[0] == ?.
172
+ Find.prune # Don't look any further into this directory.
173
+ else
174
+ next
175
+ end
176
+ elsif path =~ source_file_pattern
177
+ add_source_file path
178
+ elsif path =~ header_file_pattern
179
+ add_header_file path
180
+ add_include_path path
181
+
182
+ end
183
+ end
184
+
185
+ #
186
+ # If no source files were found, make
187
+ # the src/ directory and put in a
188
+ # sample main.cpp file
189
+ #
190
+ if source_files.length < 1
191
+ `mkdir src` unless Dir.exist?('src')
192
+ File.open('src/main.cpp',"w") do |f|
193
+ f.puts <<-MAIN_CPP
194
+ #include <Arduino.h>
195
+
196
+ extern "C" void __cxa_pure_virtual(void) {
197
+ while(1);
198
+ }
199
+
200
+ void setup() {
201
+ Serial.begin(115200);
202
+ Serial.println("Startup...");
203
+ }
204
+
205
+ void loop() {
206
+ }
207
+
208
+
209
+
210
+ int main(void)
211
+ {
212
+ init();
213
+ setup();
214
+ for (;;){
215
+ loop();
216
+ }
217
+ return 0;
218
+ }
219
+ MAIN_CPP
220
+ end
221
+ add_source_file project_dir + '/src/main.cpp'
222
+ end
223
+ end
224
+
225
+
226
+
227
+
228
+ def write_makefile_am
229
+ puts "Writing Makefile.am"
230
+ File.open('Makefile.am',"w") do |f|
231
+ f.puts <<-MAKEFILE_AM
232
+ ## Process this file with automake to produce Makefile.in
233
+ bin_PROGRAMS=#{self.project_name}
234
+ # MCU=atmega1280
235
+ MCU=atmega328p
236
+ F_CPU=-DF_CPU=16000000
237
+ ARDUINO_VERSION=-DARDUINO=105
238
+ ARDUINO_INSTALL=/usr/share/arduino/hardware/arduino
239
+ ARDUINO_CORES=$(ARDUINO_INSTALL)/cores/arduino
240
+ ARDUINO_VARIANTS=$(ARDUINO_INSTALL)/variants/#{self.board}
241
+ ARDUINO_COMMON_INCLUDES=#{self.common_includes}
242
+ ARDUINO_INCLUDE_PATH=-I$(ARDUINO_VARIANTS) $(LIBRARY_INCLUDES)
243
+ nodist_#{self.project_name}_SOURCES=#{self.source_files.join(' ')}
244
+
245
+ #{self.project_name}_CFLAGS=-Wall $(#{self.project_name}_INCLUDES) $(ARDUINO_INCLUDE_PATH) -Wl,--gc-sections -ffunction-sections -fdata-sections -gstabs -mmcu=$(MCU) $(F_CPU) $(ARDUINO_VERSION) -D__AVR_LIBC_DEPRECATED_ENABLE__
246
+ #{self.project_name}_CXXFLAGS=-Wall $(#{self.project_name}_INCLUDES) $(ARDUINO_INCLUDE_PATH) -Wl,--gc-sections -ffunction-sections -fdata-sections -gstabs -mmcu=$(MCU) $(F_CPU) $(ARDUINO_VERSION) -D__AVR_LIBC_DEPRECATED_ENABLE__
247
+ #{self.project_name}_LDFLAGS=-L.
248
+ #{self.project_name}_LDADD=#{self.arduino_linker_entries.join(' ')} -lm
249
+ #{self.project_name}_INCLUDES=-I#{self.project_includes.join("\\\n -I")}
250
+
251
+ lib_LIBRARIES=#{self.arduino_library_names.join(' ')}
252
+ #{self.output_arduino_libraries}
253
+
254
+
255
+ AM_LDFLAGS=
256
+ AM_CXXFLAGS=-g0 -Os
257
+ AM_CFLAGS=-g0 -Os
258
+ VPATH=/usr/share/arduino/hardware/arduino/cores/arduino
259
+
260
+ # AVRDUDE_PORT=/dev/ttyACM0
261
+ AVRDUDE_PORT=/dev/ttyUSB0
262
+ AVRDUDE_PROGRAMMER = arduino
263
+ # UPLOAD_RATE = 115200
264
+ UPLOAD_RATE = 57600
265
+ FORMAT=ihex
266
+
267
+ AVRDUDE_WRITE_FLASH = -U flash:w:$(bin_PROGRAMS).hex
268
+ AVRDUDE_FLAGS = -q -D -C/etc/avrdude/avrdude.conf -p$(MCU) -P$(AVRDUDE_PORT) -c$(AVRDUDE_PROGRAMMER) -b$(UPLOAD_RATE)
269
+
270
+
271
+ .PHONY: upload
272
+ upload: all-am
273
+ $(OBJCOPY) -S -O $(FORMAT) $(bin_PROGRAMS) $(bin_PROGRAMS).hex
274
+ $(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH)
275
+ MAKEFILE_AM
276
+
277
+ end
278
+ end
279
+
280
+ end
281
+ end
@@ -1,3 +1,3 @@
1
1
  module Mkduino
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
data/lib/mkduino.rb CHANGED
@@ -6,6 +6,9 @@ require 'fileutils'
6
6
 
7
7
  include FileUtils
8
8
 
9
+ require_relative "makefile_am"
10
+
11
+
9
12
  module Mkduino
10
13
  #
11
14
  # Represents the files needed for a particular arduino library
@@ -53,286 +56,6 @@ LIBRARY_OUTPUT
53
56
  end
54
57
  end
55
58
 
56
- #
57
- # Class that keeps up with the stuff needed for the Makefile.am file
58
- # this is most of the stuff needed to generate the automake stuff
59
- #
60
-
61
- class MakefileAm
62
- attr_accessor :source_files, :header_files, :arduino_sources
63
- attr_accessor :project_name, :project_author, :project_dir
64
- attr_accessor :project_includes
65
- # future stuff
66
- attr_accessor :git_project
67
- attr_accessor :board, :common_includes
68
-
69
- def initialize
70
- @project_dir = Dir.pwd
71
- @project_name = File.basename @project_dir
72
- @project_name.tr!('.','_')
73
- @source_files = []
74
- @header_files = []
75
- @project_includes = []
76
- @arduino_sources = []
77
- @arduino_includes = []
78
- @arduino_libraries = []
79
- @project_author = {}
80
- @git_project = nil
81
- @common_libraries = ['arduino', 'spi','wire']
82
- @libraries_to_skip = {
83
- 'standard' => ['Esplora','GSM','Robot_Control','Robot_Motor','TFT','robot']
84
- }
85
- @board='standard'
86
- @project_author[:username] = ENV['USERNAME']
87
- git_exists = `which git`.chomp
88
- if git_exists && git_exists.length > 0
89
- @project_author[:name] = `git config --get user.name`.chomp
90
- @project_author[:email] = `git config --get user.email`.chomp
91
- @git_project = `git remote show -n origin 2> /dev/null | grep 'Fetch URL:' | cut -f 5 -d ' '`.chomp
92
- else
93
- @project_author[:name] = @project_author[:username]
94
- @project_author[:email]= @project_author[:username]
95
- @git_project = "no_git_project"
96
- end
97
- end
98
-
99
- #
100
- # Add a source file that we found in this directory
101
- #
102
- def add_source_file(file)
103
- @source_files << "../" + Pathname.new(file).relative_path_from(Pathname.new(@project_dir)).to_s
104
- end
105
- def add_header_file(file)
106
- @header_files << "../" + Pathname.new(file).relative_path_from(Pathname.new(@project_dir)).to_s
107
- end
108
-
109
- def add_include_path file
110
- pn = Pathname.new(file)
111
- puts "!! ******** File #{file} not found ******** " unless pn.exist?
112
- include_dir = pn.file? ? pn.dirname : file
113
- @project_includes << include_dir.to_s unless @project_includes.include? include_dir.to_s
114
- end
115
-
116
-
117
- #
118
- # As libraries are found, add them to our collection
119
- # if they're not already there
120
- #
121
- def add_arduino_library library
122
- @arduino_libraries << library if !arduino_library library
123
- end
124
-
125
- #
126
- # fetch a library from our collection - nil if not there
127
- #
128
-
129
- def arduino_library library
130
- @arduino_libraries.each do |l|
131
- return l if l.name == library
132
- end
133
- nil
134
- end
135
-
136
- #
137
- # output the Makefile.am macro needed for some include
138
- # files from libraries that are apparently always needed
139
- #
140
- def common_includes
141
- @arduino_libraries.collect do |l|
142
- @common_libraries.include?(l.name) ? "$(lib#{l.name}_a_INCLUDES)" : nil
143
- end.compact.join(' ')
144
- end
145
-
146
-
147
- def source_file_pattern
148
- /\.([c])(pp|)$/
149
- end
150
-
151
- def header_file_pattern
152
- /\.([h])(pp|)$/
153
- end
154
-
155
- #
156
- # output a list of all the libraries that are needed here
157
- # for Makefile.am. The project will depend on these
158
- #
159
- def arduino_library_names
160
- @arduino_libraries.collect do |l|
161
- l.library_name
162
- end
163
- end
164
-
165
- #
166
- # return the linker entries for all of the libraries that we
167
- # know about
168
- #
169
- def arduino_linker_entries
170
- @arduino_libraries.collect do |l|
171
- "-l#{l.linker_name}"
172
- end
173
- end
174
-
175
- #
176
- # after finding all of the Arduino libraries, go through each
177
- # one of them asking them to output themselves.
178
- #
179
-
180
- def output_arduino_libraries
181
- output = @arduino_libraries.collect do |l|
182
- l.makefile_am_output
183
- end.join("\n")
184
- #
185
- # After all of the library compile lines are output, output
186
- # a comprehensive list of all of the include directories associated
187
- # with the libraries. Used for the source project
188
- #
189
- output += "\nLIBRARY_INCLUDES="
190
- output += @arduino_libraries.collect do |l|
191
- "$(lib#{l.name}_a_INCLUDES)"
192
- end.join(' ')
193
- end
194
-
195
- def find_arduino_libraries libraries_dir
196
- lib = nil
197
- Find.find(libraries_dir) do |path|
198
- if FileTest.directory?(path)
199
- if File.basename(path)[0] == ?. || File.basename(path) == 'examples' ||
200
- (@libraries_to_skip[@board] && @libraries_to_skip[@board].include?(File.basename(path)) )
201
- Find.prune # Don't look any further into this directory.
202
- else
203
- if File.dirname(path) == libraries_dir
204
- lib_name = path.split('/')[-1]
205
- lib = arduino_library(lib_name) || ArduinoLibrary.new(lib_name)
206
- add_arduino_library lib
207
- end
208
- next
209
- end
210
- elsif path =~ source_file_pattern
211
- lib.add_source_file path
212
- elsif path =~ header_file_pattern
213
- lib.add_include_path path
214
- end
215
- end
216
- end
217
-
218
- def find_source_files
219
- #
220
- # Root around for some source file
221
- # and add them to the Makefile.am
222
- #
223
- Find.find(Dir.pwd) do |path|
224
- if FileTest.directory?(path)
225
- if File.basename(path)[0] == ?.
226
- Find.prune # Don't look any further into this directory.
227
- else
228
- next
229
- end
230
- elsif path =~ source_file_pattern
231
- add_source_file path
232
- elsif path =~ header_file_pattern
233
- add_header_file path
234
- add_include_path path
235
-
236
- end
237
- end
238
-
239
- #
240
- # If no source files were found, make
241
- # the src/ directory and put in a
242
- # sample main.cpp file
243
- #
244
- if source_files.length < 1
245
- `mkdir src` unless Dir.exist?('src')
246
- File.open('src/main.cpp',"w") do |f|
247
- f.puts <<-MAIN_CPP
248
- #include <Arduino.h>
249
-
250
- extern "C" void __cxa_pure_virtual(void) {
251
- while(1);
252
- }
253
-
254
- void setup() {
255
- Serial.begin(115200);
256
- Serial.println("Startup...");
257
- }
258
-
259
- void loop() {
260
- }
261
-
262
-
263
-
264
- int main(void)
265
- {
266
- init();
267
- setup();
268
- for (;;){
269
- loop();
270
- }
271
- return 0;
272
- }
273
- MAIN_CPP
274
- end
275
- add_source_file project_dir + '/src/main.cpp'
276
- end
277
- end
278
-
279
-
280
-
281
-
282
- def write_makefile_am
283
- puts "Writing Makefile.am"
284
- File.open('Makefile.am',"w") do |f|
285
- f.puts <<-MAKEFILE_AM
286
- ## Process this file with automake to produce Makefile.in
287
- bin_PROGRAMS=#{self.project_name}
288
- # MCU=atmega1280
289
- MCU=atmega328p
290
- F_CPU=-DF_CPU=16000000
291
- ARDUINO_VERSION=-DARDUINO=105
292
- ARDUINO_INSTALL=/usr/share/arduino/hardware/arduino
293
- ARDUINO_CORES=$(ARDUINO_INSTALL)/cores/arduino
294
- ARDUINO_VARIANTS=$(ARDUINO_INSTALL)/variants/#{self.board}
295
- ARDUINO_COMMON_INCLUDES=#{self.common_includes}
296
- ARDUINO_INCLUDE_PATH=-I$(ARDUINO_VARIANTS) $(LIBRARY_INCLUDES)
297
- nodist_#{self.project_name}_SOURCES=#{self.source_files.join(' ')}
298
-
299
- #{self.project_name}_CFLAGS=-Wall $(#{self.project_name}_INCLUDES) $(ARDUINO_INCLUDE_PATH) -Wl,--gc-sections -ffunction-sections -fdata-sections -gstabs -mmcu=$(MCU) $(F_CPU) $(ARDUINO_VERSION) -D__AVR_LIBC_DEPRECATED_ENABLE__
300
- #{self.project_name}_CXXFLAGS=-Wall $(#{self.project_name}_INCLUDES) $(ARDUINO_INCLUDE_PATH) -Wl,--gc-sections -ffunction-sections -fdata-sections -gstabs -mmcu=$(MCU) $(F_CPU) $(ARDUINO_VERSION) -D__AVR_LIBC_DEPRECATED_ENABLE__
301
- #{self.project_name}_LDFLAGS=-L.
302
- #{self.project_name}_LDADD=#{self.arduino_linker_entries.join(' ')} -lm
303
- #{self.project_name}_INCLUDES=-I#{self.project_includes.join("\\\n -I")}
304
-
305
- lib_LIBRARIES=#{self.arduino_library_names.join(' ')}
306
- #{self.output_arduino_libraries}
307
-
308
-
309
- AM_LDFLAGS=
310
- AM_CXXFLAGS=-g0 -Os
311
- AM_CFLAGS=-g0 -Os
312
- VPATH=/usr/share/arduino/hardware/arduino/cores/arduino
313
-
314
- # AVRDUDE_PORT=/dev/ttyACM0
315
- AVRDUDE_PORT=/dev/ttyUSB0
316
- AVRDUDE_PROGRAMMER = arduino
317
- # UPLOAD_RATE = 115200
318
- UPLOAD_RATE = 57600
319
- FORMAT=ihex
320
-
321
- AVRDUDE_WRITE_FLASH = -U flash:w:$(bin_PROGRAMS).hex
322
- AVRDUDE_FLAGS = -q -D -C/etc/avrdude/avrdude.conf -p$(MCU) -P$(AVRDUDE_PORT) -c$(AVRDUDE_PROGRAMMER) -b$(UPLOAD_RATE)
323
-
324
-
325
- .PHONY: upload
326
- upload: all-am
327
- $(OBJCOPY) -S -O $(FORMAT) $(bin_PROGRAMS) $(bin_PROGRAMS).hex
328
- $(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH)
329
- MAKEFILE_AM
330
-
331
- end
332
- end
333
-
334
- end
335
-
336
59
 
337
60
  class ConfigureAc
338
61
  attr_accessor :makefile_am
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mkduino
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - David H. Wilkins
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-16 00:00:00.000000000 Z
11
+ date: 2014-01-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -52,6 +52,7 @@ files:
52
52
  - README.md
53
53
  - Rakefile
54
54
  - bin/mkduino
55
+ - lib/makefile_am.rb
55
56
  - lib/mkduino.rb
56
57
  - lib/mkduino/version.rb
57
58
  - mkduino.gemspec