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.
81
88
# 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.
84
94
# SERIALDEV The unix device name of the serial device that is the arduino.
85
95
# If unspecified, an attempt is made to determine the name of a
86
96
# connected arduino's serial device.
98
# SOURCES A list of all source files of whatever language. The language
99
# type is determined by the file extension. This is set
100
# automatically if a .ino (or .pde) is found.
88
102
# TARGET The name of the target file. This is set automatically if a
89
103
# .ino (or .pde) is found, but it is not necessary to set it
92
# SOURCES A list of all source files of whatever language. The language
93
# type is determined by the file extension. This is set
94
# automatically if a .ino (or .pde) is found.
96
# LIBRARIES A list of arduino libraries to build and include. This is set
97
# automatically if a .ino (or .pde) is found.
99
106
# This makefile also defines the following goals for use on the command line
100
107
# when you run make:
119
126
#_______________________________________________________________________________
122
# The full path to the arduino software, from arduino.cc
129
# default arduino software directory, check software exists
123
130
ifndef ARDUINODIR
124
131
ARDUINODIR := $(wildcard ~/opt/arduino)
127
# check arduino software
128
133
ifeq ($(wildcard $(ARDUINODIR)/hardware/arduino/boards.txt), )
129
134
$(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
133
148
INOFILE := $(wildcard *.ino *.pde)
135
150
ifneq ($(words $(INOFILE)), 1)
136
151
$(error There is more than one .pde or .ino file in this directory!)
154
# automatically determine sources and targeet
138
155
TARGET := $(basename $(INOFILE))
139
156
SOURCES := $(INOFILE) \
140
157
$(wildcard *.c *.cc *.cpp) \
141
158
$(wildcard $(addprefix util/, *.c *.cc *.cpp)) \
142
159
$(wildcard $(addprefix utility/, *.c *.cc *.cpp))
143
161
# automatically determine included libraries
144
162
ARDUINOLIBSAVAIL := $(notdir $(wildcard $(ARDUINODIR)/libraries/*))
145
163
LIBRARIES := $(filter $(ARDUINOLIBSAVAIL), \
146
164
$(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?))
159
168
# 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)
169
193
OBJECTS := $(addsuffix .o, $(basename $(SOURCES)))
170
194
ARDUINOSRCDIR := $(ARDUINODIR)/hardware/arduino/cores/arduino
171
195
ARDUINOLIBSDIR := $(ARDUINODIR)/libraries
177
201
$(patsubst %, $(ARDUINOLIBTMP)/%.o, $(basename $(notdir \
178
202
$(wildcard $(addprefix $(ARDUINOLIBSDIR)/$(lib)/, *.c *.cpp)) \
179
203
$(wildcard $(addprefix $(ARDUINOLIBSDIR)/$(lib)/utility/, *.c *.cpp)) ))))
204
AVRDUDECONF := $(wildcard $(AVRDUDE).conf)
181
206
# obtain board parameters from the arduino boards.txt file
182
207
BOARDS_FILE := $(ARDUINODIR)/hardware/arduino/boards.txt
191
216
BOARD_UPLOAD_PROTOCOL := \
192
217
$(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)
207
CPPFLAGS = -Os -Wall -fno-exceptions -ffunction-sections -fdata-sections
208
CPPFLAGS += -mmcu=$(BOARD_BUILD_MCU) -DF_CPU=$(BOARD_BUILD_FCPU)
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)
209
224
CPPFLAGS += -I. -Iutil -Iutility -I$(ARDUINOSRCDIR)
210
225
CPPFLAGS += -I$(ARDUINODIR)/hardware/arduino/variants/$(BOARD_BUILD_VARIANT)/
211
226
CPPFLAGS += $(addprefix -I$(ARDUINODIR)/libraries/, $(LIBRARIES))
212
227
CPPFLAGS += $(patsubst %, -I$(ARDUINODIR)/libraries/%/utility, $(LIBRARIES))
213
AVRDUDEFLAGS = -C $(ARDUINODIR)/hardware/tools/avrdude.conf -DV
228
AVRDUDEFLAGS := $(addprefix -C , $(AVRDUDECONF)) -DV
214
229
AVRDUDEFLAGS += -p $(BOARD_BUILD_MCU) -P $(SERIALDEV)
215
230
AVRDUDEFLAGS += -c $(BOARD_UPLOAD_PROTOCOL) -b $(BOARD_UPLOAD_SPEED)
216
LINKFLAGS = -Os -Wl,--gc-sections -mmcu=$(BOARD_BUILD_MCU)
231
LINKFLAGS := -Os -Wl,--gc-sections -mmcu=$(BOARD_BUILD_MCU)
219
234
.DEFAULT_GOAL := all