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.
136
134
# <file> Builds the specified file, either an object file or the target,
137
135
# from those that that would be built for the project.
138
136
#_______________________________________________________________________________
171
169
$(wildcard $(addprefix utility/, *.c *.cc *.cpp))
173
171
# automatically determine included libraries
174
LIBRARIES := $(filter $(notdir $(wildcard $(ARDUINODIR)/libraries/*)), \
172
ARDUINOLIBSAVAIL := $(notdir $(wildcard $(ARDUINODIR)/libraries/*))
173
LIBRARIES := $(filter $(ARDUINOLIBSAVAIL), \
175
174
$(shell sed -ne "s/^ *\# *include *[<\"]\(.*\)\.h[>\"]/\1/p" $(SOURCES)))
192
191
AR := $(call findsoftware,avr-ar)
193
192
OBJCOPY := $(call findsoftware,avr-objcopy)
194
193
AVRDUDE := $(call findsoftware,avrdude)
195
AVRSIZE := $(call findsoftware,avr-size)
198
196
TARGET := $(if $(TARGET),$(TARGET),a.out)
199
197
OBJECTS := $(addsuffix .o, $(basename $(SOURCES)))
200
DEPFILES := $(patsubst %, .dep/%.dep, $(SOURCES))
201
ARDUINOCOREDIR := $(ARDUINODIR)/hardware/arduino/cores/arduino
202
ARDUINOLIB := .lib/arduino.a
203
ARDUINOLIBLIBSDIR := $(ARDUINODIR)/libraries
204
ARDUINOLIBLIBSPATH := $(foreach lib, $(LIBRARIES), \
205
$(ARDUINODIR)/libraries/$(lib)/ $(ARDUINODIR)/libraries/$(lib)/utility/ )
206
ARDUINOLIBOBJS := $(foreach dir, $(ARDUINOCOREDIR) $(ARDUINOLIBLIBSPATH), \
207
$(patsubst %, .lib/%.o, $(wildcard $(addprefix $(dir)/, *.c *.cpp))))
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)) ))))
208
208
ifeq "$(AVRDUDECONF)" ""
209
209
ifeq "$(AVRDUDE)" "$(ARDUINODIR)/hardware/tools/avr/bin/avrdude"
210
210
AVRDUDECONF := $(ARDUINODIR)/hardware/tools/avr/etc/avrdude.conf
249
249
CPPFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums
250
250
CPPFLAGS += -mmcu=$(BOARD_BUILD_MCU)
251
251
CPPFLAGS += -DF_CPU=$(BOARD_BUILD_FCPU) -DARDUINO=$(ARDUINOCONST)
252
CPPFLAGS += -I. -Iutil -Iutility -I$(ARDUINOCOREDIR)
252
CPPFLAGS += -I. -Iutil -Iutility -I$(ARDUINOSRCDIR)
253
253
CPPFLAGS += -I$(ARDUINODIR)/hardware/arduino/variants/$(BOARD_BUILD_VARIANT)/
254
254
CPPFLAGS += $(addprefix -I$(ARDUINODIR)/libraries/, $(LIBRARIES))
255
255
CPPFLAGS += $(patsubst %, -I$(ARDUINODIR)/libraries/%/utility, $(LIBRARIES))
256
CPPDEPFLAGS = -MMD -MP -MF .dep/$<.dep
257
CPPINOFLAGS := -x c++ -include $(ARDUINOCOREDIR)/Arduino.h
258
256
AVRDUDEFLAGS := $(addprefix -C , $(AVRDUDECONF)) -DV
259
257
AVRDUDEFLAGS += -p $(BOARD_BUILD_MCU) -P $(SERIALDEV)
260
258
AVRDUDEFLAGS += -c $(BOARD_UPLOAD_PROTOCOL) -b $(BOARD_UPLOAD_SPEED)
263
261
# figure out which arg to use with stty
264
262
STTYFARG := $(shell stty --help > /dev/null 2>&1 && echo -F || echo -f)
266
# include dependencies
267
ifneq "$(MAKECMDGOALS)" "clean"
272
265
.DEFAULT_GOAL := all
274
267
#_______________________________________________________________________________
277
.PHONY: all target upload clean boards monitor size
270
.PHONY: all target upload clean boards monitor
281
274
target: $(TARGET).hex
326
316
$(TARGET).elf: $(ARDUINOLIB) $(OBJECTS)
327
317
$(CC) $(LINKFLAGS) $(OBJECTS) $(ARDUINOLIB) -o $@
330
mkdir -p .dep/$(dir $<)
331
$(COMPILE.c) $(CPPDEPFLAGS) -o $@ $<
334
mkdir -p .dep/$(dir $<)
335
$(COMPILE.cpp) $(CPPDEPFLAGS) -o $@ $<
338
mkdir -p .dep/$(dir $<)
339
$(COMPILE.cpp) $(CPPDEPFLAGS) -o $@ $<
342
mkdir -p .dep/$(dir $<)
343
$(COMPILE.cpp) $(CPPDEPFLAGS) -o $@ $<
346
mkdir -p .dep/$(dir $<)
347
$(COMPILE.cpp) $(CPPDEPFLAGS) -o $@ $(CPPINOFLAGS) $<
320
$(COMPILE.cpp) -o $@ -x c++ -include $(ARDUINOSRCDIR)/Arduino.h $<
350
mkdir -p .dep/$(dir $<)
351
$(COMPILE.cpp) $(CPPDEPFLAGS) -o $@ -x c++ -include $(ARDUINOCOREDIR)/Arduino.h $<
323
$(COMPILE.cpp) -o $@ -x c++ -include $(ARDUINOSRCDIR)/Arduino.h $<
353
325
# building the arduino library
355
327
$(ARDUINOLIB): $(ARDUINOLIBOBJS)
360
$(COMPILE.c) -o $@ $<
364
$(COMPILE.cpp) -o $@ $<
368
$(COMPILE.cpp) -o $@ $<
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)
372
355
$(COMPILE.cpp) -o $@ $<