169
166
# automatically determine sources and targeet
170
167
TARGET := $(basename $(INOFILE))
171
168
SOURCES := $(INOFILE) \
172
$(wildcard *.c *.cc *.cpp *.C) \
173
$(wildcard $(addprefix util/, *.c *.cc *.cpp *.C)) \
174
$(wildcard $(addprefix utility/, *.c *.cc *.cpp *.C))
169
$(wildcard *.c *.cc *.cpp) \
170
$(wildcard $(addprefix util/, *.c *.cc *.cpp)) \
171
$(wildcard $(addprefix utility/, *.c *.cc *.cpp))
176
173
# automatically determine included libraries
177
LIBRARIES := $(filter $(notdir $(wildcard $(addsuffix /*, $(LIBRARIESPATH)))), \
174
LIBRARIES := $(filter $(notdir $(wildcard $(ARDUINODIR)/libraries/*)), \
178
175
$(shell sed -ne "s/^ *\# *include *[<\"]\(.*\)\.h[>\"]/\1/p" $(SOURCES)))
201
198
TARGET := $(if $(TARGET),$(TARGET),a.out)
202
199
OBJECTS := $(addsuffix .o, $(basename $(SOURCES)))
203
200
DEPFILES := $(patsubst %, .dep/%.dep, $(SOURCES))
206
LIBRARIESDIRS := $(foreach lib, $(LIBRARIES), \
207
$(firstword $(wildcard $(addsuffix /$(lib), $(LIBRARIESPATH)))))
208
LIBRARIESDIRS += $(addsuffix /utility, $(LIBRARIESDIRS))
209
201
ARDUINOCOREDIR := $(ARDUINODIR)/hardware/arduino/cores/arduino
212
202
ARDUINOLIB := .lib/arduino.a
213
ARDUINOLIBOBJS := $(foreach dir, $(ARDUINOCOREDIR) $(LIBRARIESDIRS), \
203
ARDUINOLIBLIBSDIR := $(ARDUINODIR)/libraries
204
ARDUINOLIBLIBSPATH := $(foreach lib, $(LIBRARIES), \
205
$(ARDUINODIR)/libraries/$(lib)/ $(ARDUINODIR)/libraries/$(lib)/utility/ )
206
ARDUINOLIBOBJS := $(foreach dir, $(ARDUINOCOREDIR) $(ARDUINOLIBLIBSPATH), \
214
207
$(patsubst %, .lib/%.o, $(wildcard $(addprefix $(dir)/, *.c *.cpp))))
216
# avrdude confifuration
217
208
ifeq "$(AVRDUDECONF)" ""
218
209
ifeq "$(AVRDUDE)" "$(ARDUINODIR)/hardware/tools/avr/bin/avrdude"
219
210
AVRDUDECONF := $(ARDUINODIR)/hardware/tools/avr/etc/avrdude.conf
261
CPPFLAGS += -Os -Wall -fno-exceptions -ffunction-sections -fdata-sections
252
CPPFLAGS := -Os -Wall -fno-exceptions -ffunction-sections -fdata-sections
262
253
CPPFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums
263
254
CPPFLAGS += -mmcu=$(BOARD_BUILD_MCU)
264
255
CPPFLAGS += -DF_CPU=$(BOARD_BUILD_FCPU) -DARDUINO=$(ARDUINOCONST)
265
256
CPPFLAGS += -DUSB_VID=$(BOARD_USB_VID) -DUSB_PID=$(BOARD_USB_PID)
266
257
CPPFLAGS += -I. -Iutil -Iutility -I $(ARDUINOCOREDIR)
267
258
CPPFLAGS += -I $(ARDUINODIR)/hardware/arduino/variants/$(BOARD_BUILD_VARIANT)/
268
CPPFLAGS += $(addprefix -I , $(LIBRARIESDIRS))
259
CPPFLAGS += $(addprefix -I $(ARDUINODIR)/libraries/, $(LIBRARIES))
260
CPPFLAGS += $(patsubst %, -I $(ARDUINODIR)/libraries/%/utility, $(LIBRARIES))
269
261
CPPDEPFLAGS = -MMD -MP -MF .dep/$<.dep
270
262
CPPINOFLAGS := -x c++ -include $(ARDUINOCOREDIR)/Arduino.h
271
AVRDUDEFLAGS += $(addprefix -C , $(AVRDUDECONF)) -DV
263
AVRDUDEFLAGS := $(addprefix -C , $(AVRDUDECONF)) -DV
272
264
AVRDUDEFLAGS += -p $(BOARD_BUILD_MCU) -P $(SERIALDEV)
273
265
AVRDUDEFLAGS += -c $(BOARD_UPLOAD_PROTOCOL) -b $(BOARD_UPLOAD_SPEED)
274
LINKFLAGS += -Os -Wl,--gc-sections -mmcu=$(BOARD_BUILD_MCU)
266
LINKFLAGS := -Os -Wl,--gc-sections -mmcu=$(BOARD_BUILD_MCU)
276
268
# figure out which arg to use with stty (for OS X, GNU and busybox stty)
277
269
STTYFARG := $(shell stty --help 2>&1 | \