/make/arduino-mk

To get this branch, use:
bzr branch http://bzr.ed.am/make/arduino-mk

« back to all changes in this revision

Viewing changes to arduino.mk

  • Committer: edam
  • Date: 2012-11-28 21:52:52 UTC
  • Revision ID: tim@ed.am-20121128215252-5ml7w5vtfljskurt
added support for third party libraries and fixed support for .C c++ files

Show diffs side-by-side

added added

removed removed

156
156
AVRTOOLSPATH += $(ARDUINODIR)/hardware/tools/avr/bin
157
157
endif
158
158
 
 
159
# default path to find libraries
 
160
LIBRARIESPATH := libraries libs $(ARDUINODIR)/libraries
 
161
 
159
162
# auto mode?
160
163
INOFILE := $(wildcard *.ino *.pde)
161
164
ifdef INOFILE
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))
172
175
 
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)))
176
179
 
177
180
endif
198
201
TARGET := $(if $(TARGET),$(TARGET),a.out)
199
202
OBJECTS := $(addsuffix .o, $(basename $(SOURCES)))
200
203
DEPFILES := $(patsubst %, .dep/%.dep, $(SOURCES))
 
204
 
 
205
# directories
 
206
LIBRARIESDIRS := $(foreach lib, $(LIBRARIES), \
 
207
        $(firstword $(wildcard $(addsuffix /$(lib), $(LIBRARIESPATH)))))
 
208
LIBRARIESDIRS += $(addsuffix /utility, $(LIBRARIESDIRS))
201
209
ARDUINOCOREDIR := $(ARDUINODIR)/hardware/arduino/cores/arduino
 
210
 
 
211
# static arduino lib
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))))
 
215
 
 
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
256
265
CPPFLAGS += -DUSB_VID=$(BOARD_USB_VID) -DUSB_PID=$(BOARD_USB_PID)
257
266
CPPFLAGS += -I. -Iutil -Iutility -I $(ARDUINOCOREDIR)
258
267
CPPFLAGS += -I $(ARDUINODIR)/hardware/arduino/variants/$(BOARD_BUILD_VARIANT)/
259
 
CPPFLAGS += $(addprefix -I $(ARDUINODIR)/libraries/, $(LIBRARIES))
260
 
CPPFLAGS += $(patsubst %, -I $(ARDUINODIR)/libraries/%/utility, $(LIBRARIES))
 
268
CPPFLAGS += $(addprefix -I , $(LIBRARIESDIRS))
261
269
CPPDEPFLAGS = -MMD -MP -MF .dep/$<.dep
262
270
CPPINOFLAGS := -x c++ -include $(ARDUINOCOREDIR)/Arduino.h
263
271
AVRDUDEFLAGS += $(addprefix -C , $(AVRDUDECONF)) -DV
355
363
 
356
364
%.o: %.pde
357
365
        mkdir -p .dep/$(dir $<)
358
 
        $(COMPILE.cpp) $(CPPDEPFLAGS) -o $@ -x c++ -include $(ARDUINOCOREDIR)/Arduino.h $<
 
366
        $(COMPILE.cpp) $(CPPDEPFLAGS) -o $@ $(CPPINOFLAGS) $<
359
367
 
360
368
# building the arduino library
361
369