171
171
$(wildcard $(addprefix utility/, *.c *.cc *.cpp))
173
173
# automatically determine included libraries
174
ARDUINOLIBSAVAIL := $(notdir $(wildcard $(ARDUINODIR)/libraries/*))
175
LIBRARIES := $(filter $(ARDUINOLIBSAVAIL), \
174
LIBRARIES := $(filter $(notdir $(wildcard $(ARDUINODIR)/libraries/*)), \
176
175
$(shell sed -ne "s/^ *\# *include *[<\"]\(.*\)\.h[>\"]/\1/p" $(SOURCES)))
199
198
TARGET := $(if $(TARGET),$(TARGET),a.out)
200
199
OBJECTS := $(addsuffix .o, $(basename $(SOURCES)))
201
ARDUINOSRCDIR := $(ARDUINODIR)/hardware/arduino/cores/arduino
202
ARDUINOLIBSDIR := $(ARDUINODIR)/libraries
203
ARDUINOLIB := _arduino.a
204
ARDUINOLIBTMP := $(ARDUINOLIB).tmp
205
ARDUINOLIBOBJS := $(patsubst %, $(ARDUINOLIBTMP)/%.o, $(basename $(notdir \
206
$(wildcard $(addprefix $(ARDUINOSRCDIR)/, *.c *.cpp)))))
207
ARDUINOLIBOBJS += $(foreach lib, $(LIBRARIES), \
208
$(patsubst %, $(ARDUINOLIBTMP)/%.o, $(basename $(notdir \
209
$(wildcard $(addprefix $(ARDUINOLIBSDIR)/$(lib)/, *.c *.cpp)) \
210
$(wildcard $(addprefix $(ARDUINOLIBSDIR)/$(lib)/utility/, *.c *.cpp)) ))))
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))))
211
208
ifeq "$(AVRDUDECONF)" ""
212
209
ifeq "$(AVRDUDE)" "$(ARDUINODIR)/hardware/tools/avr/bin/avrdude"
213
210
AVRDUDECONF := $(ARDUINODIR)/hardware/tools/avr/etc/avrdude.conf
252
249
CPPFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums
253
250
CPPFLAGS += -mmcu=$(BOARD_BUILD_MCU)
254
251
CPPFLAGS += -DF_CPU=$(BOARD_BUILD_FCPU) -DARDUINO=$(ARDUINOCONST)
255
CPPFLAGS += -I. -Iutil -Iutility -I$(ARDUINOSRCDIR)
252
CPPFLAGS += -I. -Iutil -Iutility -I$(ARDUINOCOREDIR)
256
253
CPPFLAGS += -I$(ARDUINODIR)/hardware/arduino/variants/$(BOARD_BUILD_VARIANT)/
257
254
CPPFLAGS += $(addprefix -I$(ARDUINODIR)/libraries/, $(LIBRARIES))
258
255
CPPFLAGS += $(patsubst %, -I$(ARDUINODIR)/libraries/%/utility, $(LIBRARIES))
256
CPPDEPFLAGS = -MMD -MP -MF .dep/$<.dep
257
CPPINOFLAGS := -x c++ -include $(ARDUINOCOREDIR)/Arduino.h
259
258
AVRDUDEFLAGS := $(addprefix -C , $(AVRDUDECONF)) -DV
260
259
AVRDUDEFLAGS += -p $(BOARD_BUILD_MCU) -P $(SERIALDEV)
261
260
AVRDUDEFLAGS += -c $(BOARD_UPLOAD_PROTOCOL) -b $(BOARD_UPLOAD_SPEED)
292
296
rm -f $(TARGET).elf $(TARGET).hex $(ARDUINOLIB) *~
293
rm -rf $(ARDUINOLIBTMP)
296
300
@echo Available values for BOARD:
297
@sed -ne '/^#/d;s/^\(.*\).name=\(.*\)/\1 \2/;T' \
298
-e 's/\(.\{12\}\) *\(.*\)/\1 \2/;p' $(BOARDS_FILE)
301
@sed -nEe '/^#/d; /^[^.]+\.name=/p' $(BOARDS_FILE) | \
302
sed -Ee 's/([^.]+)\.name=(.*)/\1 \2/' \
303
-e 's/(.{12}) *(.*)/\1 \2/'
301
306
@test -n "$(SERIALDEV)" || { \
322
327
$(TARGET).elf: $(ARDUINOLIB) $(OBJECTS)
323
328
$(CC) $(LINKFLAGS) $(OBJECTS) $(ARDUINOLIB) -o $@
331
mkdir -p .dep/$(dir $<)
332
$(COMPILE.c) $(CPPDEPFLAGS) -o $@ $<
335
mkdir -p .dep/$(dir $<)
336
$(COMPILE.cpp) $(CPPDEPFLAGS) -o $@ $<
339
mkdir -p .dep/$(dir $<)
340
$(COMPILE.cpp) $(CPPDEPFLAGS) -o $@ $<
343
mkdir -p .dep/$(dir $<)
344
$(COMPILE.cpp) $(CPPDEPFLAGS) -o $@ $<
326
$(COMPILE.cpp) -o $@ -x c++ -include $(ARDUINOSRCDIR)/Arduino.h $<
347
mkdir -p .dep/$(dir $<)
348
$(COMPILE.cpp) $(CPPDEPFLAGS) -o $@ $(CPPINOFLAGS) $<
329
$(COMPILE.cpp) -o $@ -x c++ -include $(ARDUINOSRCDIR)/Arduino.h $<
351
mkdir -p .dep/$(dir $<)
352
$(COMPILE.cpp) $(CPPDEPFLAGS) -o $@ -x c++ -include $(ARDUINOCOREDIR)/Arduino.h $<
331
354
# building the arduino library
333
356
$(ARDUINOLIB): $(ARDUINOLIBOBJS)
335
rm -rf $(ARDUINOLIBTMP)
337
.INTERMEDIATE: $(ARDUINOLIBOBJS)
339
$(ARDUINOLIBTMP)/%.o: $(ARDUINOSRCDIR)/%.c
340
@test -d $(ARDUINOLIBTMP) || mkdir $(ARDUINOLIBTMP)
341
$(COMPILE.c) -o $@ $<
343
$(ARDUINOLIBTMP)/%.o: $(ARDUINOSRCDIR)/%.cpp
344
@test -d $(ARDUINOLIBTMP) || mkdir $(ARDUINOLIBTMP)
345
$(COMPILE.cpp) -o $@ $<
347
$(ARDUINOLIBTMP)/%.o: $(ARDUINODIR)/libraries/*/%.c
348
@test -d $(ARDUINOLIBTMP) || mkdir $(ARDUINOLIBTMP)
349
$(COMPILE.c) -o $@ $<
351
$(ARDUINOLIBTMP)/%.o: $(ARDUINODIR)/libraries/*/%.cpp
352
@test -d $(ARDUINOLIBTMP) || mkdir $(ARDUINOLIBTMP)
353
$(COMPILE.cpp) -o $@ $<
355
$(ARDUINOLIBTMP)/%.o: $(ARDUINODIR)/libraries/*/utility/%.c
356
@test -d $(ARDUINOLIBTMP) || mkdir $(ARDUINOLIBTMP)
357
$(COMPILE.c) -o $@ $<
359
$(ARDUINOLIBTMP)/%.o: $(ARDUINODIR)/libraries/*/utility/%.cpp
360
@test -d $(ARDUINOLIBTMP) || mkdir $(ARDUINOLIBTMP)
361
$(COMPILE.c) -o $@ $<
365
$(COMPILE.cpp) -o $@ $<
369
$(COMPILE.cpp) -o $@ $<
361
373
$(COMPILE.cpp) -o $@ $<