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.
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
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:
53
43
# SERIALDEV = /dev/ttyACM0
54
44
# include ~/src/arduino.mk
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:
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:
69
# BOARD Specify a target board type. These are defined in boards.txt,
70
# which came with your arduino installation. If unspecified,
71
# a default is used. (See below).
73
# SERIALDEV The unix device of the device where the arduino can be found.
74
# If unspecified, a default is used. (See below).
76
# The following configuration parameters can be determined automatically:
63
78
# TARGET The name of the target file. This is typically the same name
64
79
# as the project directory for an arduino project and, if
140
150
TARGET := $(basename $(INOFILE))
141
151
SOURCES := $(INOFILE) \
142
$(wildcard *.c *.cc *.cpp $(addprefix utility/, *.c *.cc *.cpp))
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)))
146
162
OBJECTS := $(addsuffix .o, $(basename $(SOURCES)))
150
163
ARDUINOSRCDIR := $(ARDUINODIR)/hardware/arduino/cores/arduino
151
164
ARDUINOLIB := _arduino.a
152
165
ARDUINOLIBTMP := _arduino.a.tmp
153
ARDUINOSOURCES := $(wildcard $(addprefix $(ARDUINOSRCDIR)/, *.c *.cpp))
154
ARDUINOOBJECTS := $(addsuffix .o, $(addprefix $(ARDUINOLIBTMP)/, $(basename \
155
$(subst $(ARDUINOSRCDIR)/,,$(ARDUINOSOURCES)))))
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))))))
157
# obtain parameters from the arduino boards.txt file
172
# obtain board parameters from the arduino boards.txt file
158
173
BOARDS_FILE := $(ARDUINODIR)/hardware/arduino/boards.txt
159
174
BOARD_BUILD_MCU := \
160
175
$(shell sed -ne "s/$(BOARD).build.mcu=\(.*\)/\1/p" $(BOARDS_FILE))
175
190
OBJCOPY := avr-objcopy
176
AVRDUDE := $(ARDUINODIR)/hardware/tools/avrdude
192
#$(ARDUINODIR)/hardware/tools/avrdude
179
195
CPPFLAGS = -Os -Wall -fno-exceptions -ffunction-sections -fdata-sections
180
196
CPPFLAGS += -mmcu=$(BOARD_BUILD_MCU) -DF_CPU=$(BOARD_BUILD_FCPU)
181
197
CPPFLAGS += -I. -Iutility -I$(ARDUINOSRCDIR)
182
198
CPPFLAGS += -I$(ARDUINODIR)/hardware/arduino/variants/$(BOARD_BUILD_VARIANT)/
183
AVRDUDEFLAGS = -V -F -C $(ARDUINODIR)/hardware/tools/avrdude.conf
199
CPPFLAGS += $(addprefix -I$(ARDUINODIR)/libraries/,$(LIBRARIES))
200
AVRDUDEFLAGS = -C $(ARDUINODIR)/hardware/tools/avrdude.conf -DV
184
201
AVRDUDEFLAGS += -p $(BOARD_BUILD_MCU) -P $(SERIALDEV)
185
202
AVRDUDEFLAGS += -c $(BOARD_UPLOAD_PROTOCOL) -b $(BOARD_UPLOAD_SPEED)
203
LINKFLAGS = -Os -Wl,--gc-sections -mmcu=$(BOARD_BUILD_MCU)
188
206
ifeq ($(TARGET),)