30
30
# This is a general purpose makefile for use with Arduino (arduino.cc)
31
31
# hardware and software. It works with the arduino-1.0 release and
32
# requires that to be downloaded separately. It can be downloaded
33
# from http://ed.am/dev/make/arduino-makefile where you can also find
34
# more information and documentation on it's use. The following text
35
# can only really be considered a reference to it's use.
37
# To use this makefile, put a file named "Makefile" in your project
38
# directory. Add all your project's settings to your Makefile and
39
# then include this file from it. For example, your Makefile might
40
# look something like this:
32
# requires that to be downloaded separately.
34
# There are two ways to use this file, an automatic mode and a manual
35
# mode. In automatic mode, you simply copy this makefile to your
36
# arduino project directory, rename it "Makefile" and type make. The
37
# project directory is expected to contain an .ino or .pde file, which
38
# will automatically be used automatically, along with any other .c,
39
# .cc or .cpp files in the project directory and any subdirectory
40
# named "utility". In this way, this makefile should act as a drop-in
41
# replacement for the Arduino IDE's build process and can build a
42
# project automatically from the files in a project directory.
44
# Alternatively, you can manually specify what files should be
45
# inclided in a build. To use this makefile manually, you might be
46
# better to keep it somewhere and include it in your project's
47
# Makefile after having defined certain parameters that control the
48
# build. As an example, consider the following Makefile:
51
# SOURCES = main.cc foo.cc
43
53
# SERIALDEV = /dev/ttyACM0
44
54
# include ~/src/arduino.mk
46
# A complete list of all the settings you can use in your Makefile
47
# follows shortly. But it should be noted that there are two ways to
48
# use this file, an automatic mode and a manual mode.
50
# In automatic mode, you simply define a BOARD and SERIALDEV and then
51
# include this makefile. The project directory must contain an .ino
52
# or .pde file, which will automatically be used, along with any other
53
# .c, .cc or .cpp files in the project directory. When buliding, any
54
# arduino libraries that are #included in your code are detected and
55
# automatically linked against. In this way, this makefile should act
56
# as a drop-in replacement for the Arduino IDE's build system. You
57
# should be able to type "make" from the command line and achieve the
58
# same as building and uploading from the Arduino IDE.
60
# The alternative, manual mode, makes no assumptions. If the
61
# directory doesn't contain an .ino or .pde file, you must also
62
# specify the SOURCES, TARGET and LIBRARIES manually in your Makefile.
63
# You will also be expected to provide a main() function, for example
64
# in main.cc, which may or may not duplicate the functionality of the
65
# default main() that calls init() and loop().
67
# Here is a list of all configuration parameters:
56
# In both manual and automatic modes, the standard Arduino main.cpp's
57
# main() is included, which expects to be able to call init() and
58
# loop() in your code. The main difference is that, in manual mode,
59
# these would typically be placed in a .cc or .cpp file.
61
# When using manual mode, the following variables can be used:
63
# TARGET The name of the target file. This is typically the same name
64
# as the project directory for an arduino project and, if
65
# unspecified, that is used as a default.
67
# SOURCES A list of all source files of whatever language. The language
68
# type is determined by the file extension.
69
70
# BOARD Specify a target board type. These are defined in boards.txt,
70
71
# which came with your arduino installation. If unspecified,
73
74
# SERIALDEV The unix device of the device where the arduino can be found.
74
75
# If unspecified, a default is used. (See below).
76
# The following configuration parameters can be determined automatically:
78
# TARGET The name of the target file. This is typically the same name
79
# as the project directory for an arduino project and, if
80
# unspecified, that is used as a default.
82
# SOURCES A list of all source files of whatever language. The language
83
# type is determined by the file extension.
85
# LIBRARIES A list of arduino libraries to include
87
77
# This general-purpose makefile also defines the following goals for use on the
88
78
# command line when you run make:
150
140
TARGET := $(basename $(INOFILE))
151
141
SOURCES := $(INOFILE) \
152
$(wildcard *.c *.cc *.cpp) \
153
$(wildcard $(addprefix util/, *.c *.cc *.cpp)) \
154
$(wildcard $(addprefix utility/, *.c *.cc *.cpp))
155
# automatically determine included libraries
156
ARDUINOLIBSAVAIL := $(notdir $(wildcard $(ARDUINODIR)/libraries/*))
157
LIBRARIES := $(filter $(ARDUINOLIBSAVAIL), \
158
$(shell sed -ne "s/^ *\# *include *[<\"]\(.*\)\.h[>\"]/\1/p" $(SOURCES)))
142
$(wildcard *.c *.cc *.cpp $(addprefix utility/, *.c *.cc *.cpp))
162
146
OBJECTS := $(addsuffix .o, $(basename $(SOURCES)))
163
150
ARDUINOSRCDIR := $(ARDUINODIR)/hardware/arduino/cores/arduino
164
151
ARDUINOLIB := _arduino.a
165
152
ARDUINOLIBTMP := _arduino.a.tmp
166
ARDUINOLIBOBJS := $(patsubst %, $(ARDUINOLIBTMP)/%.o, $(basename $(notdir \
167
$(wildcard $(addprefix $(ARDUINOSRCDIR)/, *.c *.cpp)))))
168
ARDUINOLIBOBJS += $(foreach lib, $(LIBRARIES), \
169
$(patsubst %, $(ARDUINOLIBTMP)/%.o, $(basename $(notdir \
170
$(wildcard $(addprefix $(ARDUINODIR)/libraries/$(lib)/, *.c *.cpp))))))
153
ARDUINOSOURCES := $(wildcard $(addprefix $(ARDUINOSRCDIR)/, *.c *.cpp))
154
ARDUINOOBJECTS := $(addsuffix .o, $(addprefix $(ARDUINOLIBTMP)/, $(basename \
155
$(subst $(ARDUINOSRCDIR)/,,$(ARDUINOSOURCES)))))
172
# obtain board parameters from the arduino boards.txt file
157
# obtain parameters from the arduino boards.txt file
173
158
BOARDS_FILE := $(ARDUINODIR)/hardware/arduino/boards.txt
174
159
BOARD_BUILD_MCU := \
175
160
$(shell sed -ne "s/$(BOARD).build.mcu=\(.*\)/\1/p" $(BOARDS_FILE))
190
175
OBJCOPY := avr-objcopy
192
#$(ARDUINODIR)/hardware/tools/avrdude
176
AVRDUDE := $(ARDUINODIR)/hardware/tools/avrdude
195
179
CPPFLAGS = -Os -Wall -fno-exceptions -ffunction-sections -fdata-sections
196
180
CPPFLAGS += -mmcu=$(BOARD_BUILD_MCU) -DF_CPU=$(BOARD_BUILD_FCPU)
197
181
CPPFLAGS += -I. -Iutility -I$(ARDUINOSRCDIR)
198
182
CPPFLAGS += -I$(ARDUINODIR)/hardware/arduino/variants/$(BOARD_BUILD_VARIANT)/
199
CPPFLAGS += $(addprefix -I$(ARDUINODIR)/libraries/,$(LIBRARIES))
200
AVRDUDEFLAGS = -C $(ARDUINODIR)/hardware/tools/avrdude.conf -DV
183
AVRDUDEFLAGS = -V -F -C $(ARDUINODIR)/hardware/tools/avrdude.conf
201
184
AVRDUDEFLAGS += -p $(BOARD_BUILD_MCU) -P $(SERIALDEV)
202
185
AVRDUDEFLAGS += -c $(BOARD_UPLOAD_PROTOCOL) -b $(BOARD_UPLOAD_SPEED)
203
LINKFLAGS = -Os -Wl,--gc-sections -mmcu=$(BOARD_BUILD_MCU)
206
188
ifeq ($(TARGET),)