131
131
# monitor Start `screen` on the serial device. This is meant to be an
132
132
# equivalent to the Arduino serial monitor.
134
# size Displays size information about the bulit target.
134
136
# <file> Builds the specified file, either an object file or the target,
135
137
# from those that that would be built for the project.
136
138
#_______________________________________________________________________________
169
171
$(wildcard $(addprefix utility/, *.c *.cc *.cpp))
171
173
# automatically determine included libraries
172
ARDUINOLIBSAVAIL := $(notdir $(wildcard $(ARDUINODIR)/libraries/*))
173
LIBRARIES := $(filter $(ARDUINOLIBSAVAIL), \
174
LIBRARIES := $(filter $(notdir $(wildcard $(ARDUINODIR)/libraries/*)), \
174
175
$(shell sed -ne "s/^ *\# *include *[<\"]\(.*\)\.h[>\"]/\1/p" $(SOURCES)))
191
192
AR := $(call findsoftware,avr-ar)
192
193
OBJCOPY := $(call findsoftware,avr-objcopy)
193
194
AVRDUDE := $(call findsoftware,avrdude)
195
AVRSIZE := $(call findsoftware,avr-size)
196
198
TARGET := $(if $(TARGET),$(TARGET),a.out)
197
199
OBJECTS := $(addsuffix .o, $(basename $(SOURCES)))
198
ARDUINOSRCDIR := $(ARDUINODIR)/hardware/arduino/cores/arduino
199
ARDUINOLIBSDIR := $(ARDUINODIR)/libraries
200
ARDUINOLIB := _arduino.a
201
ARDUINOLIBTMP := $(ARDUINOLIB).tmp
202
ARDUINOLIBOBJS := $(patsubst %, $(ARDUINOLIBTMP)/%.o, $(basename $(notdir \
203
$(wildcard $(addprefix $(ARDUINOSRCDIR)/, *.c *.cpp)))))
204
ARDUINOLIBOBJS += $(foreach lib, $(LIBRARIES), \
205
$(patsubst %, $(ARDUINOLIBTMP)/%.o, $(basename $(notdir \
206
$(wildcard $(addprefix $(ARDUINOLIBSDIR)/$(lib)/, *.c *.cpp)) \
207
$(wildcard $(addprefix $(ARDUINOLIBSDIR)/$(lib)/utility/, *.c *.cpp)) ))))
200
ARDUINOCOREDIR := $(ARDUINODIR)/hardware/arduino/cores/arduino
201
ARDUINOLIB := .lib/arduino.a
202
ARDUINOLIBLIBSDIR := $(ARDUINODIR)/libraries
203
ARDUINOLIBLIBSPATH := $(foreach lib, $(LIBRARIES), \
204
$(ARDUINODIR)/libraries/$(lib)/ $(ARDUINODIR)/libraries/$(lib)/utility/ )
205
ARDUINOLIBOBJS := $(foreach dir, $(ARDUINOCOREDIR) $(ARDUINOLIBLIBSPATH), \
206
$(patsubst %, .lib/%.o, $(wildcard $(addprefix $(dir)/, *.c *.cpp))))
208
207
ifeq "$(AVRDUDECONF)" ""
209
208
ifeq "$(AVRDUDE)" "$(ARDUINODIR)/hardware/tools/avr/bin/avrdude"
210
209
AVRDUDECONF := $(ARDUINODIR)/hardware/tools/avr/etc/avrdude.conf
248
CPPFLAGS := -Os -Wall -fno-exceptions -ffunction-sections -fdata-sections
249
CPPFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums
250
CPPFLAGS += -mmcu=$(BOARD_BUILD_MCU)
251
CPPFLAGS += -DF_CPU=$(BOARD_BUILD_FCPU) -DARDUINO=$(ARDUINOCONST)
252
CPPFLAGS += -I. -Iutil -Iutility -I$(ARDUINOSRCDIR)
253
CPPFLAGS += -I$(ARDUINODIR)/hardware/arduino/variants/$(BOARD_BUILD_VARIANT)/
254
CPPFLAGS += $(addprefix -I$(ARDUINODIR)/libraries/, $(LIBRARIES))
255
CPPFLAGS += $(patsubst %, -I$(ARDUINODIR)/libraries/%/utility, $(LIBRARIES))
247
CPPFLAGS_S := -Os -Wall -fno-exceptions -ffunction-sections -fdata-sections
248
CPPFLAGS_S += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums
249
CPPFLAGS_S += -mmcu=$(BOARD_BUILD_MCU)
250
CPPFLAGS_S += -DF_CPU=$(BOARD_BUILD_FCPU) -DARDUINO=$(ARDUINOCONST)
251
CPPFLAGS_S += -I. -Iutil -Iutility -I$(ARDUINOCOREDIR)
252
CPPFLAGS_S += -I$(ARDUINODIR)/hardware/arduino/variants/$(BOARD_BUILD_VARIANT)/
253
CPPFLAGS_S += $(addprefix -I$(ARDUINODIR)/libraries/, $(LIBRARIES))
254
CPPFLAGS_S += $(patsubst %, -I$(ARDUINODIR)/libraries/%/utility, $(LIBRARIES))
255
CPPFLAGS = $(CPPFLAGS_S)
256
256
AVRDUDEFLAGS := $(addprefix -C , $(AVRDUDECONF)) -DV
257
257
AVRDUDEFLAGS += -p $(BOARD_BUILD_MCU) -P $(SERIALDEV)
258
258
AVRDUDEFLAGS += -c $(BOARD_UPLOAD_PROTOCOL) -b $(BOARD_UPLOAD_SPEED)
316
319
$(TARGET).elf: $(ARDUINOLIB) $(OBJECTS)
317
320
$(CC) $(LINKFLAGS) $(OBJECTS) $(ARDUINOLIB) -o $@
323
# $(COMPILE.c) -o $@ $<
320
$(COMPILE.cpp) -o $@ -x c++ -include $(ARDUINOSRCDIR)/Arduino.h $<
326
$(COMPILE.cpp) -o $@ -x c++ -include $(ARDUINOCOREDIR)/Arduino.h $<
323
$(COMPILE.cpp) -o $@ -x c++ -include $(ARDUINOSRCDIR)/Arduino.h $<
329
$(COMPILE.cpp) -o $@ -x c++ -include $(ARDUINOCOREDIR)/Arduino.h $<
325
331
# building the arduino library
327
333
$(ARDUINOLIB): $(ARDUINOLIBOBJS)
329
rm -rf $(ARDUINOLIBTMP)
331
.INTERMEDIATE: $(ARDUINOLIBOBJS)
333
$(ARDUINOLIBTMP)/%.o: $(ARDUINOSRCDIR)/%.c
334
@test -d $(ARDUINOLIBTMP) || mkdir $(ARDUINOLIBTMP)
335
$(COMPILE.c) -o $@ $<
337
$(ARDUINOLIBTMP)/%.o: $(ARDUINOSRCDIR)/%.cpp
338
@test -d $(ARDUINOLIBTMP) || mkdir $(ARDUINOLIBTMP)
339
$(COMPILE.cpp) -o $@ $<
341
$(ARDUINOLIBTMP)/%.o: $(ARDUINODIR)/libraries/*/%.c
342
@test -d $(ARDUINOLIBTMP) || mkdir $(ARDUINOLIBTMP)
343
$(COMPILE.c) -o $@ $<
345
$(ARDUINOLIBTMP)/%.o: $(ARDUINODIR)/libraries/*/%.cpp
346
@test -d $(ARDUINOLIBTMP) || mkdir $(ARDUINOLIBTMP)
347
$(COMPILE.cpp) -o $@ $<
349
$(ARDUINOLIBTMP)/%.o: $(ARDUINODIR)/libraries/*/utility/%.c
350
@test -d $(ARDUINOLIBTMP) || mkdir $(ARDUINOLIBTMP)
351
$(COMPILE.c) -o $@ $<
353
$(ARDUINOLIBTMP)/%.o: $(ARDUINODIR)/libraries/*/utility/%.cpp
354
@test -d $(ARDUINOLIBTMP) || mkdir $(ARDUINOLIBTMP)
338
$(COMPILE.c) -o $@ $<
342
$(COMPILE.cpp) -o $@ $<
346
$(COMPILE.cpp) -o $@ $<
355
350
$(COMPILE.cpp) -o $@ $<