34
34
# more information and documentation on it's use. The following text
35
35
# can only really be considered a reference to it's use.
37
# There are two ways to use this file, an automatic mode and a manual
38
# mode. In automatic mode, you simply copy this makefile to your
39
# arduino project directory, rename it "Makefile" and type make. The
40
# project directory is expected to contain an .ino or .pde file, which
41
# will automatically be used automatically, along with any other .c,
42
# .cc or .cpp files in the project directory and any subdirectory
43
# named "utility". In this way, this makefile should act as a drop-in
44
# replacement for the Arduino IDE's build process and can build a
45
# project automatically from the files in a project directory.
47
# Alternatively, you can manually specify what files should be
48
# inclided in a build. To use this makefile manually, you might be
49
# better to keep it somewhere and include it in your project's
50
# Makefile after having defined certain parameters that control the
51
# build. As an example, consider the following Makefile:
54
# SOURCES = main.cc foo.cc
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:
56
43
# SERIALDEV = /dev/ttyACM0
57
44
# include ~/src/arduino.mk
59
# In both manual and automatic modes, the standard Arduino main.cpp's
60
# main() is included, which expects to be able to call init() and
61
# loop() in your code. The main difference is that, in manual mode,
62
# these would typically be placed in a .cc or .cpp file.
64
# 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:
66
78
# TARGET The name of the target file. This is typically the same name
67
79
# as the project directory for an arduino project and, if
70
82
# SOURCES A list of all source files of whatever language. The language
71
83
# type is determined by the file extension.
73
# BOARD Specify a target board type. These are defined in boards.txt,
74
# which came with your arduino installation. If unspecified,
75
# a default is used. (See below).
77
# SERIALDEV The unix device of the device where the arduino can be found.
78
# If unspecified, a default is used. (See below).
85
# LIBRARIES A list of arduino libraries to include
80
87
# This general-purpose makefile also defines the following goals for use on the
81
88
# command line when you run make:
143
150
TARGET := $(basename $(INOFILE))
144
151
SOURCES := $(INOFILE) \
145
$(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)))
149
162
OBJECTS := $(addsuffix .o, $(basename $(SOURCES)))
153
163
ARDUINOSRCDIR := $(ARDUINODIR)/hardware/arduino/cores/arduino
154
164
ARDUINOLIB := _arduino.a
155
165
ARDUINOLIBTMP := _arduino.a.tmp
156
ARDUINOSOURCES := $(wildcard $(ARDUINOSRCDIR)/*.c $(ARDUINOSRCDIR)/*.cpp)
157
ARDUINOOBJECTS := $(addsuffix .o, $(addprefix $(ARDUINOLIBTMP)/, $(basename \
158
$(notdir $(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))))))
160
172
# obtain board parameters from the arduino boards.txt file
161
173
BOARDS_FILE := $(ARDUINODIR)/hardware/arduino/boards.txt