239
239
$(error There is more than one .pde or .ino file in this directory!)
242
# automatically determine sources and targeet
242
# automatically determine sources and target
243
243
TARGET := $(basename $(INOFILE))
244
244
SOURCES := $(INOFILE) \
245
$(wildcard *.c *.cc *.cpp *.C) \
246
$(wildcard $(addprefix util/, *.c *.cc *.cpp *.C)) \
247
$(wildcard $(addprefix utility/, *.c *.cc *.cpp *.C))
249
# automatically determine included libraries
250
LIBRARIES := $(filter $(notdir $(wildcard $(addsuffix /*, $(LIBRARYPATH)))), \
251
$(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)))))
258
277
CXX := $(call findsoftware,avr-g++)
259
278
LD := $(call findsoftware,avr-ld)
260
279
AR := $(call findsoftware,avr-ar)
280
AS := $(call findsoftware,avr-as)
261
281
OBJCOPY := $(call findsoftware,avr-objcopy)
262
282
AVRDUDE := $(call findsoftware,avrdude)
263
283
AVRSIZE := $(call findsoftware,avr-size)
266
286
ARDUINOCOREDIR := $(ARDUINODIR)/hardware/arduino/cores/$(BOARD_BUILD_CORE)
267
LIBRARYDIRS := $(foreach lib, $(LIBRARIES), \
268
$(firstword $(wildcard $(addsuffix /$(lib), $(LIBRARYPATH)))))
269
287
LIBRARYDIRS += $(addsuffix /utility, $(LIBRARYDIRS))
274
292
DEPFILES := $(patsubst %, .dep/%.dep, $(SOURCES))
275
293
ARDUINOLIB := .lib/arduino.a
276
294
ARDUINOLIBOBJS := $(foreach dir, $(ARDUINOCOREDIR) $(LIBRARYDIRS), \
277
$(patsubst %, .lib/%.o, $(wildcard $(addprefix $(dir)/, *.c *.cpp))))
295
$(patsubst %, .lib/%.o, $(wildcard $(addprefix $(dir)/, \
296
*.c *.cc *.cpp *.C *.s *.S))))
278
297
BOOTLOADERHEX := $(addprefix \
279
298
$(ARDUINODIR)/hardware/arduino/bootloaders/$(BOARD_BOOTLOADER_PATH)/, \
280
299
$(BOARD_BOOTLOADER_FILE))