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.
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.
102
88
# TARGET The name of the target file. This is set automatically if a
103
89
# .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.
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
# arduino version (currently fixed)
197
# software (prioritise binaries that came with arduino software)
198
FIND_SOFTWARE = $(firstword $(wildcard \
199
$(ARDUINODIR)/hardware/tools/$(1) \
200
$(ARDUINODIR)/hardware/tools/avr/bin/$(1) \
202
CC := $(call FIND_SOFTWARE,avr-gcc)
203
CXX := $(call FIND_SOFTWARE,avr-g++)
204
LD := $(call FIND_SOFTWARE,avr-ld)
205
AR := $(call FIND_SOFTWARE,avr-ar)
206
OBJCOPY := $(call FIND_SOFTWARE,avr-objcopy)
207
AVRDUDE := $(call FIND_SOFTWARE,avrdude)
220
CPPFLAGS := -Os -Wall -fno-exceptions -ffunction-sections -fdata-sections
210
CPPFLAGS = -Os -Wall -fno-exceptions -ffunction-sections -fdata-sections
221
211
CPPFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums
222
212
CPPFLAGS += -mmcu=$(BOARD_BUILD_MCU)
223
CPPFLAGS += -DF_CPU=$(BOARD_BUILD_FCPU) -DARDUINO=$(ARDUINOCONST)
213
CPPFLAGS += -DF_CPU=$(BOARD_BUILD_FCPU) -DARDUINO=$(ARDUINOVER)
224
214
CPPFLAGS += -I. -Iutil -Iutility -I$(ARDUINOSRCDIR)
225
215
CPPFLAGS += -I$(ARDUINODIR)/hardware/arduino/variants/$(BOARD_BUILD_VARIANT)/
226
216
CPPFLAGS += $(addprefix -I$(ARDUINODIR)/libraries/, $(LIBRARIES))
227
217
CPPFLAGS += $(patsubst %, -I$(ARDUINODIR)/libraries/%/utility, $(LIBRARIES))
228
AVRDUDEFLAGS := $(addprefix -C , $(AVRDUDECONF)) -DV
218
AVRDUDEFLAGS = -C $(ARDUINODIR)/hardware/tools/avrdude.conf -DV
229
219
AVRDUDEFLAGS += -p $(BOARD_BUILD_MCU) -P $(SERIALDEV)
230
220
AVRDUDEFLAGS += -c $(BOARD_UPLOAD_PROTOCOL) -b $(BOARD_UPLOAD_SPEED)
231
LINKFLAGS := -Os -Wl,--gc-sections -mmcu=$(BOARD_BUILD_MCU)
221
LINKFLAGS = -Os -Wl,--gc-sections -mmcu=$(BOARD_BUILD_MCU)
234
224
.DEFAULT_GOAL := all