199
199
# obtain board parameters from the arduino boards.txt file
200
200
BOARDSFILE := $(ARDUINODIR)/hardware/arduino/boards.txt
201
readboardsparam = $(shell sed -ne "s/$(BOARD).$(1)=\(.*\)/\1/p" $(BOARDSFILE))
201
readboardsparam = $(shell sed -ne "s/^$(BOARD).$(1)=\(.*\)/\1/p" $(BOARDSFILE))
202
202
BOARD_BUILD_MCU := $(call readboardsparam,build.mcu)
203
203
BOARD_BUILD_FCPU := $(call readboardsparam,build.f_cpu)
204
204
BOARD_BUILD_VARIANT := $(call readboardsparam,build.variant)
205
BOARD_BUILD_CORE := $(call readboardsparam,build.core)
205
206
BOARD_UPLOAD_SPEED := $(call readboardsparam,upload.speed)
206
207
BOARD_UPLOAD_PROTOCOL := $(call readboardsparam,upload.protocol)
207
208
BOARD_USB_VID := $(call readboardsparam,build.vid)
238
239
$(error There is more than one .pde or .ino file in this directory!)
241
# automatically determine sources and targeet
242
# automatically determine sources and target
242
243
TARGET := $(basename $(INOFILE))
243
244
SOURCES := $(INOFILE) \
244
$(wildcard *.c *.cc *.cpp *.C) \
245
$(wildcard $(addprefix util/, *.c *.cc *.cpp *.C)) \
246
$(wildcard $(addprefix utility/, *.c *.cc *.cpp *.C))
248
# automatically determine included libraries
249
LIBRARIES := $(filter $(notdir $(wildcard $(addsuffix /*, $(LIBRARYPATH)))), \
250
$(shell sed -ne "s/^ *\# *include *[<\"]\(.*\)\.h[>\"]/\1/p" $(SOURCES)))
245
$(wildcard *.c *.cc *.cpp *.C *.s *.S) \
246
$(wildcard $(addprefix util/, *.c *.cc *.cpp *.C *.s *.S)) \
247
$(wildcard $(addprefix utility/, *.c *.cc *.cpp *.C *.s *.S))
249
# automatically determine library directories (to pull library sources in from)
250
# by matching included headers in poject sources to headers that exist in the
251
# roots of any library directories, giving priority to libraries in the order
252
# they're in LIBRARYPATH, and then to the alphabetically-greater named library
253
# (this is a really stupid way of doing it, but it's how the IDE works -- if
254
# it's causing problems, you can override it by setting LIBRARIES manually)
256
$(shell sed -nre "s/^\s*\#\s*include\s*[<\"](\S+\.h)[>\"].*/\1/p" \
258
reverse = $(if $(1),$(call reverse,$(wordlist 2,$(words $(1)),$(1)))) \
260
LIBRARYHEADERS := $(foreach dir, $(LIBRARYPATH), \
261
$(call reverse, $(sort $(wildcard $(dir)/*))))
262
LIBRARYHEADERS := $(foreach dir, $(LIBRARYHEADERS), $(wildcard $(dir)/*.h))
263
LIBRARYDIRS := $(foreach hdr, $(INCLUDEDHEADERS), $(patsubst %/$(hdr), %, \
264
$(firstword $(filter %/$(hdr), $(LIBRARYHEADERS)))))
268
# if LIBRARIES is specified, use it
269
ifneq "$(LIBRARIES)" ""
270
LIBRARYDIRS := $(foreach lib, $(LIBRARIES), \
271
$(firstword $(wildcard $(addsuffix /$(lib), $(LIBRARYPATH)))))
257
277
CXX := $(call findsoftware,avr-g++)
258
278
LD := $(call findsoftware,avr-ld)
259
279
AR := $(call findsoftware,avr-ar)
280
AS := $(call findsoftware,avr-as)
260
281
OBJCOPY := $(call findsoftware,avr-objcopy)
261
282
AVRDUDE := $(call findsoftware,avrdude)
262
283
AVRSIZE := $(call findsoftware,avr-size)
265
ARDUINOCOREDIR := $(ARDUINODIR)/hardware/arduino/cores/arduino
266
LIBRARYDIRS := $(foreach lib, $(LIBRARIES), \
267
$(firstword $(wildcard $(addsuffix /$(lib), $(LIBRARYPATH)))))
286
ARDUINOCOREDIR := $(ARDUINODIR)/hardware/arduino/cores/$(BOARD_BUILD_CORE)
268
287
LIBRARYDIRS += $(addsuffix /utility, $(LIBRARYDIRS))
273
292
DEPFILES := $(patsubst %, .dep/%.dep, $(SOURCES))
274
293
ARDUINOLIB := .lib/arduino.a
275
294
ARDUINOLIBOBJS := $(foreach dir, $(ARDUINOCOREDIR) $(LIBRARYDIRS), \
276
$(patsubst %, .lib/%.o, $(wildcard $(addprefix $(dir)/, *.c *.cpp))))
295
$(patsubst %, .lib/%.o, $(wildcard $(addprefix $(dir)/, \
296
*.c *.cc *.cpp *.C *.s *.S))))
277
297
BOOTLOADERHEX := $(addprefix \
278
298
$(ARDUINODIR)/hardware/arduino/bootloaders/$(BOARD_BOOTLOADER_PATH)/, \
279
299
$(BOARD_BOOTLOADER_FILE))
299
319
CPPDEPFLAGS = -MMD -MP -MF .dep/$<.dep
300
320
CPPINOFLAGS := -x c++ -include $(ARDUINOCOREDIR)/Arduino.h
301
321
AVRDUDEFLAGS += $(addprefix -C , $(AVRDUDECONF)) -DV
302
AVRDUDEFLAGS += -p $(BOARD_BUILD_MCU) -P $(SERIALDEV)
303
AVRDUDEFLAGS += -c $(BOARD_UPLOAD_PROTOCOL) -b $(BOARD_UPLOAD_SPEED)
322
AVRDUDEFLAGS += -p$(BOARD_BUILD_MCU) -P$(SERIALDEV) -c$(BOARD_UPLOAD_PROTOCOL)
323
AVRDUDEFLAGS += $(addprefix -b, $(BOARD_UPLOAD_SPEED))
304
324
LINKFLAGS += -Os -Wl,--gc-sections -mmcu=$(BOARD_BUILD_MCU)
306
326
# figure out which arg to use with stty (for OS X, GNU and busybox stty)