/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: Tim Marston
  • Date: 2013-02-25 23:02:43 UTC
  • Revision ID: tim@ed.am-20130225230243-0t4nbq519w556bl4
updated NEWS and THANKS

Show diffs side-by-side

added added

removed removed

2
2
#
3
3
#                         edam's Arduino makefile
4
4
#_______________________________________________________________________________
5
 
#                                                                 version 0.6dev
 
5
#                                                                 version 0.5dev
6
6
#
7
 
# Copyright (C) 2011, 2012, 2013 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
198
198
 
199
199
# obtain board parameters from the arduino boards.txt file
200
200
BOARDSFILE := $(ARDUINODIR)/hardware/arduino/boards.txt
201
 
readboardsparam = $(shell sed -ne "s/^$(BOARD).$(1)=\(.*\)/\1/p" $(BOARDSFILE))
 
201
readboardsparam = $(shell sed -ne "s/$(BOARD).$(1)=\(.*\)/\1/p" $(BOARDSFILE))
202
202
BOARD_BUILD_MCU := $(call readboardsparam,build.mcu)
203
203
BOARD_BUILD_FCPU := $(call readboardsparam,build.f_cpu)
204
204
BOARD_BUILD_VARIANT := $(call readboardsparam,build.variant)
205
 
BOARD_BUILD_CORE := $(call readboardsparam,build.core)
206
205
BOARD_UPLOAD_SPEED := $(call readboardsparam,upload.speed)
207
206
BOARD_UPLOAD_PROTOCOL := $(call readboardsparam,upload.protocol)
208
207
BOARD_USB_VID := $(call readboardsparam,build.vid)
242
241
# automatically determine sources and targeet
243
242
TARGET := $(basename $(INOFILE))
244
243
SOURCES := $(INOFILE) \
245
 
        $(wildcard *.c *.cc *.cpp *.C *.s *.S) \
246
 
        $(wildcard $(addprefix util/, *.c *.cc *.cpp *.C *.s *.S)) \
247
 
        $(wildcard $(addprefix utility/, *.c *.cc *.cpp *.C *.s *.S))
 
244
        $(wildcard *.c *.cc *.cpp *.C) \
 
245
        $(wildcard $(addprefix util/, *.c *.cc *.cpp *.C)) \
 
246
        $(wildcard $(addprefix utility/, *.c *.cc *.cpp *.C))
248
247
 
249
248
# automatically determine included libraries
250
249
LIBRARIES := $(filter $(notdir $(wildcard $(addsuffix /*, $(LIBRARYPATH)))), \
251
 
        $(shell sed -nre "s/^\s*\#\s*include\s*[<\"](\S+)\.h[>\"].*/\1/p" \
252
 
        $(SOURCES)))
 
250
        $(shell sed -ne "s/^ *\# *include *[<\"]\(.*\)\.h[>\"]/\1/p" $(SOURCES)))
253
251
 
254
252
endif
255
253
 
259
257
CXX := $(call findsoftware,avr-g++)
260
258
LD := $(call findsoftware,avr-ld)
261
259
AR := $(call findsoftware,avr-ar)
262
 
AS := $(call findsoftware,avr-as)
263
260
OBJCOPY := $(call findsoftware,avr-objcopy)
264
261
AVRDUDE := $(call findsoftware,avrdude)
265
262
AVRSIZE := $(call findsoftware,avr-size)
266
263
 
267
264
# directories
268
 
ARDUINOCOREDIR := $(ARDUINODIR)/hardware/arduino/cores/$(BOARD_BUILD_CORE)
 
265
ARDUINOCOREDIR := $(ARDUINODIR)/hardware/arduino/cores/arduino
269
266
LIBRARYDIRS := $(foreach lib, $(LIBRARIES), \
270
267
        $(firstword $(wildcard $(addsuffix /$(lib), $(LIBRARYPATH)))))
271
268
LIBRARYDIRS += $(addsuffix /utility, $(LIBRARYDIRS))
276
273
DEPFILES := $(patsubst %, .dep/%.dep, $(SOURCES))
277
274
ARDUINOLIB := .lib/arduino.a
278
275
ARDUINOLIBOBJS := $(foreach dir, $(ARDUINOCOREDIR) $(LIBRARYDIRS), \
279
 
        $(patsubst %, .lib/%.o, $(wildcard $(addprefix $(dir)/, \
280
 
                *.c *.cc *.cpp *.C *.s *.S))))
 
276
        $(patsubst %, .lib/%.o, $(wildcard $(addprefix $(dir)/, *.c *.cpp))))
281
277
BOOTLOADERHEX := $(addprefix \
282
278
        $(ARDUINODIR)/hardware/arduino/bootloaders/$(BOARD_BOOTLOADER_PATH)/, \
283
279
        $(BOARD_BOOTLOADER_FILE))
303
299
CPPDEPFLAGS = -MMD -MP -MF .dep/$<.dep
304
300
CPPINOFLAGS := -x c++ -include $(ARDUINOCOREDIR)/Arduino.h
305
301
AVRDUDEFLAGS += $(addprefix -C , $(AVRDUDECONF)) -DV
306
 
AVRDUDEFLAGS += -p$(BOARD_BUILD_MCU) -P$(SERIALDEV) -c$(BOARD_UPLOAD_PROTOCOL)
307
 
AVRDUDEFLAGS += $(addprefix -b, $(BOARD_UPLOAD_SPEED))
 
302
AVRDUDEFLAGS += -p $(BOARD_BUILD_MCU) -P $(SERIALDEV)
 
303
AVRDUDEFLAGS += -c $(BOARD_UPLOAD_PROTOCOL) -b $(BOARD_UPLOAD_SPEED)
308
304
LINKFLAGS += -Os -Wl,--gc-sections -mmcu=$(BOARD_BUILD_MCU)
309
305
 
310
306
# figure out which arg to use with stty (for OS X, GNU and busybox stty)
339
335
ifeq "$(BOARD_BOOTLOADER_PATH)" "caterina"
340
336
        stty $(STTYFARG) $(SERIALDEV) speed 1200
341
337
        sleep 1
342
 
else
 
338
endif
343
339
        stty $(STTYFARG) $(SERIALDEV) hupcl
344
 
endif
345
340
        $(AVRDUDE) $(AVRDUDEFLAGS) -U flash:w:$(TARGET).hex:i
346
341
 
347
342
clean:
400
395
$(TARGET).elf: $(ARDUINOLIB) $(OBJECTS)
401
396
        $(CC) $(LINKFLAGS) $(OBJECTS) $(ARDUINOLIB) -lm -o $@
402
397
 
403
 
%.o: %.ino
404
 
        mkdir -p .dep/$(dir $<)
405
 
        $(COMPILE.cpp) $(CPPDEPFLAGS) -o $@ $(CPPINOFLAGS) $<
406
 
 
407
 
%.o: %.pde
408
 
        mkdir -p .dep/$(dir $<)
409
 
        $(COMPILE.cpp) $(CPPDEPFLAGS) -o $@ $(CPPINOFLAGS) $<
410
 
 
411
398
%.o: %.c
412
399
        mkdir -p .dep/$(dir $<)
413
400
        $(COMPILE.c) $(CPPDEPFLAGS) -o $@ $<
424
411
        mkdir -p .dep/$(dir $<)
425
412
        $(COMPILE.cpp) $(CPPDEPFLAGS) -o $@ $<
426
413
 
427
 
%.o: %.S
428
 
        mkdir -p .dep/$(dir $<)
429
 
        $(COMPILE.S) $(CPPDEPFLAGS) -o $@ $<
 
414
%.o: %.ino
 
415
        mkdir -p .dep/$(dir $<)
 
416
        $(COMPILE.cpp) $(CPPDEPFLAGS) -o $@ $(CPPINOFLAGS) $<
 
417
 
 
418
%.o: %.pde
 
419
        mkdir -p .dep/$(dir $<)
 
420
        $(COMPILE.cpp) $(CPPDEPFLAGS) -o $@ $(CPPINOFLAGS) $<
430
421
 
431
422
# building the arduino library
432
423
 
449
440
        mkdir -p $(dir $@)
450
441
        $(COMPILE.cpp) -o $@ $<
451
442
 
452
 
.lib/%.s.o: %.s
453
 
        mkdir -p $(dir $@)
454
 
        $(COMPILE.s) -o $@ $<
455
 
 
456
 
.lib/%.S.o: %.S
457
 
        mkdir -p $(dir $@)
458
 
        $(COMPILE.S) -o $@ $<
459
 
 
460
443
# Local Variables:
461
444
# mode: makefile
462
445
# tab-width: 4