/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: 2013-01-02 19:55:16 UTC
  • Revision ID: tim@ed.am-20130102195516-0dn4obb92007gqth
added support for burning bootloaders

Show diffs side-by-side

added added

removed removed

144
144
# monitor      Start `screen` on the serial device.  This is meant to be an
145
145
#              equivalent to the Arduino serial monitor.
146
146
#
147
 
# size         Displays size information about the built target.
 
147
# size         Displays size information about the bulit target.
148
148
#
149
149
# bootloader   Burns the bootloader for your board to it.
150
150
#
155
155
 
156
156
# default arduino software directory, check software exists
157
157
ifndef ARDUINODIR
158
 
ARDUINODIR := $(firstword $(wildcard ~/opt/arduino /usr/share/arduino \
159
 
        /Applications/Arduino.app/Contents/Resources/Java \
160
 
        $(HOME)/Applications/Arduino.app/Contents/Resources/Java))
 
158
ARDUINODIR := $(firstword $(wildcard ~/opt/arduino /usr/share/arduino))
161
159
endif
162
160
ifeq "$(wildcard $(ARDUINODIR)/hardware/arduino/boards.txt)" ""
163
161
$(error ARDUINODIR is not set correctly; arduino software not found)
209
207
BOARD_BOOTLOADER_FILE := $(call readboardsparam,bootloader.file)
210
208
 
211
209
# obtain preferences from the IDE's preferences.txt
212
 
PREFERENCESFILE := $(firstword $(wildcard \
213
 
        $(HOME)/.arduino/preferences.txt $(HOME)/Library/Arduino/preferences.txt))
 
210
PREFERENCESFILE := $(wildcard $(HOME)/.arduino/preferences.txt)
214
211
ifneq "$(PREFERENCESFILE)" ""
215
212
readpreferencesparam = $(shell sed -ne "s/$(1)=\(.*\)/\1/p" $(PREFERENCESFILE))
216
213
SKETCHBOOKDIR := $(call readpreferencesparam,sketchbook.path)
260
257
LIBRARYDIRS := $(foreach lib, $(LIBRARIES), \
261
258
        $(firstword $(wildcard $(addsuffix /$(lib), $(LIBRARYPATH)))))
262
259
LIBRARYDIRS += $(addsuffix /utility, $(LIBRARYDIRS))
 
260
BOOTLOADERDIR := \
 
261
        $(ARDUINODIR)/hardware/arduino/bootloaders/$(BOARD_BOOTLOADER_PATH)
263
262
 
264
263
# files
265
264
TARGET := $(if $(TARGET),$(TARGET),a.out)
268
267
ARDUINOLIB := .lib/arduino.a
269
268
ARDUINOLIBOBJS := $(foreach dir, $(ARDUINOCOREDIR) $(LIBRARYDIRS), \
270
269
        $(patsubst %, .lib/%.o, $(wildcard $(addprefix $(dir)/, *.c *.cpp))))
271
 
BOOTLOADERHEX := $(addprefix \
272
 
        $(ARDUINODIR)/hardware/arduino/bootloaders/$(BOARD_BOOTLOADER_PATH)/, \
273
 
        $(BOARD_BOOTLOADER_FILE))
 
270
BOOTLOADERHEX := $(wildcard $(BOOTLOADERDIR)/$(BOARD_BOOTLOADER_FILE))
274
271
 
275
272
# avrdude confifuration
276
273
ifeq "$(AVRDUDECONF)" ""
361
358
 
362
359
bootloader:
363
360
        @echo "Burning bootloader to board..."
 
361
        @test -n "$(BOOTLOADERHEX)" || { \
 
362
                echo "error: bootloader file could not be determined." >&2; \
 
363
                exit 1; }
364
364
        @test -n "$(SERIALDEV)" || { \
365
365
                echo "error: SERIALDEV could not be determined automatically." >&2; \
366
366
                exit 1; }
369
369
                echo; }
370
370
        stty $(STTYFARG) $(SERIALDEV) hupcl
371
371
        $(AVRDUDE) $(AVRDUDEFLAGS) -U lock:w:$(BOARD_BOOTLOADER_UNLOCK):m
372
 
        $(AVRDUDE) $(AVRDUDEFLAGS) -eU lfuse:w:$(BOARD_BOOTLOADER_LFUSES):m
373
 
        $(AVRDUDE) $(AVRDUDEFLAGS) -U hfuse:w:$(BOARD_BOOTLOADER_HFUSES):m
374
 
ifneq "$(BOARD_BOOTLOADER_EFUSES)" ""
375
 
        $(AVRDUDE) $(AVRDUDEFLAGS) -U efuse:w:$(BOARD_BOOTLOADER_EFUSES):m
376
 
endif
377
 
ifneq "$(BOOTLOADERHEX)" ""
 
372
        $(AVRDUDE) $(AVRDUDEFLAGS) -e -U lfuse:w:$(BOARD_BOOTLOADER_LFUSES):m \
 
373
                -U hfuse:w:$(BOARD_BOOTLOADER_HFUSES):m \
 
374
                $(patsubst %, -U efuse:w:%:m, $(BOARD_BOOTLOADER_EFUSES))
378
375
        $(AVRDUDE) $(AVRDUDEFLAGS) -U flash:w:$(BOOTLOADERHEX):i
379
 
endif
380
376
        $(AVRDUDE) $(AVRDUDEFLAGS) -U lock:w:$(BOARD_BOOTLOADER_LOCK):m
381
377
 
382
378
# building the target
433
429
.lib/%.C.o: %.C
434
430
        mkdir -p $(dir $@)
435
431
        $(COMPILE.cpp) -o $@ $<
436
 
 
437
 
# Local Variables:
438
 
# mode: makefile
439
 
# tab-width: 4
440
 
# End: