60
60
# You may also need to set SERIALDEV if it is not detected correctly.
62
# The presence of a .ino (or .pde) file causes the arduino.mk to automatically
62
# The presence of a .ino or .pde file causes the arduino.mk to automatically
63
63
# determine values for SOURCES, TARGET and LIBRARIES. Any .c, .cc and .cpp
64
64
# files in the project directory (or any "util" or "utility" subdirectories)
65
65
# are automatically included in the build and are scanned for Arduino libraries
66
# that have been #included. Note, there can only be one .ino (or .pde) file.
66
# that have been #included. Note, there can only be one .ino or .pde file.
68
68
# Alternatively, if you want to manually specify build variables, create a
69
69
# Makefile that defines SOURCES and LIBRARIES and then includes arduino.mk.
78
78
# ARDUINODIR The path where you have installed/unpacked the arduino software
79
79
# (from http://arduino.cc/)
81
# ARDUINOCONST The arduino software version, as an integer, used to define the
82
# ARDUINO version constant. This defaults to 100 if unset.
84
# AVRTOOLSPATH A space-separated list of directories to search in order when
85
# lookin for the avr build tools. This defaults to the system PATH
86
# followed by subdirectories in ARDUINODIR if unset.
88
81
# BOARD Specify a target board type. Run `make boards` to see available
91
# LIBRARIES A list of arduino libraries to build and include. This is set
92
# automatically if a .ino (or .pde) is found.
94
84
# SERIALDEV The unix device name of the serial device that is the arduino.
95
85
# If unspecified, an attempt is made to determine the name of a
96
86
# connected arduino's serial device.
88
# TARGET The name of the target file. This is set automatically if a
89
# .ino or .pde is found, but it is not necessary to set it
98
92
# SOURCES A list of all source files of whatever language. The language
99
93
# type is determined by the file extension. This is set
100
# automatically if a .ino (or .pde) is found.
94
# automatically if a .ino or .pde is found.
102
# TARGET The name of the target file. This is set automatically if a
103
# .ino (or .pde) is found, but it is not necessary to set it
96
# LIBRARIES A list of arduino libraries to build and include. This is set
97
# automatically if a .ino or .pde is found.
106
99
# This makefile also defines the following goals for use on the command line
107
100
# when you run make:
126
119
#_______________________________________________________________________________
129
# default arduino software directory, check software exists
122
# The full path to the arduino software, from arduino.cc
130
123
ifndef ARDUINODIR
131
124
ARDUINODIR := $(wildcard ~/opt/arduino)
127
# check arduino software
133
128
ifeq ($(wildcard $(ARDUINODIR)/hardware/arduino/boards.txt), )
134
129
$(error ARDUINODIR is not set correctly; arduino software not found)
137
# default arduino version
140
# default path for avr tools
142
AVRTOOLSPATH := $(subst :, , $(PATH))
143
AVRTOOLSPATH += $(ARDUINODIR)/hardware/tools
144
AVRTOOLSPATH += $(ARDUINODIR)/hardware/tools/avr/bin
148
133
INOFILE := $(wildcard *.ino *.pde)
150
135
ifneq ($(words $(INOFILE)), 1)
151
136
$(error There is more than one .pde or .ino file in this directory!)
154
# automatically determine sources and targeet
155
138
TARGET := $(basename $(INOFILE))
156
139
SOURCES := $(INOFILE) \
157
140
$(wildcard *.c *.cc *.cpp) \
158
141
$(wildcard $(addprefix util/, *.c *.cc *.cpp)) \
159
142
$(wildcard $(addprefix utility/, *.c *.cc *.cpp))
161
143
# automatically determine included libraries
162
144
ARDUINOLIBSAVAIL := $(notdir $(wildcard $(ARDUINODIR)/libraries/*))
163
145
LIBRARIES := $(filter $(ARDUINOLIBSAVAIL), \
164
146
$(shell sed -ne "s/^ *\# *include *[<\"]\(.*\)\.h[>\"]/\1/p" $(SOURCES)))
149
# no target? use default
154
# no serial device? attempt to detect an arduino
155
ifeq ($(SERIALDEV), )
156
SERIALDEV := $(firstword $(wildcard /dev/ttyACM? /dev/ttyUSB?))
168
159
# no board? oh dear...
177
# no serial device? make a poor attempt to detect an arduino
178
ifeq ($(SERIALDEV), )
179
SERIALDEV := $(firstword $(wildcard /dev/ttyACM? /dev/ttyUSB?))
183
findsoftware = $(firstword $(wildcard $(addsuffix /$(1), $(AVRTOOLSPATH))))
184
CC := $(call findsoftware,avr-gcc)
185
CXX := $(call findsoftware,avr-g++)
186
LD := $(call findsoftware,avr-ld)
187
AR := $(call findsoftware,avr-ar)
188
OBJCOPY := $(call findsoftware,avr-objcopy)
189
AVRDUDE := $(call findsoftware,avrdude)
192
TARGET := $(if $(TARGET), $(TARGET), a.out)
193
169
OBJECTS := $(addsuffix .o, $(basename $(SOURCES)))
194
170
ARDUINOSRCDIR := $(ARDUINODIR)/hardware/arduino/cores/arduino
195
171
ARDUINOLIBSDIR := $(ARDUINODIR)/libraries
201
177
$(patsubst %, $(ARDUINOLIBTMP)/%.o, $(basename $(notdir \
202
178
$(wildcard $(addprefix $(ARDUINOLIBSDIR)/$(lib)/, *.c *.cpp)) \
203
179
$(wildcard $(addprefix $(ARDUINOLIBSDIR)/$(lib)/utility/, *.c *.cpp)) ))))
204
AVRDUDECONF := $(wildcard $(AVRDUDE).conf)
206
181
# obtain board parameters from the arduino boards.txt file
207
182
BOARDS_FILE := $(ARDUINODIR)/hardware/arduino/boards.txt
216
191
BOARD_UPLOAD_PROTOCOL := \
217
192
$(shell sed -ne "s/$(BOARD).upload.protocol=\(.*\)/\1/p" $(BOARDS_FILE))
194
# software (prioritise binaries that came with arduino software)
195
FIND_SOFTWARE = $(firstword $(wildcard \
196
$(ARDUINODIR)/hardware/tools/$(1) \
197
$(ARDUINODIR)/hardware/tools/avr/bin/$(1) \
199
CC := $(call FIND_SOFTWARE,avr-gcc)
200
CXX := $(call FIND_SOFTWARE,avr-g++)
201
LD := $(call FIND_SOFTWARE,avr-ld)
202
AR := $(call FIND_SOFTWARE,avr-ar)
203
OBJCOPY := $(call FIND_SOFTWARE,avr-objcopy)
204
AVRDUDE := $(call FIND_SOFTWARE,avrdude)
220
CPPFLAGS := -Os -Wall -fno-exceptions -ffunction-sections -fdata-sections
221
CPPFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums
222
CPPFLAGS += -mmcu=$(BOARD_BUILD_MCU)
223
CPPFLAGS += -DF_CPU=$(BOARD_BUILD_FCPU) -DARDUINO=$(ARDUINOCONST)
207
CPPFLAGS = -Os -Wall -fno-exceptions -ffunction-sections -fdata-sections
208
CPPFLAGS += -mmcu=$(BOARD_BUILD_MCU) -DF_CPU=$(BOARD_BUILD_FCPU)
224
209
CPPFLAGS += -I. -Iutil -Iutility -I$(ARDUINOSRCDIR)
225
210
CPPFLAGS += -I$(ARDUINODIR)/hardware/arduino/variants/$(BOARD_BUILD_VARIANT)/
226
211
CPPFLAGS += $(addprefix -I$(ARDUINODIR)/libraries/, $(LIBRARIES))
227
212
CPPFLAGS += $(patsubst %, -I$(ARDUINODIR)/libraries/%/utility, $(LIBRARIES))
228
AVRDUDEFLAGS := $(addprefix -C , $(AVRDUDECONF)) -DV
213
AVRDUDEFLAGS = -C $(ARDUINODIR)/hardware/tools/avrdude.conf -DV
229
214
AVRDUDEFLAGS += -p $(BOARD_BUILD_MCU) -P $(SERIALDEV)
230
215
AVRDUDEFLAGS += -c $(BOARD_UPLOAD_PROTOCOL) -b $(BOARD_UPLOAD_SPEED)
231
LINKFLAGS := -Os -Wl,--gc-sections -mmcu=$(BOARD_BUILD_MCU)
216
LINKFLAGS = -Os -Wl,--gc-sections -mmcu=$(BOARD_BUILD_MCU)
234
219
.DEFAULT_GOAL := all