3
3
# edam's Arduino makefile
4
4
#_______________________________________________________________________________
7
# Copyright (C) 2011, 1012 Tim Marston <tim@ed.am>.
7
# Copyright (C) 2011, 2012 Tim Marston <tim@ed.am>.
9
9
# Permission is hereby granted, free of charge, to any person obtaining a copy
10
10
# of this software and associated documentation files (the "Software"), to deal
166
169
# automatically determine sources and targeet
167
170
TARGET := $(basename $(INOFILE))
168
171
SOURCES := $(INOFILE) \
169
$(wildcard *.c *.cc *.cpp) \
170
$(wildcard $(addprefix util/, *.c *.cc *.cpp)) \
171
$(wildcard $(addprefix utility/, *.c *.cc *.cpp))
172
$(wildcard *.c *.cc *.cpp *.C) \
173
$(wildcard $(addprefix util/, *.c *.cc *.cpp *.C)) \
174
$(wildcard $(addprefix utility/, *.c *.cc *.cpp *.C))
173
176
# automatically determine included libraries
174
LIBRARIES := $(filter $(notdir $(wildcard $(ARDUINODIR)/libraries/*)), \
177
LIBRARIES := $(filter $(notdir $(wildcard $(addsuffix /*, $(LIBRARIESPATH)))), \
175
178
$(shell sed -ne "s/^ *\# *include *[<\"]\(.*\)\.h[>\"]/\1/p" $(SOURCES)))
198
201
TARGET := $(if $(TARGET),$(TARGET),a.out)
199
202
OBJECTS := $(addsuffix .o, $(basename $(SOURCES)))
200
203
DEPFILES := $(patsubst %, .dep/%.dep, $(SOURCES))
206
LIBRARIESDIRS := $(foreach lib, $(LIBRARIES), \
207
$(firstword $(wildcard $(addsuffix /$(lib), $(LIBRARIESPATH)))))
208
LIBRARIESDIRS += $(addsuffix /utility, $(LIBRARIESDIRS))
201
209
ARDUINOCOREDIR := $(ARDUINODIR)/hardware/arduino/cores/arduino
202
212
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), \
213
ARDUINOLIBOBJS := $(foreach dir, $(ARDUINOCOREDIR) $(LIBRARIESDIRS), \
207
214
$(patsubst %, .lib/%.o, $(wildcard $(addprefix $(dir)/, *.c *.cpp))))
216
# avrdude confifuration
208
217
ifeq "$(AVRDUDECONF)" ""
209
218
ifeq "$(AVRDUDE)" "$(ARDUINODIR)/hardware/tools/avr/bin/avrdude"
210
219
AVRDUDECONF := $(ARDUINODIR)/hardware/tools/avr/etc/avrdude.conf
234
243
$(shell sed -ne "s/$(BOARD).upload.speed=\(.*\)/\1/p" $(BOARDS_FILE))
235
244
BOARD_UPLOAD_PROTOCOL := \
236
245
$(shell sed -ne "s/$(BOARD).upload.protocol=\(.*\)/\1/p" $(BOARDS_FILE))
247
$(shell sed -ne "s/$(BOARD).build.vid=\(.*\)/\1/p" $(BOARDS_FILE))
249
$(shell sed -ne "s/$(BOARD).build.pid=\(.*\)/\1/p" $(BOARDS_FILE))
239
252
ifeq "$(BOARD_BUILD_MCU)" ""
248
CPPFLAGS := -Os -Wall -fno-exceptions -ffunction-sections -fdata-sections
261
CPPFLAGS += -Os -Wall -fno-exceptions -ffunction-sections -fdata-sections
249
262
CPPFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums
250
263
CPPFLAGS += -mmcu=$(BOARD_BUILD_MCU)
251
264
CPPFLAGS += -DF_CPU=$(BOARD_BUILD_FCPU) -DARDUINO=$(ARDUINOCONST)
252
CPPFLAGS += -I. -Iutil -Iutility -I$(ARDUINOCOREDIR)
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))
265
CPPFLAGS += -DUSB_VID=$(BOARD_USB_VID) -DUSB_PID=$(BOARD_USB_PID)
266
CPPFLAGS += -I. -Iutil -Iutility -I $(ARDUINOCOREDIR)
267
CPPFLAGS += -I $(ARDUINODIR)/hardware/arduino/variants/$(BOARD_BUILD_VARIANT)/
268
CPPFLAGS += $(addprefix -I , $(LIBRARIESDIRS))
256
269
CPPDEPFLAGS = -MMD -MP -MF .dep/$<.dep
257
270
CPPINOFLAGS := -x c++ -include $(ARDUINOCOREDIR)/Arduino.h
258
AVRDUDEFLAGS := $(addprefix -C , $(AVRDUDECONF)) -DV
271
AVRDUDEFLAGS += $(addprefix -C , $(AVRDUDECONF)) -DV
259
272
AVRDUDEFLAGS += -p $(BOARD_BUILD_MCU) -P $(SERIALDEV)
260
273
AVRDUDEFLAGS += -c $(BOARD_UPLOAD_PROTOCOL) -b $(BOARD_UPLOAD_SPEED)
261
LINKFLAGS := -Os -Wl,--gc-sections -mmcu=$(BOARD_BUILD_MCU)
274
LINKFLAGS += -Os -Wl,--gc-sections -mmcu=$(BOARD_BUILD_MCU)
263
# figure out which arg to use with stty
264
STTYFARG := $(shell stty --help > /dev/null 2>&1 && echo -F || echo -f)
276
# figure out which arg to use with stty (for OS X, GNU and busybox stty)
277
STTYFARG := $(shell stty --help 2>&1 | \
278
grep -q 'illegal option' && echo -f || echo -F)
266
280
# include dependencies
267
281
ifneq "$(MAKECMDGOALS)" "clean"
300
314
@echo Available values for BOARD:
301
@sed -ne '/^#/d;s/^\(.*\).name=\(.*\)/\1 \2/;T' \
302
-e 's/\(.\{12\}\) *\(.*\)/\1 \2/;p' $(BOARDS_FILE)
315
@sed -nEe '/^#/d; /^[^.]+\.name=/p' $(BOARDS_FILE) | \
316
sed -Ee 's/([^.]+)\.name=(.*)/\1 \2/' \
317
-e 's/(.{12}) *(.*)/\1 \2/'
305
320
@test -n "$(SERIALDEV)" || { \