arduino-mk 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. data/README.md +60 -0
  2. data/lib/arduino-mk.rb +10 -0
  3. data/lib/arduino-mk/base.rb +61 -0
  4. data/lib/arduino-mk/error_improver.rb +42 -0
  5. data/lib/arduino-mk/makefile/runner.rb +23 -0
  6. data/lib/arduino-mk/makefile/template.rb +27 -0
  7. data/lib/arduino-mk/null_project.rb +5 -0
  8. data/lib/arduino-mk/null_project/null.c +1 -0
  9. data/lib/arduino-mk/option_parser.rb +35 -0
  10. data/lib/arduino-mk/project_copier.rb +9 -0
  11. data/vendor/Arduino-Makefile/Arduino.mk +1306 -0
  12. data/vendor/Arduino-Makefile/CONTRIBUTING.md +35 -0
  13. data/vendor/Arduino-Makefile/Common.mk +46 -0
  14. data/vendor/Arduino-Makefile/HISTORY.md +225 -0
  15. data/vendor/Arduino-Makefile/README.md +189 -0
  16. data/vendor/Arduino-Makefile/ard-reset-arduino.1 +48 -0
  17. data/vendor/Arduino-Makefile/arduino-mk-vars.md +1101 -0
  18. data/vendor/Arduino-Makefile/bin/ard-reset-arduino +38 -0
  19. data/vendor/Arduino-Makefile/chipKIT.mk +109 -0
  20. data/vendor/Arduino-Makefile/examples/ATtinyBlink/ATtinyBlink.ino +23 -0
  21. data/vendor/Arduino-Makefile/examples/ATtinyBlink/Makefile +13 -0
  22. data/vendor/Arduino-Makefile/examples/AnalogInOutSerial/AnalogInOutSerial.ino +53 -0
  23. data/vendor/Arduino-Makefile/examples/AnalogInOutSerial/Makefile +4 -0
  24. data/vendor/Arduino-Makefile/examples/Blink/Blink.ino +19 -0
  25. data/vendor/Arduino-Makefile/examples/Blink/Makefile +5 -0
  26. data/vendor/Arduino-Makefile/examples/BlinkChipKIT/BlinkChipKIT.pde +19 -0
  27. data/vendor/Arduino-Makefile/examples/BlinkChipKIT/Makefile +5 -0
  28. data/vendor/Arduino-Makefile/examples/BlinkInAVRC/Makefile +16 -0
  29. data/vendor/Arduino-Makefile/examples/BlinkInAVRC/blink.c +38 -0
  30. data/vendor/Arduino-Makefile/examples/BlinkWithoutDelay/BlinkWithoutDelay.ino +65 -0
  31. data/vendor/Arduino-Makefile/examples/BlinkWithoutDelay/Makefile +4 -0
  32. data/vendor/Arduino-Makefile/examples/Fade/Fade.ino +31 -0
  33. data/vendor/Arduino-Makefile/examples/Fade/Makefile +4 -0
  34. data/vendor/Arduino-Makefile/examples/HelloWorld/HelloWorld.ino +58 -0
  35. data/vendor/Arduino-Makefile/examples/HelloWorld/Makefile +4 -0
  36. data/vendor/Arduino-Makefile/examples/MakefileExample/Makefile-example.mk +55 -0
  37. data/vendor/Arduino-Makefile/examples/README.md +7 -0
  38. data/vendor/Arduino-Makefile/examples/TinySoftWareSerial/Makefile +14 -0
  39. data/vendor/Arduino-Makefile/examples/TinySoftWareSerial/TinySoftwareSerial.ino +12 -0
  40. data/vendor/Arduino-Makefile/examples/WebServer/Makefile +6 -0
  41. data/vendor/Arduino-Makefile/examples/WebServer/WebServer.ino +82 -0
  42. data/vendor/Arduino-Makefile/examples/master_reader/Makefile +6 -0
  43. data/vendor/Arduino-Makefile/examples/master_reader/master_reader.ino +32 -0
  44. data/vendor/Arduino-Makefile/examples/toneMelody/Makefile +4 -0
  45. data/vendor/Arduino-Makefile/examples/toneMelody/pitches.h +95 -0
  46. data/vendor/Arduino-Makefile/examples/toneMelody/toneMelody.ino +49 -0
  47. data/vendor/Arduino-Makefile/licence.txt +502 -0
  48. data/vendor/Arduino-Makefile/packaging/debian/README.md +23 -0
  49. data/vendor/Arduino-Makefile/packaging/fedora/README.md +39 -0
  50. data/vendor/Arduino-Makefile/packaging/fedora/arduino-mk.spec +70 -0
  51. metadata +110 -0
@@ -0,0 +1,60 @@
1
+ ## arduino-mk
2
+
3
+ Compile and upload Arduino sketches with Ruby.
4
+
5
+ ## Usage
6
+
7
+ ```ruby
8
+ arduino = Arduino.new(board: "uno")
9
+
10
+ if arduino.upload("/path/to/project")
11
+ puts "Sketch uploaded successfully!"
12
+ else
13
+ puts arduino.error
14
+ end
15
+ ```
16
+
17
+ To test if your project compiles without uploading:
18
+
19
+ ```ruby
20
+ if arduino.compiles?("/path/to/project")
21
+ puts "Sketch compiles successfully!"
22
+ else
23
+ puts arduino.error
24
+ end
25
+ ```
26
+
27
+ To reset your Arduino:
28
+
29
+ ```ruby
30
+ if arduino.reset
31
+ puts "Arduino reset successfully!"
32
+ else
33
+ puts arduino.error
34
+ end
35
+ ```
36
+
37
+ ## Further configuration
38
+
39
+ To include additional Makefile configuration:
40
+
41
+ ```ruby
42
+ arduino = Arduino.new(board: "uno", arduino_dir: "/path/to/arduino/libs")
43
+ ```
44
+
45
+ The path of the default Makefile is available at:
46
+
47
+ ```ruby
48
+ Arduino.makefile
49
+ ```
50
+
51
+ You can use this as reference.
52
+
53
+ ## Contribution
54
+
55
+ If you'd like to contribute, please send me a pull request or open an issue.
56
+
57
+ It'd be great to test this gem on a wide range of Arduinos and platforms.
58
+
59
+ You should follow me on [twitter](http://twitter.com/cpatuzzo).
60
+
@@ -0,0 +1,10 @@
1
+ require "fileutils"
2
+ require "open3"
3
+
4
+ require "arduino-mk/base"
5
+ require "arduino-mk/option_parser"
6
+ require "arduino-mk/project_copier"
7
+ require "arduino-mk/makefile/template"
8
+ require "arduino-mk/makefile/runner"
9
+ require "arduino-mk/null_project"
10
+ require "arduino-mk/error_improver"
@@ -0,0 +1,61 @@
1
+ class Arduino
2
+
3
+ def initialize(options = {})
4
+ @options = OptionParser.parse(options)
5
+ end
6
+
7
+ def upload(project)
8
+ make(project, "upload")
9
+ @result.success?
10
+ end
11
+
12
+ def compiles?(project)
13
+ make(project)
14
+ @result.success?
15
+ end
16
+
17
+ def reset
18
+ make(NullProject.path, "reset")
19
+ @result.success?
20
+ end
21
+
22
+ def output
23
+ return unless @result
24
+ @result.stdout
25
+ end
26
+
27
+ def error
28
+ return unless @result
29
+
30
+ if @result.success?
31
+ @result.stderr
32
+ else
33
+ ErrorImprover.improve(@result.stderr)
34
+ end
35
+ end
36
+
37
+ def self.boards
38
+ instance = new(board: "null")
39
+ instance.boards
40
+ end
41
+
42
+ def boards
43
+ make(NullProject.path, "show_boards")
44
+ array = output.split("\n")
45
+ array[array.index("uno")..-2]
46
+ end
47
+
48
+ def self.makefile
49
+ Makefile::Template.path_to_arduino_mk
50
+ end
51
+
52
+ private
53
+ def make(project, command = "all")
54
+ copy_dir = ProjectCopier.copy(project)
55
+ Makefile::Template.create(copy_dir, @options)
56
+ @result = Makefile::Runner.run(copy_dir, command)
57
+ FileUtils.rm_rf(copy_dir)
58
+ end
59
+
60
+ end
61
+
@@ -0,0 +1,42 @@
1
+ module Arduino::ErrorImprover
2
+ def improve(message)
3
+ case message
4
+ when /Arduino port (.*) not found!/
5
+ message + boilerplate(ports($1))
6
+ else
7
+ message + boilerplate(boards)
8
+ end
9
+ end
10
+
11
+ private
12
+ def ports(attempt)
13
+ hint = "The port is usually /dev/ttySomething"
14
+ if attempt.empty?
15
+ [
16
+ "Could not find an arduino by autodetection",
17
+ "Try setting the port explicitly in your initializer",
18
+ hint,
19
+ ]
20
+ else
21
+ [
22
+ "Could not find an arduino on port #{attempt}",
23
+ "Try removing the port from the initializer to enable autodetection",
24
+ hint,
25
+ ]
26
+ end
27
+ end
28
+
29
+ def boards
30
+ [
31
+ "Sometimes you'll get random errors if the wrong board is set",
32
+ "Please make sure you've set the board correctly",
33
+ "For a list of supported boards, run Arduino.boards",
34
+ ]
35
+ end
36
+
37
+ def boilerplate(messages)
38
+ ["\n\n=== Error ===", *messages].join("\n")
39
+ end
40
+
41
+ extend self
42
+ end
@@ -0,0 +1,23 @@
1
+ module Arduino::Makefile
2
+ module Runner
3
+
4
+ def self.run(makefile, task)
5
+ command = "make -C #{makefile} #{task}"
6
+ Result.new(*Open3.capture3(command))
7
+ end
8
+
9
+ class Result
10
+ attr_reader :stdout, :stderr
11
+
12
+ def initialize(stdout, stderr, status)
13
+ @stdout = stdout
14
+ @stderr = stderr
15
+ @success = status.success?
16
+ end
17
+
18
+ def success?
19
+ @success
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,27 @@
1
+ module Arduino::Makefile
2
+ module Template
3
+
4
+ def create(directory, options)
5
+ filename = File.join(directory, "Makefile")
6
+
7
+ File.open(filename, "w") do |file|
8
+ file.puts environment_variables(options)
9
+ file.puts "include #{path_to_arduino_mk}"
10
+ end
11
+ end
12
+
13
+ def environment_variables(options)
14
+ options.map { |k, v| "#{k}=#{v}" }.join("\n")
15
+ end
16
+
17
+ def path_to_arduino_mk
18
+ gem_root = File.join(__FILE__, "..", "..", "..", "..")
19
+ arduino_mk = File.join(gem_root, "vendor", "Arduino-Makefile")
20
+ relative_path = File.join(arduino_mk, "Arduino.mk")
21
+
22
+ File.expand_path(relative_path)
23
+ end
24
+
25
+ extend self
26
+ end
27
+ end
@@ -0,0 +1,5 @@
1
+ module Arduino::NullProject
2
+ def self.path
3
+ File.join(File.dirname(__FILE__), "null_project")
4
+ end
5
+ end
@@ -0,0 +1 @@
1
+ // Reset fails unless this exists.
@@ -0,0 +1,35 @@
1
+ module Arduino::OptionParser
2
+ def parse(options)
3
+ options = options.dup
4
+
5
+ raise_if_no_board(options)
6
+
7
+ rename_key(options, :board, :BOARD_TAG)
8
+ rename_key(options, :port, :ARDUINO_PORT)
9
+
10
+ upcase_keys(options)
11
+
12
+ options
13
+ end
14
+
15
+ def raise_if_no_board(options)
16
+ unless options[:board]
17
+ message = "Please specifiy your board in the initializer."
18
+ message += "\n\nArduino.boards will give you a list of valid boards."
19
+
20
+ raise ArgumentError, message
21
+ end
22
+ end
23
+
24
+ def upcase_keys(options)
25
+ options.keys.each do |k|
26
+ rename_key(options, k, k.upcase)
27
+ end
28
+ end
29
+
30
+ def rename_key(options, from, to)
31
+ options[to] = options.delete(from) if options[from]
32
+ end
33
+
34
+ extend self
35
+ end
@@ -0,0 +1,9 @@
1
+ module Arduino::ProjectCopier
2
+ def self.copy(project_directory)
3
+ basename = File.basename(project_directory)
4
+ copy_directory = "#{basename}_copy"
5
+
6
+ FileUtils.cp_r(project_directory, copy_directory)
7
+ File.expand_path(copy_directory)
8
+ end
9
+ end
@@ -0,0 +1,1306 @@
1
+ ########################################################################
2
+ #
3
+ # Makefile for compiling Arduino sketches from command line
4
+ # System part (i.e. project independent)
5
+ #
6
+ # Copyright (C) 2012 Sudar <http://sudarmuthu.com>, based on
7
+ # M J Oldfield work: https://github.com/mjoldfield/Arduino-Makefile
8
+ #
9
+ # Copyright (C) 2010,2011,2012 Martin Oldfield <m@mjo.tc>, based on
10
+ # work that is copyright Nicholas Zambetti, David A. Mellis & Hernando
11
+ # Barragan.
12
+ #
13
+ # This file is free software; you can redistribute it and/or modify it
14
+ # under the terms of the GNU Lesser General Public License as
15
+ # published by the Free Software Foundation; either version 2.1 of the
16
+ # License, or (at your option) any later version.
17
+ #
18
+ # Adapted from Arduino 0011 Makefile by M J Oldfield
19
+ #
20
+ # Original Arduino adaptation by mellis, eighthave, oli.keller
21
+ #
22
+ # Current version: 1.3.3
23
+ #
24
+ # Refer to HISTORY.md file for complete history of changes
25
+ #
26
+ ########################################################################
27
+ #
28
+ # PATHS YOU NEED TO SET UP
29
+ #
30
+ # We need to worry about three different sorts of file:
31
+ #
32
+ # 1. The directory where the *.mk files are stored
33
+ # => ARDMK_DIR
34
+ #
35
+ # 2. Things which are always in the Arduino distribution e.g.
36
+ # boards.txt, libraries, &c.
37
+ # => ARDUINO_DIR
38
+ #
39
+ # 3. Things which might be bundled with the Arduino distribution, but
40
+ # might come from the system. Most of the toolchain is like this:
41
+ # on Linux it's supplied by the system.
42
+ # => AVR_TOOLS_DIR
43
+ #
44
+ # Having set these three variables, we can work out the rest assuming
45
+ # that things are canonically arranged beneath the directories defined
46
+ # above.
47
+ #
48
+ # On the Mac you might want to set:
49
+ #
50
+ # ARDUINO_DIR = /Applications/Arduino.app/Contents/Resources/Java
51
+ # ARDMK_DIR = /usr/local
52
+ #
53
+ # On Linux, you might prefer:
54
+ #
55
+ # ARDUINO_DIR = /usr/share/arduino
56
+ # ARDMK_DIR = /usr/share/arduino
57
+ # AVR_TOOLS_DIR = /usr
58
+ #
59
+ # On Windows declare this environmental variables using the windows
60
+ # configuration options. Control Panel > System > Advanced system settings
61
+ # Also take into account that when you set them you have to add '\' on
62
+ # all spaces and special characters.
63
+ # ARDUINO_DIR and AVR_TOOLS_DIR have to be relative and not absolute.
64
+ # This are just examples, you have to adapt this variables accordingly to
65
+ # your system.
66
+ #
67
+ # ARDUINO_DIR =../../../../../Arduino
68
+ # AVR_TOOLS_DIR =../../../../../Arduino/hardware/tools/avr
69
+ # ARDMK_DIR = /cygdrive/c/Users/"YourUser"/Arduino-Makefile
70
+ #
71
+ # On Windows it is highly recommended that you create a symbolic link directory
72
+ # for avoiding using the normal directories name of windows such as
73
+ # c:\Program Files (x86)\Arduino
74
+ # For this use the command mklink on the console.
75
+ #
76
+ #
77
+ # You can either set these up in the Makefile, or put them in your
78
+ # environment e.g. in your .bashrc
79
+ #
80
+ # If you don't specify these, we can try to guess, but that might not work
81
+ # or work the way you want it to.
82
+ #
83
+ # If you'd rather not see the configuration output, define ARDUINO_QUIET.
84
+ #
85
+ ########################################################################
86
+ #
87
+ # DEPENDENCIES
88
+ #
89
+ # The Perl programs need a couple of libraries:
90
+ # Device::SerialPort
91
+ #
92
+ ########################################################################
93
+ #
94
+ # STANDARD ARDUINO WORKFLOW
95
+ #
96
+ # Given a normal sketch directory, all you need to do is to create
97
+ # a small Makefile which defines a few things, and then includes this one.
98
+ #
99
+ # For example:
100
+ #
101
+ # ARDUINO_LIBS = Ethernet SPI
102
+ # BOARD_TAG = uno
103
+ # MONITOR_PORT = /dev/cu.usb*
104
+ #
105
+ # include /usr/share/arduino/Arduino.mk
106
+ #
107
+ # Hopefully these will be self-explanatory but in case they're not:
108
+ #
109
+ # ARDUINO_LIBS - A list of any libraries used by the sketch (we
110
+ # assume these are in $(ARDUINO_DIR)/hardware/libraries
111
+ # or your sketchbook's libraries directory)
112
+ #
113
+ # MONITOR_PORT - The port where the Arduino can be found (only needed
114
+ # when uploading)
115
+ #
116
+ # BOARD_TAG - The tag for the board e.g. uno or mega
117
+ # 'make show_boards' shows a list
118
+ #
119
+ # If you have your additional libraries relative to your source, rather
120
+ # than in your "sketchbook", also set USER_LIB_PATH, like this example:
121
+ #
122
+ # USER_LIB_PATH := $(realpath ../../libraries)
123
+ #
124
+ # If you've added the Arduino-Makefile repository to your git repo as a
125
+ # submodule (or other similar arrangement), you might have lines like this
126
+ # in your Makefile:
127
+ #
128
+ # ARDMK_DIR := $(realpath ../../tools/Arduino-Makefile)
129
+ # include $(ARDMK_DIR)/Arduino.mk
130
+ #
131
+ # In any case, once this file has been created the typical workflow is just
132
+ #
133
+ # $ make upload
134
+ #
135
+ # All of the object files are created in the build-{BOARD_TAG} subdirectory
136
+ # All sources should be in the current directory and can include:
137
+ # - at most one .pde or .ino file which will be treated as C++ after
138
+ # the standard Arduino header and footer have been affixed.
139
+ # - any number of .c, .cpp, .s and .h files
140
+ #
141
+ # Included libraries are built in the build-{BOARD_TAG}/libs subdirectory.
142
+ #
143
+ # Besides make upload, there are a couple of other targets that are available.
144
+ # Do make help to get the complete list of targets and their description
145
+ #
146
+ ########################################################################
147
+ #
148
+ # SERIAL MONITOR
149
+ #
150
+ # The serial monitor just invokes the GNU screen program with suitable
151
+ # options. For more information see screen (1) and search for
152
+ # 'character special device'.
153
+ #
154
+ # The really useful thing to know is that ^A-k gets you out!
155
+ #
156
+ # The fairly useful thing to know is that you can bind another key to
157
+ # escape too, by creating $HOME{.screenrc} containing e.g.
158
+ #
159
+ # bindkey ^C kill
160
+ #
161
+ # If you want to change the baudrate, just set MONITOR_BAUDRATE. If you
162
+ # don't set it, it tries to read from the sketch. If it couldn't read
163
+ # from the sketch, then it defaults to 9600 baud.
164
+ #
165
+ ########################################################################
166
+ #
167
+ # ARDUINO WITH ISP
168
+ #
169
+ # You need to specify some details of your ISP programmer and might
170
+ # also need to specify the fuse values:
171
+ #
172
+ # ISP_PROG = stk500v2
173
+ # ISP_PORT = /dev/ttyACM0
174
+ #
175
+ # You might also need to set the fuse bits, but typically they'll be
176
+ # read from boards.txt, based on the BOARD_TAG variable:
177
+ #
178
+ # ISP_LOCK_FUSE_PRE = 0x3f
179
+ # ISP_LOCK_FUSE_POST = 0xcf
180
+ # ISP_HIGH_FUSE = 0xdf
181
+ # ISP_LOW_FUSE = 0xff
182
+ # ISP_EXT_FUSE = 0x01
183
+ #
184
+ # You can specify to also upload the EEPROM file:
185
+ # ISP_EEPROM = 1
186
+ #
187
+ # I think the fuses here are fine for uploading to the ATmega168
188
+ # without bootloader.
189
+ #
190
+ # To actually do this upload use the ispload target:
191
+ #
192
+ # make ispload
193
+ #
194
+ #
195
+ ########################################################################
196
+ #
197
+ # ALTERNATIVE CORES
198
+ #
199
+ # To use alternative cores for platforms such as ATtiny, you need to
200
+ # specify a few more variables, depending on the core in use.
201
+ #
202
+ # The HLT (attiny-master) core can be used just by specifying
203
+ # ALTERNATE_CORE, assuming your core is in your ~/sketchbook/hardware
204
+ # directory. For example:
205
+ #
206
+ # ISP_PORT = /dev/ttyACM0
207
+ # BOARD_TAG = attiny85
208
+ # ALTERNATE_CORE = attiny-master
209
+ #
210
+ # To use the more complex arduino-tiny and TinyCore2 cores, you must
211
+ # also set ARDUINO_CORE_PATH and ARDUINO_VAR_PATH to the core
212
+ # directory, as these cores essentially replace the main Arduino core.
213
+ # For example:
214
+ #
215
+ # ISP_PORT = /dev/ttyACM0
216
+ # BOARD_TAG = attiny85at8
217
+ # ALTERNATE_CORE = arduino-tiny
218
+ # ARDUINO_VAR_PATH = ~/sketchbook/hardware/arduino-tiny/cores/tiny
219
+ # ARDUINO_CORE_PATH = ~/sketchbook/hardware/arduino-tiny/cores/tiny
220
+ #
221
+ # or....
222
+ #
223
+ # ISP_PORT = /dev/ttyACM0
224
+ # BOARD_TAG = attiny861at8
225
+ # ALTERNATE_CORE = tiny2
226
+ # ARDUINO_VAR_PATH = ~/sketchbook/hardware/tiny2/cores/tiny
227
+ # ARDUINO_CORE_PATH = ~/sketchbook/hardware/tiny2/cores/tiny
228
+ #
229
+ ########################################################################
230
+
231
+ arduino_output =
232
+ # When output is not suppressed and we're in the top-level makefile,
233
+ # running for the first time (i.e., not after a restart after
234
+ # regenerating the dependency file), then output the configuration.
235
+ ifndef ARDUINO_QUIET
236
+ ifeq ($(MAKE_RESTARTS),)
237
+ ifeq ($(MAKELEVEL),0)
238
+ arduino_output = $(info $(1))
239
+ endif
240
+ endif
241
+ endif
242
+
243
+ ########################################################################
244
+ # Makefile distribution path
245
+
246
+ ifndef ARDMK_DIR
247
+ # presume it's the same path to our own file
248
+ ARDMK_DIR := $(realpath $(dir $(realpath $(lastword $(MAKEFILE_LIST)))))
249
+ else
250
+ # show_config_variable macro is defined in Common.mk file and is not available yet.
251
+ # Let's define a variable to know that user specified ARDMK_DIR
252
+ ARDMK_DIR_MSG = USER
253
+ endif
254
+
255
+ # include Common.mk now we know where it is
256
+ include $(ARDMK_DIR)/Common.mk
257
+
258
+ # show_config_variable macro is available now. So let's print config details for ARDMK_DIR
259
+ ifndef ARDMK_DIR_MSG
260
+ $(call show_config_variable,ARDMK_DIR,[COMPUTED],(relative to $(notdir $(lastword $(MAKEFILE_LIST)))))
261
+ else
262
+ $(call show_config_variable,ARDMK_DIR,[USER])
263
+ endif
264
+
265
+ ########################################################################
266
+ # Arduino Directory
267
+
268
+ ifndef ARDUINO_DIR
269
+ AUTO_ARDUINO_DIR := $(firstword \
270
+ $(call dir_if_exists,/usr/share/arduino) \
271
+ $(call dir_if_exists,/Applications/Arduino.app/Contents/Resources/Java) )
272
+ ifdef AUTO_ARDUINO_DIR
273
+ ARDUINO_DIR = $(AUTO_ARDUINO_DIR)
274
+ $(call show_config_variable,ARDUINO_DIR,[AUTODETECTED])
275
+ else
276
+ echo $(error "ARDUINO_DIR is not defined")
277
+ endif
278
+ else
279
+ $(call show_config_variable,ARDUINO_DIR,[USER])
280
+ endif
281
+
282
+ ########################################################################
283
+ # Default TARGET to pwd (ex Daniele Vergini)
284
+
285
+ ifndef TARGET
286
+ TARGET = $(notdir $(CURDIR))
287
+ endif
288
+
289
+ ########################################################################
290
+ # Arduino version number
291
+
292
+ ifndef ARDUINO_VERSION
293
+ # Remove all the decimals, and right-pad with zeros, and finally grab the first 3 bytes.
294
+ # Works for 1.0 and 1.0.1
295
+ VERSION_FILE := $(ARDUINO_DIR)/lib/version.txt
296
+ AUTO_ARDUINO_VERSION := $(shell [ -e $(VERSION_FILE) ] && cat $(VERSION_FILE) | sed -e 's/^[0-9]://g' -e 's/[.]//g' -e 's/$$/0000/' | head -c3)
297
+ ifdef AUTO_ARDUINO_VERSION
298
+ ARDUINO_VERSION = $(AUTO_ARDUINO_VERSION)
299
+ $(call show_config_variable,ARDUINO_VERSION,[AUTODETECTED])
300
+ else
301
+ ARDUINO_VERSION = 100
302
+ $(call show_config_variable,ARDUINO_VERSION,[DEFAULT])
303
+ endif
304
+ else
305
+ $(call show_config_variable,ARDUINO_VERSION,[USER])
306
+ endif
307
+
308
+ ########################################################################
309
+ # Arduino Sketchbook folder
310
+
311
+ ifndef ARDUINO_SKETCHBOOK
312
+ ifndef ARDUINO_PREFERENCES_PATH
313
+
314
+ AUTO_ARDUINO_PREFERENCES := $(firstword \
315
+ $(call dir_if_exists,$(HOME)/.arduino/preferences.txt) \
316
+ $(call dir_if_exists,$(HOME)/Library/Arduino/preferences.txt) )
317
+ ifdef AUTO_ARDUINO_PREFERENCES
318
+ ARDUINO_PREFERENCES_PATH = $(AUTO_ARDUINO_PREFERENCES)
319
+ $(call show_config_variable,ARDUINO_PREFERENCES_PATH,[AUTODETECTED])
320
+ endif
321
+
322
+ else
323
+ $(call show_config_variable,ARDUINO_PREFERENCES_PATH,[USER])
324
+ endif
325
+
326
+ ifneq ($(ARDUINO_PREFERENCES_PATH),)
327
+ ARDUINO_SKETCHBOOK = $(shell grep --max-count=1 --regexp="sketchbook.path=" \
328
+ $(ARDUINO_PREFERENCES_PATH) | \
329
+ sed -e 's/sketchbook.path=//' )
330
+ endif
331
+
332
+ ifneq ($(ARDUINO_SKETCHBOOK),)
333
+ $(call show_config_variable,ARDUINO_SKETCHBOOK,[AUTODETECTED],(from arduino preferences file))
334
+ else
335
+ ARDUINO_SKETCHBOOK = $(HOME)/sketchbook
336
+ $(call show_config_variable,ARDUINO_SKETCHBOOK,[DEFAULT])
337
+ endif
338
+ else
339
+ $(call show_config_variable,ARDUINO_SKETCHBOOK,[USER])
340
+ endif
341
+
342
+ ########################################################################
343
+ # Arduino and system paths
344
+
345
+ ifndef CC_NAME
346
+ CC_NAME = avr-gcc
347
+ endif
348
+
349
+ ifndef CXX_NAME
350
+ CXX_NAME = avr-g++
351
+ endif
352
+
353
+ ifndef OBJCOPY_NAME
354
+ OBJCOPY_NAME = avr-objcopy
355
+ endif
356
+
357
+ ifndef OBJDUMP_NAME
358
+ OBJDUMP_NAME = avr-objdump
359
+ endif
360
+
361
+ ifndef AR_NAME
362
+ AR_NAME = avr-ar
363
+ endif
364
+
365
+ ifndef SIZE_NAME
366
+ SIZE_NAME = avr-size
367
+ endif
368
+
369
+ ifndef NM_NAME
370
+ NM_NAME = avr-nm
371
+ endif
372
+
373
+ ifndef AVR_TOOLS_DIR
374
+
375
+ BUNDLED_AVR_TOOLS_DIR := $(call dir_if_exists,$(ARDUINO_DIR)/hardware/tools/avr)
376
+
377
+ ifdef BUNDLED_AVR_TOOLS_DIR
378
+ AVR_TOOLS_DIR = $(BUNDLED_AVR_TOOLS_DIR)
379
+ $(call show_config_variable,AVR_TOOLS_DIR,[BUNDLED],(in Arduino distribution))
380
+
381
+ # In Linux distribution of Arduino, the path to avrdude and avrdude.conf are different
382
+ # More details at https://github.com/sudar/Arduino-Makefile/issues/48 and
383
+ # https://groups.google.com/a/arduino.cc/d/msg/developers/D_m97jGr8Xs/uQTt28KO_8oJ
384
+ ifeq ($(CURRENT_OS),LINUX)
385
+
386
+ ifndef AVRDUDE
387
+ AVRDUDE = $(AVR_TOOLS_DIR)/../avrdude
388
+ endif
389
+
390
+ ifndef AVRDUDE_CONF
391
+ AVRDUDE_CONF = $(AVR_TOOLS_DIR)/../avrdude.conf
392
+ endif
393
+
394
+ else
395
+
396
+ ifndef AVRDUDE_CONF
397
+ AVRDUDE_CONF = $(AVR_TOOLS_DIR)/etc/avrdude.conf
398
+ endif
399
+
400
+ endif
401
+
402
+ else
403
+
404
+ SYSTEMPATH_AVR_TOOLS_DIR := $(call dir_if_exists,$(abspath $(dir $(shell which $(CC_NAME)))/..))
405
+ ifdef SYSTEMPATH_AVR_TOOLS_DIR
406
+ AVR_TOOLS_DIR = $(SYSTEMPATH_AVR_TOOLS_DIR)
407
+ $(call show_config_variable,AVR_TOOLS_DIR,[AUTODETECTED],(found in $$PATH))
408
+ else
409
+ echo $(error No AVR tools directory found)
410
+ endif # SYSTEMPATH_AVR_TOOLS_DIR
411
+
412
+ endif # BUNDLED_AVR_TOOLS_DIR
413
+
414
+ else
415
+ $(call show_config_variable,AVR_TOOLS_DIR,[USER])
416
+
417
+ # Check in Windows as Cygwin is being used, that the configuration file for the AVRDUDE is set
418
+ # Check if it works on MAC
419
+ ifeq ($(CURRENT_OS),WINDOWS)
420
+ ifndef AVRDUDE_CONF
421
+ AVRDUDE_CONF = $(AVR_TOOLS_DIR)/etc/avrdude.conf
422
+ endif
423
+ endif
424
+
425
+ endif #ndef AVR_TOOLS_DIR
426
+
427
+ ifndef AVR_TOOLS_PATH
428
+ AVR_TOOLS_PATH = $(AVR_TOOLS_DIR)/bin
429
+ endif
430
+
431
+ ARDUINO_LIB_PATH = $(ARDUINO_DIR)/libraries
432
+ $(call show_config_variable,ARDUINO_LIB_PATH,[COMPUTED],(from ARDUINO_DIR))
433
+ ifndef ARDUINO_CORE_PATH
434
+ ARDUINO_CORE_PATH = $(ARDUINO_DIR)/hardware/arduino/cores/arduino
435
+ $(call show_config_variable,ARDUINO_CORE_PATH,[DEFAULT])
436
+ else
437
+ $(call show_config_variable,ARDUINO_CORE_PATH,[USER])
438
+ endif
439
+
440
+ # Third party hardware and core like ATtiny or ATmega 16
441
+ ifdef ALTERNATE_CORE
442
+ $(call show_config_variable,ALTERNATE_CORE,[USER])
443
+
444
+ ifndef ALTERNATE_CORE_PATH
445
+ ALTERNATE_CORE_PATH = $(ARDUINO_SKETCHBOOK)/hardware/$(ALTERNATE_CORE)
446
+ endif
447
+ endif
448
+
449
+ ifdef ALTERNATE_CORE_PATH
450
+
451
+ ifdef ALTERNATE_CORE
452
+ $(call show_config_variable,ALTERNATE_CORE_PATH,[COMPUTED], (from ARDUINO_SKETCHBOOK and ALTERNATE_CORE))
453
+ else
454
+ $(call show_config_variable,ALTERNATE_CORE_PATH,[USER])
455
+ endif
456
+
457
+ ifndef ARDUINO_VAR_PATH
458
+ ARDUINO_VAR_PATH = $(ALTERNATE_CORE_PATH)/variants
459
+ $(call show_config_variable,ARDUINO_VAR_PATH,[COMPUTED],(from ALTERNATE_CORE_PATH))
460
+ endif
461
+
462
+ ifndef BOARDS_TXT
463
+ BOARDS_TXT = $(ALTERNATE_CORE_PATH)/boards.txt
464
+ $(call show_config_variable,BOARDS_TXT,[COMPUTED],(from ALTERNATE_CORE_PATH))
465
+ endif
466
+
467
+ else
468
+
469
+ ifndef ARDUINO_VAR_PATH
470
+ ARDUINO_VAR_PATH = $(ARDUINO_DIR)/hardware/arduino/variants
471
+ $(call show_config_variable,ARDUINO_VAR_PATH,[COMPUTED],(from ARDUINO_DIR))
472
+ else
473
+ $(call show_config_variable,ARDUINO_VAR_PATH,[USER])
474
+ endif
475
+
476
+ ifndef BOARDS_TXT
477
+ BOARDS_TXT = $(ARDUINO_DIR)/hardware/arduino/boards.txt
478
+ $(call show_config_variable,BOARDS_TXT,[COMPUTED],(from ARDUINO_DIR))
479
+ else
480
+ $(call show_config_variable,BOARDS_TXT,[USER])
481
+ endif
482
+
483
+ endif
484
+
485
+ ########################################################################
486
+ # Miscellaneous
487
+
488
+ ifndef USER_LIB_PATH
489
+ USER_LIB_PATH = $(ARDUINO_SKETCHBOOK)/libraries
490
+ $(call show_config_variable,USER_LIB_PATH,[DEFAULT],(in user sketchbook))
491
+ else
492
+ $(call show_config_variable,USER_LIB_PATH,[USER])
493
+ endif
494
+
495
+ ifndef PRE_BUILD_HOOK
496
+ PRE_BUILD_HOOK = pre-build-hook.sh
497
+ $(call show_config_variable,PRE_BUILD_HOOK,[DEFAULT])
498
+ else
499
+ $(call show_config_variable,PRE_BUILD_HOOK,[USER])
500
+ endif
501
+
502
+ ########################################################################
503
+ # boards.txt parsing
504
+
505
+ ifndef BOARD_TAG
506
+ BOARD_TAG = uno
507
+ $(call show_config_variable,BOARD_TAG,[DEFAULT])
508
+ else
509
+ # Strip the board tag of any extra whitespace, since it was causing the makefile to fail
510
+ # https://github.com/sudar/Arduino-Makefile/issues/57
511
+ BOARD_TAG := $(strip $(BOARD_TAG))
512
+ $(call show_config_variable,BOARD_TAG,[USER])
513
+ endif
514
+
515
+ ifndef PARSE_BOARD
516
+ # result = $(call READ_BOARD_TXT, 'boardname', 'parameter')
517
+ PARSE_BOARD = $(shell grep -v "^\#" $(BOARDS_TXT) | grep $(1).$(2) | cut -d = -f 2 )
518
+ endif
519
+
520
+ # If NO_CORE is set, then we don't have to parse boards.txt file
521
+ # But the user might have to define MCU, F_CPU etc
522
+ ifeq ($(strip $(NO_CORE)),)
523
+
524
+ # Which variant ? This affects the include path
525
+ ifndef VARIANT
526
+ VARIANT = $(call PARSE_BOARD,$(BOARD_TAG),build.variant)
527
+ endif
528
+
529
+ # see if we are a caterina device like leonardo or micro
530
+ CATERINA = $(findstring caterina,$(call PARSE_BOARD,$(BOARD_TAG),bootloader.path))
531
+
532
+ # processor stuff
533
+ ifndef MCU
534
+ MCU = $(call PARSE_BOARD,$(BOARD_TAG),build.mcu)
535
+ endif
536
+
537
+ ifndef F_CPU
538
+ F_CPU = $(call PARSE_BOARD,$(BOARD_TAG),build.f_cpu)
539
+ endif
540
+
541
+ ifneq ($(CATERINA),)
542
+ # USB IDs for the caterina devices like leonardo or micro
543
+ ifndef USB_VID
544
+ USB_VID = $(call PARSE_BOARD,$(BOARD_TAG),build.vid)
545
+ endif
546
+
547
+ ifndef USB_PID
548
+ USB_PID = $(call PARSE_BOARD,$(BOARD_TAG),build.pid)
549
+ endif
550
+ endif
551
+
552
+ # normal programming info
553
+ ifndef AVRDUDE_ARD_PROGRAMMER
554
+ AVRDUDE_ARD_PROGRAMMER = $(call PARSE_BOARD,$(BOARD_TAG),upload.protocol)
555
+ endif
556
+
557
+ ifndef AVRDUDE_ARD_BAUDRATE
558
+ AVRDUDE_ARD_BAUDRATE = $(call PARSE_BOARD,$(BOARD_TAG),upload.speed)
559
+ endif
560
+
561
+ # fuses if you're using e.g. ISP
562
+ ifndef ISP_LOCK_FUSE_PRE
563
+ ISP_LOCK_FUSE_PRE = $(call PARSE_BOARD,$(BOARD_TAG),bootloader.unlock_bits)
564
+ endif
565
+
566
+ ifndef ISP_HIGH_FUSE
567
+ ISP_HIGH_FUSE = $(call PARSE_BOARD,$(BOARD_TAG),bootloader.high_fuses)
568
+ endif
569
+
570
+ ifndef ISP_LOW_FUSE
571
+ ISP_LOW_FUSE = $(call PARSE_BOARD,$(BOARD_TAG),bootloader.low_fuses)
572
+ endif
573
+
574
+ ifndef ISP_EXT_FUSE
575
+ ISP_EXT_FUSE = $(call PARSE_BOARD,$(BOARD_TAG),bootloader.extended_fuses)
576
+ endif
577
+
578
+ ifndef BOOTLOADER_PATH
579
+ BOOTLOADER_PATH = $(call PARSE_BOARD,$(BOARD_TAG),bootloader.path)
580
+ endif
581
+
582
+ ifndef BOOTLOADER_FILE
583
+ BOOTLOADER_FILE = $(call PARSE_BOARD,$(BOARD_TAG),bootloader.file)
584
+ endif
585
+
586
+ ifndef ISP_LOCK_FUSE_POST
587
+ ISP_LOCK_FUSE_POST = $(call PARSE_BOARD,$(BOARD_TAG),bootloader.lock_bits)
588
+ endif
589
+
590
+ ifndef HEX_MAXIMUM_SIZE
591
+ HEX_MAXIMUM_SIZE = $(call PARSE_BOARD,$(BOARD_TAG),upload.maximum_size)
592
+ endif
593
+
594
+ endif
595
+
596
+ # Everything gets built in here (include BOARD_TAG now)
597
+ ifndef OBJDIR
598
+ OBJDIR = build-$(BOARD_TAG)
599
+ $(call show_config_variable,OBJDIR,[COMPUTED],(from BOARD_TAG))
600
+ else
601
+ $(call show_config_variable,OBJDIR,[USER])
602
+ endif
603
+
604
+ ########################################################################
605
+ # Reset
606
+
607
+ ifndef RESET_CMD
608
+ ARD_RESET_ARDUINO := $(shell which ard-reset-arduino 2> /dev/null)
609
+ ifndef ARD_RESET_ARDUINO
610
+ # same level as *.mk in bin directory when checked out from git
611
+ # or in $PATH when packaged
612
+ ARD_RESET_ARDUINO = $(ARDMK_DIR)/bin/ard-reset-arduino
613
+ endif
614
+ ifneq ($(CATERINA),)
615
+ RESET_CMD = $(ARD_RESET_ARDUINO) --caterina $(ARD_RESET_OPTS) $(call get_monitor_port)
616
+ else
617
+ RESET_CMD = $(ARD_RESET_ARDUINO) $(ARD_RESET_OPTS) $(call get_monitor_port)
618
+ endif
619
+ endif
620
+
621
+ ifneq ($(CATERINA),)
622
+ ERROR_ON_CATERINA = $(error On $(BOARD_TAG), raw_xxx operation is not supported)
623
+ else
624
+ ERROR_ON_CATERINA =
625
+ endif
626
+
627
+ ########################################################################
628
+ # Local sources
629
+
630
+ LOCAL_C_SRCS ?= $(wildcard *.c)
631
+ LOCAL_CPP_SRCS ?= $(wildcard *.cpp)
632
+ LOCAL_CC_SRCS ?= $(wildcard *.cc)
633
+ LOCAL_PDE_SRCS ?= $(wildcard *.pde)
634
+ LOCAL_INO_SRCS ?= $(wildcard *.ino)
635
+ LOCAL_AS_SRCS ?= $(wildcard *.S)
636
+ LOCAL_SRCS = $(LOCAL_C_SRCS) $(LOCAL_CPP_SRCS) \
637
+ $(LOCAL_CC_SRCS) $(LOCAL_PDE_SRCS) \
638
+ $(LOCAL_INO_SRCS) $(LOCAL_AS_SRCS)
639
+ LOCAL_OBJ_FILES = $(LOCAL_C_SRCS:.c=.o) $(LOCAL_CPP_SRCS:.cpp=.o) \
640
+ $(LOCAL_CC_SRCS:.cc=.o) $(LOCAL_PDE_SRCS:.pde=.o) \
641
+ $(LOCAL_INO_SRCS:.ino=.o) $(LOCAL_AS_SRCS:.S=.o)
642
+ LOCAL_OBJS = $(patsubst %,$(OBJDIR)/%,$(LOCAL_OBJ_FILES))
643
+
644
+ ifeq ($(words $(LOCAL_SRCS)), 0)
645
+ $(error Atleast one source file (*.ino, *.pde, *.cpp, *c, *cc, *.S) is needed)
646
+ endif
647
+
648
+ ifeq ($(strip $(NO_CORE)),)
649
+
650
+ # Ideally, this should just check if there are more than one file
651
+ ifneq ($(words $(LOCAL_PDE_SRCS) $(LOCAL_INO_SRCS)), 1)
652
+ ifeq ($(words $(LOCAL_PDE_SRCS) $(LOCAL_INO_SRCS)), 0)
653
+ $(call show_config_info,No .pde or .ino files found. If you are compiling .c or .cpp files then you need to explicitly include Arduino header files)
654
+ else
655
+ #TODO: Support more than one file. https://github.com/sudar/Arduino-Makefile/issues/49
656
+ $(error Need exactly one .pde or .ino file. This makefile doesn't support multiple .ino/.pde files yet)
657
+ endif
658
+ endif
659
+
660
+ endif
661
+
662
+ # core sources
663
+ ifeq ($(strip $(NO_CORE)),)
664
+ ifdef ARDUINO_CORE_PATH
665
+ CORE_C_SRCS = $(wildcard $(ARDUINO_CORE_PATH)/*.c)
666
+ CORE_C_SRCS += $(wildcard $(ARDUINO_CORE_PATH)/avr-libc/*.c)
667
+ CORE_CPP_SRCS = $(wildcard $(ARDUINO_CORE_PATH)/*.cpp)
668
+
669
+ ifneq ($(strip $(NO_CORE_MAIN_CPP)),)
670
+ CORE_CPP_SRCS := $(filter-out %main.cpp, $(CORE_CPP_SRCS))
671
+ $(call show_config_info,NO_CORE_MAIN_CPP set so core library will not include main.cpp,[MANUAL])
672
+ endif
673
+
674
+ CORE_OBJ_FILES = $(CORE_C_SRCS:.c=.o) $(CORE_CPP_SRCS:.cpp=.o) $(CORE_AS_SRCS:.S=.o)
675
+ CORE_OBJS = $(patsubst $(ARDUINO_CORE_PATH)/%, \
676
+ $(OBJDIR)/%,$(CORE_OBJ_FILES))
677
+ endif
678
+ else
679
+ $(call show_config_info,NO_CORE set so core library will not be built,[MANUAL])
680
+ endif
681
+
682
+ ########################################################################
683
+ # Determine ARDUINO_LIBS automatically
684
+
685
+ ifndef ARDUINO_LIBS
686
+ # automatically determine included libraries
687
+ ARDUINO_LIBS += $(filter $(notdir $(wildcard $(ARDUINO_DIR)/libraries/*)), \
688
+ $(shell sed -ne "s/^ *\# *include *[<\"]\(.*\)\.h[>\"]/\1/p" $(LOCAL_SRCS)))
689
+ ARDUINO_LIBS += $(filter $(notdir $(wildcard $(ARDUINO_SKETCHBOOK)/libraries/*)), \
690
+ $(shell sed -ne "s/^ *\# *include *[<\"]\(.*\)\.h[>\"]/\1/p" $(LOCAL_SRCS)))
691
+ ARDUINO_LIBS += $(filter $(notdir $(wildcard $(USER_LIB_PATH)/*)), \
692
+ $(shell sed -ne "s/^ *\# *include *[<\"]\(.*\)\.h[>\"]/\1/p" $(LOCAL_SRCS)))
693
+ endif
694
+
695
+ ########################################################################
696
+ # Serial monitor (just a screen wrapper)
697
+
698
+ # Quite how to construct the monitor command seems intimately tied
699
+ # to the command we're using (here screen). So, read the screen docs
700
+ # for more information (search for 'character special device').
701
+
702
+ ifeq ($(strip $(NO_CORE)),)
703
+ ifndef MONITOR_BAUDRATE
704
+ ifeq ($(words $(LOCAL_PDE_SRCS) $(LOCAL_INO_SRCS)), 1)
705
+ SPEED = $(shell egrep -h 'Serial.begin *\([0-9]+\)' $(LOCAL_PDE_SRCS) $(LOCAL_INO_SRCS) | sed -e 's/[^0-9]//g'| head -n1)
706
+ MONITOR_BAUDRATE = $(findstring $(SPEED),300 1200 2400 4800 9600 14400 19200 28800 38400 57600 115200)
707
+ endif
708
+
709
+ ifeq ($(MONITOR_BAUDRATE),)
710
+ MONITOR_BAUDRATE = 9600
711
+ $(call show_config_variable,MONITOR_BAUDRATE,[ASSUMED])
712
+ else
713
+ $(call show_config_variable,MONITOR_BAUDRATE,[DETECTED], (in sketch))
714
+ endif
715
+ else
716
+ $(call show_config_variable,MONITOR_BAUDRATE, [USER])
717
+ endif
718
+
719
+ ifndef MONITOR_CMD
720
+ MONITOR_CMD = screen
721
+ endif
722
+ endif
723
+
724
+ ########################################################################
725
+ # Include Arduino Header file
726
+
727
+ ifndef ARDUINO_HEADER
728
+ # We should check for Arduino version, not just the file extension
729
+ # because, a .pde file can be used in Arduino 1.0 as well
730
+ ifeq ($(shell expr $(ARDUINO_VERSION) '<' 100), 1)
731
+ ARDUINO_HEADER=WProgram.h
732
+ else
733
+ ARDUINO_HEADER=Arduino.h
734
+ endif
735
+ endif
736
+
737
+ ########################################################################
738
+ # Rules for making stuff
739
+
740
+ # The name of the main targets
741
+ TARGET_HEX = $(OBJDIR)/$(TARGET).hex
742
+ TARGET_ELF = $(OBJDIR)/$(TARGET).elf
743
+ TARGET_EEP = $(OBJDIR)/$(TARGET).eep
744
+ TARGETS = $(OBJDIR)/$(TARGET).*
745
+ CORE_LIB = $(OBJDIR)/libcore.a
746
+
747
+ # Names of executables - chipKIT needs to override all to set paths to PIC32
748
+ # tools, and we can't use "?=" assignment because these are already implicitly
749
+ # defined by Make (e.g. $(CC) == cc).
750
+ ifndef OVERRIDE_EXECUTABLES
751
+ CC = $(AVR_TOOLS_PATH)/$(CC_NAME)
752
+ CXX = $(AVR_TOOLS_PATH)/$(CXX_NAME)
753
+ AS = $(AVR_TOOLS_PATH)/$(AS_NAME)
754
+ OBJCOPY = $(AVR_TOOLS_PATH)/$(OBJCOPY_NAME)
755
+ OBJDUMP = $(AVR_TOOLS_PATH)/$(OBJDUMP_NAME)
756
+ AR = $(AVR_TOOLS_PATH)/$(AR_NAME)
757
+ SIZE = $(AVR_TOOLS_PATH)/$(SIZE_NAME)
758
+ NM = $(AVR_TOOLS_PATH)/$(NM_NAME)
759
+ endif
760
+
761
+ REMOVE = rm -rf
762
+ MV = mv -f
763
+ CAT = cat
764
+ ECHO = printf
765
+ MKDIR = mkdir -p
766
+
767
+ # General arguments
768
+ USER_LIBS = $(wildcard $(patsubst %,$(USER_LIB_PATH)/%,$(ARDUINO_LIBS)))
769
+ USER_LIB_NAMES = $(patsubst $(USER_LIB_PATH)/%,%,$(USER_LIBS))
770
+
771
+ # Let user libraries override system ones.
772
+ SYS_LIBS = $(wildcard $(patsubst %,$(ARDUINO_LIB_PATH)/%,$(filter-out $(USER_LIB_NAMES),$(ARDUINO_LIBS))))
773
+ SYS_LIB_NAMES = $(patsubst $(ARDUINO_LIB_PATH)/%,%,$(SYS_LIBS))
774
+
775
+ # Error here if any are missing.
776
+ LIBS_NOT_FOUND = $(filter-out $(USER_LIB_NAMES) $(SYS_LIB_NAMES),$(ARDUINO_LIBS))
777
+ ifneq (,$(strip $(LIBS_NOT_FOUND)))
778
+ $(error The following libraries specified in ARDUINO_LIBS could not be found (searched USER_LIB_PATH and ARDUINO_LIB_PATH): $(LIBS_NOT_FOUND))
779
+ endif
780
+
781
+ SYS_LIBS := $(wildcard $(SYS_LIBS) $(addsuffix /utility,$(SYS_LIBS)))
782
+ USER_LIBS := $(wildcard $(USER_LIBS) $(addsuffix /utility,$(USER_LIBS)))
783
+ SYS_INCLUDES = $(patsubst %,-I%,$(SYS_LIBS))
784
+ USER_INCLUDES = $(patsubst %,-I%,$(USER_LIBS))
785
+ LIB_C_SRCS = $(wildcard $(patsubst %,%/*.c,$(SYS_LIBS)))
786
+ LIB_CPP_SRCS = $(wildcard $(patsubst %,%/*.cpp,$(SYS_LIBS)))
787
+ LIB_AS_SRCS = $(wildcard $(patsubst %,%/*.S,$(SYS_LIBS)))
788
+ USER_LIB_CPP_SRCS = $(wildcard $(patsubst %,%/*.cpp,$(USER_LIBS)))
789
+ USER_LIB_C_SRCS = $(wildcard $(patsubst %,%/*.c,$(USER_LIBS)))
790
+ USER_LIB_AS_SRCS = $(wildcard $(patsubst %,%/*.S,$(USER_LIBS)))
791
+ LIB_OBJS = $(patsubst $(ARDUINO_LIB_PATH)/%.c,$(OBJDIR)/libs/%.o,$(LIB_C_SRCS)) \
792
+ $(patsubst $(ARDUINO_LIB_PATH)/%.cpp,$(OBJDIR)/libs/%.o,$(LIB_CPP_SRCS)) \
793
+ $(patsubst $(ARDUINO_LIB_PATH)/%.S,$(OBJDIR)/libs/%.o,$(LIB_AS_SRCS))
794
+ USER_LIB_OBJS = $(patsubst $(USER_LIB_PATH)/%.cpp,$(OBJDIR)/libs/%.o,$(USER_LIB_CPP_SRCS)) \
795
+ $(patsubst $(USER_LIB_PATH)/%.c,$(OBJDIR)/libs/%.o,$(USER_LIB_C_SRCS)) \
796
+ $(patsubst $(USER_LIB_PATH)/%.S,$(OBJDIR)/libs/%.o,$(USER_LIB_AS_SRCS))
797
+
798
+ # Dependency files
799
+ DEPS = $(LOCAL_OBJS:.o=.d) $(LIB_OBJS:.o=.d) $(USER_LIB_OBJS:.o=.d) $(CORE_OBJS:.o=.d)
800
+
801
+ # Optimization level for the compiler.
802
+ # You can get the list of options at http://www.nongnu.org/avr-libc/user-manual/using_tools.html#gcc_optO
803
+ # Also read http://www.nongnu.org/avr-libc/user-manual/FAQ.html#faq_optflags
804
+ ifndef OPTIMIZATION_LEVEL
805
+ OPTIMIZATION_LEVEL=s
806
+ $(call show_config_variable,OPTIMIZATION_LEVEL,[DEFAULT])
807
+ else
808
+ $(call show_config_variable,OPTIMIZATION_LEVEL,[USER])
809
+ endif
810
+
811
+ ifndef DEBUG_FLAGS
812
+ DEBUG_FLAGS = -O0 -g
813
+ endif
814
+
815
+ # SoftwareSerial requires -Os (some delays are tuned for this optimization level)
816
+ %SoftwareSerial.o : OPTIMIZATION_FLAGS = -Os
817
+
818
+ ifndef MCU_FLAG_NAME
819
+ MCU_FLAG_NAME = mmcu
820
+ $(call show_config_variable,MCU_FLAG_NAME,[DEFAULT])
821
+ else
822
+ $(call show_config_variable,MCU_FLAG_NAME,[USER])
823
+ endif
824
+
825
+ # Using += instead of =, so that CPPFLAGS can be set per sketch level
826
+ CPPFLAGS += -$(MCU_FLAG_NAME)=$(MCU) -DF_CPU=$(F_CPU) -DARDUINO=$(ARDUINO_VERSION) -D__PROG_TYPES_COMPAT__ \
827
+ -I. -I$(ARDUINO_CORE_PATH) -I$(ARDUINO_VAR_PATH)/$(VARIANT) \
828
+ $(SYS_INCLUDES) $(USER_INCLUDES) -Wall -ffunction-sections \
829
+ -fdata-sections
830
+
831
+ ifdef DEBUG
832
+ OPTIMIZATION_FLAGS= $(DEBUG_FLAGS)
833
+ else
834
+ OPTIMIZATION_FLAGS = -O$(OPTIMIZATION_LEVEL)
835
+ endif
836
+
837
+ CPPFLAGS += $(OPTIMIZATION_FLAGS)
838
+
839
+ # USB IDs for the Caterina devices like leonardo or micro
840
+ ifneq ($(CATERINA),)
841
+ CPPFLAGS += -DUSB_VID=$(USB_VID) -DUSB_PID=$(USB_PID)
842
+ endif
843
+
844
+ ifndef CFLAGS_STD
845
+ CFLAGS_STD = -std=gnu99
846
+ $(call show_config_variable,CFLAGS_STD,[DEFAULT])
847
+ else
848
+ $(call show_config_variable,CFLAGS_STD,[USER])
849
+ endif
850
+
851
+ CFLAGS += $(EXTRA_FLAGS) $(EXTRA_CFLAGS)
852
+ CXXFLAGS += -fno-exceptions $(EXTRA_FLAGS) $(EXTRA_CXXFLAGS)
853
+ ASFLAGS += -x assembler-with-cpp
854
+ LDFLAGS += -$(MCU_FLAG_NAME)=$(MCU) -Wl,--gc-sections -O$(OPTIMIZATION_LEVEL) $(EXTRA_FLAGS) $(EXTRA_CXXFLAGS) $(EXTRA_LDFLAGS)
855
+ SIZEFLAGS ?= --mcu=$(MCU) -C
856
+
857
+ # for backwards compatibility, grab ARDUINO_PORT if the user has it set
858
+ MONITOR_PORT ?= $(ARDUINO_PORT)
859
+
860
+ ifeq ($(CURRENT_OS), WINDOWS)
861
+ # Expect MONITOR_PORT to be '1' or 'com1' for COM1 in Windows. Split it up
862
+ # into the two styles required: /dev/ttyS* for ard-reset-arduino and com*
863
+ # for avrdude. This also could work with /dev/com* device names and be more
864
+ # consistent, but the /dev/com* is not recommended by Cygwin and doesn't
865
+ # always show up.
866
+ COM_PORT_ID = $(subst com,,$(MONITOR_PORT))
867
+ COM_STYLE_MONITOR_PORT = com$(COM_PORT_ID)
868
+ DEVICE_PATH = /dev/ttyS$(shell awk 'BEGIN{ print $(COM_PORT_ID) - 1 }')
869
+ endif
870
+
871
+ ifdef ARDUINO_PORT
872
+ DEVICE_PATH = $(MONITOR_PORT)
873
+ else
874
+ # If no port is specified, try to guess it from wildcards.
875
+ DEVICE_PATH = $(firstword $(wildcard \
876
+ /dev/ttyACM? /dev/ttyUSB? /dev/tty.usbserial* /dev/tty.usbmodem*))
877
+ endif
878
+
879
+ # Returns the Arduino port (first wildcard expansion) if it exists, otherwise it errors.
880
+ get_monitor_port = $(if $(wildcard $(DEVICE_PATH)),$(firstword $(wildcard $(DEVICE_PATH))),$(error Arduino port $(DEVICE_PATH) not found!))
881
+
882
+ # Returns the ISP port (first wildcard expansion) if it exists, otherwise it errors.
883
+ get_isp_port = $(if $(wildcard $(ISP_PORT)),$(firstword $(wildcard $(ISP_PORT))),$(if $(findstring Xusb,X$(ISP_PORT)),$(ISP_PORT),$(error ISP port $(ISP_PORT) not found!)))
884
+
885
+ # Command for avr_size: do $(call avr_size,elffile,hexfile)
886
+ ifneq (,$(findstring AVR,$(shell $(SIZE) --help)))
887
+ # We have a patched version of binutils that mentions AVR - pass the MCU
888
+ # and the elf to get nice output.
889
+ avr_size = $(SIZE) $(SIZEFLAGS) --format=avr $(1)
890
+ $(call show_config_info,Size utility: AVR-aware for enhanced output,[AUTODETECTED])
891
+ else
892
+ # We have a plain-old binutils version - just give it the hex.
893
+ avr_size = $(SIZE) $(2)
894
+ $(call show_config_info,Size utility: Basic (not AVR-aware),[AUTODETECTED])
895
+ endif
896
+
897
+ ifneq (,$(strip $(ARDUINO_LIBS)))
898
+ $(call arduino_output,-)
899
+ $(call show_config_info,ARDUINO_LIBS =)
900
+ endif
901
+
902
+ ifneq (,$(strip $(USER_LIB_NAMES)))
903
+ $(foreach lib,$(USER_LIB_NAMES),$(call show_config_info, $(lib),[USER]))
904
+ endif
905
+
906
+ ifneq (,$(strip $(SYS_LIB_NAMES)))
907
+ $(foreach lib,$(SYS_LIB_NAMES),$(call show_config_info, $(lib),[SYSTEM]))
908
+ endif
909
+
910
+ # either calculate parent dir from arduino dir, or user-defined path
911
+ ifndef BOOTLOADER_PARENT
912
+ BOOTLOADER_PARENT = $(ARDUINO_DIR)/hardware/arduino/bootloaders
913
+ $(call show_config_variable,BOOTLOADER_PARENT,[COMPUTED],(from ARDUINO_DIR))
914
+ else
915
+ $(call show_config_variable,BOOTLOADER_PARENT,[USER])
916
+ endif
917
+
918
+ # end of config output
919
+ $(call show_separator)
920
+
921
+ # Implicit rules for building everything (needed to get everything in
922
+ # the right directory)
923
+ #
924
+ # Rather than mess around with VPATH there are quasi-duplicate rules
925
+ # here for building e.g. a system C++ file and a local C++
926
+ # file. Besides making things simpler now, this would also make it
927
+ # easy to change the build options in future
928
+
929
+ # library sources
930
+ $(OBJDIR)/libs/%.o: $(ARDUINO_LIB_PATH)/%.c
931
+ @$(MKDIR) $(dir $@)
932
+ $(CC) -MMD -c $(CPPFLAGS) $(CFLAGS) $< -o $@
933
+
934
+ $(OBJDIR)/libs/%.o: $(ARDUINO_LIB_PATH)/%.cpp
935
+ @$(MKDIR) $(dir $@)
936
+ $(CC) -MMD -c $(CPPFLAGS) $(CXXFLAGS) $< -o $@
937
+
938
+ $(OBJDIR)/libs/%.o: $(ARDUINO_LIB_PATH)/%.S
939
+ @$(MKDIR) $(dir $@)
940
+ $(CC) -MMD -c $(CPPFLAGS) $(ASFLAGS) $< -o $@
941
+
942
+ $(OBJDIR)/libs/%.o: $(USER_LIB_PATH)/%.cpp
943
+ @$(MKDIR) $(dir $@)
944
+ $(CC) -MMD -c $(CPPFLAGS) $(CFLAGS) $< -o $@
945
+
946
+ $(OBJDIR)/libs/%.o: $(USER_LIB_PATH)/%.c
947
+ @$(MKDIR) $(dir $@)
948
+ $(CC) -MMD -c $(CPPFLAGS) $(CFLAGS) $< -o $@
949
+
950
+ $(OBJDIR)/libs/%.o: $(USER_LIB_PATH)/%.S
951
+ @$(MKDIR) $(dir $@)
952
+ $(CC) -MMD -c $(CPPFLAGS) $(ASFLAGS) $< -o $@
953
+
954
+ ifdef COMMON_DEPS
955
+ COMMON_DEPS := $(COMMON_DEPS) $(MAKEFILE_LIST)
956
+ else
957
+ COMMON_DEPS := $(MAKEFILE_LIST)
958
+ endif
959
+
960
+ # normal local sources
961
+ $(OBJDIR)/%.o: %.c $(COMMON_DEPS) | $(OBJDIR)
962
+ @$(MKDIR) $(dir $@)
963
+ $(CC) -MMD -c $(CPPFLAGS) $(CFLAGS) $< -o $@
964
+
965
+ $(OBJDIR)/%.o: %.cc $(COMMON_DEPS) | $(OBJDIR)
966
+ @$(MKDIR) $(dir $@)
967
+ $(CXX) -MMD -c $(CPPFLAGS) $(CXXFLAGS) $< -o $@
968
+
969
+ $(OBJDIR)/%.o: %.cpp $(COMMON_DEPS) | $(OBJDIR)
970
+ @$(MKDIR) $(dir $@)
971
+ $(CXX) -MMD -c $(CPPFLAGS) $(CXXFLAGS) $< -o $@
972
+
973
+ $(OBJDIR)/%.o: %.S $(COMMON_DEPS) | $(OBJDIR)
974
+ @$(MKDIR) $(dir $@)
975
+ $(CC) -MMD -c $(CPPFLAGS) $(ASFLAGS) $< -o $@
976
+
977
+ $(OBJDIR)/%.o: %.s $(COMMON_DEPS) | $(OBJDIR)
978
+ @$(MKDIR) $(dir $@)
979
+ $(CC) -c $(CPPFLAGS) $(ASFLAGS) $< -o $@
980
+
981
+ # the pde -> o file
982
+ $(OBJDIR)/%.o: %.pde $(COMMON_DEPS) | $(OBJDIR)
983
+ @$(MKDIR) $(dir $@)
984
+ $(CXX) -x c++ -include $(ARDUINO_HEADER) -MMD -c $(CPPFLAGS) $(CXXFLAGS) $< -o $@
985
+
986
+ # the ino -> o file
987
+ $(OBJDIR)/%.o: %.ino $(COMMON_DEPS) | $(OBJDIR)
988
+ @$(MKDIR) $(dir $@)
989
+ $(CXX) -x c++ -include $(ARDUINO_HEADER) -MMD -c $(CPPFLAGS) $(CXXFLAGS) $< -o $@
990
+
991
+ # generated assembly
992
+ $(OBJDIR)/%.s: %.pde $(COMMON_DEPS) | $(OBJDIR)
993
+ @$(MKDIR) $(dir $@)
994
+ $(CXX) -x c++ -include $(ARDUINO_HEADER) -MMD -S -fverbose-asm $(CPPFLAGS) $(CXXFLAGS) $< -o $@
995
+
996
+ $(OBJDIR)/%.s: %.ino $(COMMON_DEPS) | $(OBJDIR)
997
+ @$(MKDIR) $(dir $@)
998
+ $(CXX) -x c++ -include $(ARDUINO_HEADER) -MMD -S -fverbose-asm $(CPPFLAGS) $(CXXFLAGS) $< -o $@
999
+
1000
+ #$(OBJDIR)/%.lst: $(OBJDIR)/%.s
1001
+ # $(AS) -$(MCU_FLAG_NAME)=$(MCU) -alhnd $< > $@
1002
+
1003
+ # core files
1004
+ $(OBJDIR)/%.o: $(ARDUINO_CORE_PATH)/%.c $(COMMON_DEPS) | $(OBJDIR)
1005
+ @$(MKDIR) $(dir $@)
1006
+ $(CC) -MMD -c $(CPPFLAGS) $(CFLAGS) $< -o $@
1007
+
1008
+ $(OBJDIR)/%.o: $(ARDUINO_CORE_PATH)/%.cpp $(COMMON_DEPS) | $(OBJDIR)
1009
+ @$(MKDIR) $(dir $@)
1010
+ $(CXX) -MMD -c $(CPPFLAGS) $(CXXFLAGS) $< -o $@
1011
+
1012
+ $(OBJDIR)/%.o: $(ARDUINO_CORE_PATH)/%.S $(COMMON_DEPS) | $(OBJDIR)
1013
+ @$(MKDIR) $(dir $@)
1014
+ $(CC) -MMD -c $(CPPFLAGS) $(ASFLAGS) $< -o $@
1015
+
1016
+ # various object conversions
1017
+ $(OBJDIR)/%.hex: $(OBJDIR)/%.elf $(COMMON_DEPS)
1018
+ @$(MKDIR) $(dir $@)
1019
+ $(OBJCOPY) -O ihex -R .eeprom $< $@
1020
+ @$(ECHO) '\n'
1021
+ $(call avr_size,$<,$@)
1022
+ ifneq ($(strip $(HEX_MAXIMUM_SIZE)),)
1023
+ @if [ `$(SIZE) $@ | awk 'FNR == 2 {print $$2}'` -le $(HEX_MAXIMUM_SIZE) ]; then touch $@.sizeok; fi
1024
+ else
1025
+ @$(ECHO) "Maximum flash memory of $(BOARD_TAG) is not specified. Make sure the size of $@ is less than $(BOARD_TAG)\'s flash memory"
1026
+ @touch $@.sizeok
1027
+ endif
1028
+
1029
+ $(OBJDIR)/%.eep: $(OBJDIR)/%.elf $(COMMON_DEPS)
1030
+ @$(MKDIR) $(dir $@)
1031
+ -$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
1032
+ --change-section-lma .eeprom=0 -O ihex $< $@
1033
+
1034
+ $(OBJDIR)/%.lss: $(OBJDIR)/%.elf $(COMMON_DEPS)
1035
+ @$(MKDIR) $(dir $@)
1036
+ $(OBJDUMP) -h --source --demangle --wide $< > $@
1037
+
1038
+ $(OBJDIR)/%.sym: $(OBJDIR)/%.elf $(COMMON_DEPS)
1039
+ @$(MKDIR) $(dir $@)
1040
+ $(NM) --size-sort --demangle --reverse-sort --line-numbers $< > $@
1041
+
1042
+ ########################################################################
1043
+ # Avrdude
1044
+
1045
+ # If avrdude is installed separately, it can find its own config file
1046
+ ifndef AVRDUDE
1047
+ AVRDUDE = $(AVR_TOOLS_PATH)/avrdude
1048
+ endif
1049
+
1050
+ # Default avrdude options
1051
+ # -V Do not verify
1052
+ # -q - suppress progress output
1053
+ # -D - Disable auto erase for flash memory
1054
+ # (-D is needed for Mega boards. See https://github.com/sudar/Arduino-Makefile/issues/114#issuecomment-25011005)
1055
+ ifndef AVRDUDE_OPTS
1056
+ AVRDUDE_OPTS = -q -V -D
1057
+ endif
1058
+
1059
+ AVRDUDE_COM_OPTS = $(AVRDUDE_OPTS) -p $(MCU)
1060
+ ifdef AVRDUDE_CONF
1061
+ AVRDUDE_COM_OPTS += -C $(AVRDUDE_CONF)
1062
+ endif
1063
+
1064
+ AVRDUDE_ARD_OPTS = -c $(AVRDUDE_ARD_PROGRAMMER) -b $(AVRDUDE_ARD_BAUDRATE) -P
1065
+ ifeq ($(CURRENT_OS), WINDOWS)
1066
+ # get_monitor_port checks to see if the monitor port exists, assuming it is
1067
+ # a file. In Windows, avrdude needs the port in the format 'com1' which is
1068
+ # not a file, so we have to add the COM-style port directly.
1069
+ AVRDUDE_ARD_OPTS += $(COM_STYLE_MONITOR_PORT)
1070
+ else
1071
+ AVRDUDE_ARD_OPTS += $(call get_monitor_port)
1072
+ endif
1073
+
1074
+ ifndef ISP_PROG
1075
+ ifneq ($(strip $(AVRDUDE_ARD_PROGRAMMER)),)
1076
+ ISP_PROG = $(AVRDUDE_ARD_PROGRAMMER)
1077
+ else
1078
+ ISP_PROG = stk500v1
1079
+ endif
1080
+ endif
1081
+
1082
+ ifndef AVRDUDE_ISP_BAUDRATE
1083
+ ifneq ($(strip $(AVRDUDE_ARD_BAUDRATE)),)
1084
+ AVRDUDE_ISP_BAUDRATE = $(AVRDUDE_ARD_BAUDRATE)
1085
+ else
1086
+ AVRDUDE_ISP_BAUDRATE = 19200
1087
+ endif
1088
+ endif
1089
+
1090
+ # Fuse settings copied from Arduino IDE.
1091
+ # https://github.com/arduino/Arduino/blob/master/app/src/processing/app/debug/AvrdudeUploader.java#L254
1092
+
1093
+ # Pre fuse settings
1094
+ ifndef AVRDUDE_ISP_FUSES_PRE
1095
+ ifneq ($(strip $(ISP_LOCK_FUSE_PRE)),)
1096
+ AVRDUDE_ISP_FUSES_PRE += -U lock:w:$(ISP_LOCK_FUSE_PRE):m
1097
+ endif
1098
+
1099
+ ifneq ($(strip $(ISP_EXT_FUSE)),)
1100
+ AVRDUDE_ISP_FUSES_PRE += -U efuse:w:$(ISP_EXT_FUSE):m
1101
+ endif
1102
+
1103
+ ifneq ($(strip $(ISP_HIGH_FUSE)),)
1104
+ AVRDUDE_ISP_FUSES_PRE += -U hfuse:w:$(ISP_HIGH_FUSE):m
1105
+ endif
1106
+
1107
+ ifneq ($(strip $(ISP_LOW_FUSE)),)
1108
+ AVRDUDE_ISP_FUSES_PRE += -U lfuse:w:$(ISP_LOW_FUSE):m
1109
+ endif
1110
+ endif
1111
+
1112
+ # Bootloader file settings
1113
+ ifndef AVRDUDE_ISP_BURN_BOOTLOADER
1114
+ ifneq ($(strip $(BOOTLOADER_PATH)),)
1115
+ ifneq ($(strip $(BOOTLOADER_FILE)),)
1116
+ AVRDUDE_ISP_BURN_BOOTLOADER += -U flash:w:$(BOOTLOADER_PARENT)/$(BOOTLOADER_PATH)/$(BOOTLOADER_FILE):i
1117
+ endif
1118
+ endif
1119
+ endif
1120
+
1121
+ # Post fuse settings
1122
+ ifndef AVRDUDE_ISP_FUSES_POST
1123
+ ifneq ($(strip $(ISP_LOCK_FUSE_POST)),)
1124
+ AVRDUDE_ISP_FUSES_POST += -U lock:w:$(ISP_LOCK_FUSE_POST):m
1125
+ endif
1126
+ endif
1127
+
1128
+ AVRDUDE_ISP_OPTS = -c $(ISP_PROG) -b $(AVRDUDE_ISP_BAUDRATE)
1129
+
1130
+ ifndef $(ISP_PORT)
1131
+ ifneq ($(strip $(ISP_PROG)),$(filter $(ISP_PROG), usbasp usbtiny gpio))
1132
+ AVRDUDE_ISP_OPTS += -P $(call get_isp_port)
1133
+ endif
1134
+ else
1135
+ AVRDUDE_ISP_OPTS += -P $(call get_isp_port)
1136
+ endif
1137
+
1138
+ ifndef ISP_EEPROM
1139
+ ISP_EEPROM = 0
1140
+ endif
1141
+
1142
+ AVRDUDE_UPLOAD_HEX = -U flash:w:$(TARGET_HEX):i
1143
+ AVRDUDE_UPLOAD_EEP = -U eeprom:w:$(TARGET_EEP):i
1144
+ AVRDUDE_ISPLOAD_OPTS = $(AVRDUDE_UPLOAD_HEX)
1145
+
1146
+ ifneq ($(ISP_EEPROM), 0)
1147
+ AVRDUDE_ISPLOAD_OPTS += $(AVRDUDE_UPLOAD_EEP)
1148
+ endif
1149
+
1150
+ ########################################################################
1151
+ # Explicit targets start here
1152
+
1153
+ all: $(TARGET_EEP) $(TARGET_HEX)
1154
+
1155
+ # Rule to create $(OBJDIR) automatically. All rules with recipes that
1156
+ # create a file within it, but do not already depend on a file within it
1157
+ # should depend on this rule. They should use a "order-only
1158
+ # prerequisite" (e.g., put "| $(OBJDIR)" at the end of the prerequisite
1159
+ # list) to prevent remaking the target when any file in the directory
1160
+ # changes.
1161
+ $(OBJDIR): pre-build
1162
+ $(MKDIR) $(OBJDIR)
1163
+
1164
+ pre-build:
1165
+ $(call runscript_if_exists,$(PRE_BUILD_HOOK))
1166
+
1167
+ $(TARGET_ELF): $(LOCAL_OBJS) $(CORE_LIB) $(OTHER_OBJS)
1168
+ $(CC) $(LDFLAGS) -o $@ $(LOCAL_OBJS) $(CORE_LIB) $(OTHER_OBJS) -lc -lm
1169
+
1170
+ $(CORE_LIB): $(CORE_OBJS) $(LIB_OBJS) $(USER_LIB_OBJS)
1171
+ $(AR) rcs $@ $(CORE_OBJS) $(LIB_OBJS) $(USER_LIB_OBJS)
1172
+
1173
+ error_on_caterina:
1174
+ $(ERROR_ON_CATERINA)
1175
+
1176
+
1177
+ # Use submake so we can guarantee the reset happens
1178
+ # before the upload, even with make -j
1179
+ upload: $(TARGET_HEX) verify_size
1180
+ $(MAKE) reset
1181
+ $(MAKE) do_upload
1182
+
1183
+ raw_upload: $(TARGET_HEX) verify_size
1184
+ $(MAKE) error_on_caterina
1185
+ $(MAKE) do_upload
1186
+
1187
+ do_upload:
1188
+ $(AVRDUDE) $(AVRDUDE_COM_OPTS) $(AVRDUDE_ARD_OPTS) \
1189
+ $(AVRDUDE_UPLOAD_HEX)
1190
+
1191
+ do_eeprom: $(TARGET_EEP) $(TARGET_HEX)
1192
+ $(AVRDUDE) $(AVRDUDE_COM_OPTS) $(AVRDUDE_ARD_OPTS) \
1193
+ $(AVRDUDE_UPLOAD_EEP)
1194
+
1195
+ eeprom: $(TARGET_HEX) verify_size
1196
+ $(MAKE) reset
1197
+ $(MAKE) do_eeprom
1198
+
1199
+ raw_eeprom: $(TARGET_HEX) verify_size
1200
+ $(MAKE) error_on_caterina
1201
+ $(MAKE) do_eeprom
1202
+
1203
+ reset:
1204
+ $(call arduino_output,Resetting Arduino...)
1205
+ $(RESET_CMD)
1206
+
1207
+ # stty on MacOS likes -F, but on Debian it likes -f redirecting
1208
+ # stdin/out appears to work but generates a spurious error on MacOS at
1209
+ # least. Perhaps it would be better to just do it in perl ?
1210
+ reset_stty:
1211
+ for STTYF in 'stty -F' 'stty --file' 'stty -f' 'stty <' ; \
1212
+ do $$STTYF /dev/tty >/dev/null 2>&1 && break ; \
1213
+ done ; \
1214
+ $$STTYF $(call get_monitor_port) hupcl ; \
1215
+ (sleep 0.1 2>/dev/null || sleep 1) ; \
1216
+ $$STTYF $(call get_monitor_port) -hupcl
1217
+
1218
+ ispload: $(TARGET_EEP) $(TARGET_HEX) verify_size
1219
+ $(AVRDUDE) $(AVRDUDE_COM_OPTS) $(AVRDUDE_ISP_OPTS) \
1220
+ $(AVRDUDE_ISPLOAD_OPTS)
1221
+
1222
+ burn_bootloader:
1223
+ ifneq ($(strip $(AVRDUDE_ISP_FUSES_PRE)),)
1224
+ $(AVRDUDE) $(AVRDUDE_COM_OPTS) $(AVRDUDE_ISP_OPTS) -e $(AVRDUDE_ISP_FUSES_PRE)
1225
+ endif
1226
+ ifneq ($(strip $(AVRDUDE_ISP_BURN_BOOTLOADER)),)
1227
+ $(AVRDUDE) $(AVRDUDE_COM_OPTS) $(AVRDUDE_ISP_OPTS) $(AVRDUDE_ISP_BURN_BOOTLOADER)
1228
+ endif
1229
+ ifneq ($(strip $(AVRDUDE_ISP_FUSES_POST)),)
1230
+ $(AVRDUDE) $(AVRDUDE_COM_OPTS) $(AVRDUDE_ISP_OPTS) $(AVRDUDE_ISP_FUSES_POST)
1231
+ endif
1232
+
1233
+ set_fuses:
1234
+ ifneq ($(strip $(AVRDUDE_ISP_FUSES_PRE)),)
1235
+ $(AVRDUDE) $(AVRDUDE_COM_OPTS) $(AVRDUDE_ISP_OPTS) -e $(AVRDUDE_ISP_FUSES_PRE)
1236
+ endif
1237
+ ifneq ($(strip $(AVRDUDE_ISP_FUSES_POST)),)
1238
+ $(AVRDUDE) $(AVRDUDE_COM_OPTS) $(AVRDUDE_ISP_OPTS) $(AVRDUDE_ISP_FUSES_POST)
1239
+ endif
1240
+
1241
+ clean:
1242
+ $(REMOVE) $(LOCAL_OBJS) $(CORE_OBJS) $(LIB_OBJS) $(CORE_LIB) $(TARGETS) $(DEPS) $(USER_LIB_OBJS) ${OBJDIR}
1243
+
1244
+ size: $(TARGET_HEX)
1245
+ $(call avr_size,$(TARGET_ELF),$(TARGET_HEX))
1246
+
1247
+ show_boards:
1248
+ @$(CAT) $(BOARDS_TXT) | grep -E "^[[:alnum:]]" | cut -d . -f 1 | uniq
1249
+
1250
+ monitor:
1251
+ $(MONITOR_CMD) $(call get_monitor_port) $(MONITOR_BAUDRATE)
1252
+
1253
+ disasm: $(OBJDIR)/$(TARGET).lss
1254
+ @$(ECHO) "The compiled ELF file has been disassembled to $(OBJDIR)/$(TARGET).lss"
1255
+
1256
+ symbol_sizes: $(OBJDIR)/$(TARGET).sym
1257
+ @$(ECHO) "A symbol listing sorted by their size have been dumped to $(OBJDIR)/$(TARGET).sym"
1258
+
1259
+ verify_size:
1260
+ ifeq ($(strip $(HEX_MAXIMUM_SIZE)),)
1261
+ @$(ECHO) "\nMaximum flash memory of $(BOARD_TAG) is not specified. Make sure the size of $(TARGET_HEX) is less than $(BOARD_TAG)\'s flash memory\n\n"
1262
+ endif
1263
+ @if [ ! -f $(TARGET_HEX).sizeok ]; then echo >&2 "\nThe size of the compiled binary file is greater than the $(BOARD_TAG)'s flash memory. \
1264
+ See http://www.arduino.cc/en/Guide/Troubleshooting#size for tips on reducing it."; false; fi
1265
+
1266
+ generate_assembly: $(OBJDIR)/$(TARGET).s
1267
+ @$(ECHO) "Compiler-generated assembly for the main input source has been dumped to $(OBJDIR)/$(TARGET).s"
1268
+
1269
+ generated_assembly: generate_assembly
1270
+ @$(ECHO) "\"generated_assembly\" target is deprecated. Use \"generate_assembly\" target instead"
1271
+
1272
+ help_vars:
1273
+ @$(CAT) $(ARDMK_DIR)/arduino-mk-vars.md
1274
+
1275
+ help:
1276
+ @$(ECHO) "\nAvailable targets:\n\
1277
+ make - no upload\n\
1278
+ make upload - upload\n\
1279
+ make clean - remove all our dependencies\n\
1280
+ make depends - update dependencies\n\
1281
+ make reset - reset the Arduino by tickling DTR on the serial port\n\
1282
+ make raw_upload - upload without first resetting\n\
1283
+ make show_boards - list all the boards defined in boards.txt\n\
1284
+ make monitor - connect to the Arduino's serial port\n\
1285
+ make size - show the size of the compiled output (relative to\n\
1286
+ resources, if you have a patched avr-size)\n\
1287
+ make disasm - generate a .lss file in build-cli that contains\n\
1288
+ disassembly of the compiled file interspersed\n\
1289
+ with your original source code.\n\
1290
+ make verify_size - Verify that the size of the final file is less than\n\
1291
+ the capacity of the micro controller.\n\
1292
+ make eeprom - upload the eep file\n\
1293
+ make raw_eeprom - upload the eep file without first resetting\n\
1294
+ make burn_bootloader - burn bootloader and fuses\n\
1295
+ make set_fuses - set fuses without burning bootloader\n\
1296
+ make help_vars - print all variables that can be overridden\n\
1297
+ make help - show this help\n\
1298
+ "
1299
+ @$(ECHO) "Please refer to $(ARDMK_DIR)/Arduino.mk for more details.\n"
1300
+
1301
+ .PHONY: all upload raw_upload raw_eeprom error_on_caterina reset reset_stty ispload \
1302
+ clean depends size show_boards monitor disasm symbol_sizes generated_assembly \
1303
+ generate_assembly verify_size burn_bootloader help pre-build
1304
+
1305
+ # added - in the beginning, so that we don't get an error if the file is not present
1306
+ -include $(DEPS)