/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

2
2
#
3
3
#                         edam's Arduino makefile
4
4
#_______________________________________________________________________________
5
 
#                                                                 version 0.4dev
 
5
#                                                                 version 0.5dev
6
6
#
7
 
# Copyright (C) 2011, 1012 Tim Marston <tim@ed.am>.
 
7
# Copyright (C) 2011, 2012 Tim Marston <tim@ed.am>.
8
8
#
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
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
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))
 
246
BOARD_USB_VID := \
 
247
        $(shell sed -ne "s/$(BOARD).build.vid=\(.*\)/\1/p" $(BOARDS_FILE))
 
248
BOARD_USB_PID := \
 
249
        $(shell sed -ne "s/$(BOARD).build.pid=\(.*\)/\1/p" $(BOARDS_FILE))
237
250
 
238
251
# invalid board?
239
252
ifeq "$(BOARD_BUILD_MCU)" ""
245
258
endif
246
259
 
247
260
# flags
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)
 
265
CPPFLAGS += -DUSB_VID=$(BOARD_USB_VID) -DUSB_PID=$(BOARD_USB_PID)
252
266
CPPFLAGS += -I. -Iutil -Iutility -I $(ARDUINOCOREDIR)
253
267
CPPFLAGS += -I $(ARDUINODIR)/hardware/arduino/variants/$(BOARD_BUILD_VARIANT)/
254
 
CPPFLAGS += $(addprefix -I $(ARDUINODIR)/libraries/, $(LIBRARIES))
255
 
CPPFLAGS += $(patsubst %, -I $(ARDUINODIR)/libraries/%/utility, $(LIBRARIES))
 
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)
262
275
 
263
276
# figure out which arg to use with stty (for OS X, GNU and busybox stty)
264
277
STTYFARG := $(shell stty --help 2>&1 | \
326
339
.INTERMEDIATE: $(TARGET).elf
327
340
 
328
341
$(TARGET).elf: $(ARDUINOLIB) $(OBJECTS)
329
 
        $(CC) $(LINKFLAGS) $(OBJECTS) $(ARDUINOLIB) -o $@ -lm
 
342
        $(CC) $(LINKFLAGS) $(OBJECTS) $(ARDUINOLIB) -lm -o $@
330
343
 
331
344
%.o: %.c
332
345
        mkdir -p .dep/$(dir $<)
350
363
 
351
364
%.o: %.pde
352
365
        mkdir -p .dep/$(dir $<)
353
 
        $(COMPILE.cpp) $(CPPDEPFLAGS) -o $@ -x c++ -include $(ARDUINOCOREDIR)/Arduino.h $<
 
366
        $(COMPILE.cpp) $(CPPDEPFLAGS) -o $@ $(CPPINOFLAGS) $<
354
367
 
355
368
# building the arduino library
356
369