6dba68de451a016df70de06f0fc17d9d5a6a1398
[pub/USBasp.git] / LUFA / Build / DMBS / DMBS / avrdude.mk
1 #
2 # DMBS Build System
3 # Released into the public domain.
4 #
5 # dean [at] fourwalledcubicle [dot] com
6 # www.fourwalledcubicle.com
7 #
8
9 DMBS_BUILD_MODULES += AVRDUDE
10 DMBS_BUILD_TARGETS += avrdude avrdude-ee
11 DMBS_BUILD_MANDATORY_VARS += MCU TARGET
12 DMBS_BUILD_OPTIONAL_VARS += AVRDUDE_PROGRAMMER AVRDUDE_PORT AVRDUDE_FLAGS AVRDUDE_MEMORY
13 DMBS_BUILD_PROVIDED_VARS +=
14 DMBS_BUILD_PROVIDED_MACROS +=
15
16 SHELL = /bin/sh
17
18 ERROR_IF_UNSET ?= $(if $(filter undefined, $(origin $(strip $(1)))), $(error Makefile $(strip $(1)) value not set))
19 ERROR_IF_EMPTY ?= $(if $(strip $($(strip $(1)))), , $(error Makefile $(strip $(1)) option cannot be blank))
20 ERROR_IF_NONBOOL ?= $(if $(filter Y N, $($(strip $(1)))), , $(error Makefile $(strip $(1)) option must be Y or N))
21
22 # Default values of optionally user-supplied variables
23 AVRDUDE_PROGRAMMER ?= jtagicemkii
24 AVRDUDE_PORT ?= usb
25 AVRDUDE_FLAGS ?=
26 AVRDUDE_MEMORY ?= flash
27
28 # Sanity check user supplied values
29 $(foreach MANDATORY_VAR, $(DMBS_BUILD_MANDATORY_VARS), $(call ERROR_IF_UNSET, $(MANDATORY_VAR)))
30 $(call ERROR_IF_EMPTY, MCU)
31 $(call ERROR_IF_EMPTY, TARGET)
32 $(call ERROR_IF_EMPTY, AVRDUDE_PROGRAMMER)
33 $(call ERROR_IF_EMPTY, AVRDUDE_PORT)
34
35 # Output Messages
36 MSG_AVRDUDE_CMD := ' [AVRDUDE] :'
37
38 # Construct base avrdude command flags
39 BASE_AVRDUDE_FLAGS := -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER)
40
41 # Programs in the target FLASH memory using AVRDUDE
42 avrdude: $(TARGET).hex $(MAKEFILE_LIST)
43 @echo $(MSG_AVRDUDE_CMD) Programming device \"$(MCU)\" FLASH using \"$(AVRDUDE_PROGRAMMER)\" on port \"$(AVRDUDE_PORT)\"
44 avrdude $(BASE_AVRDUDE_FLAGS) -U $(AVRDUDE_MEMORY):w:$< $(AVRDUDE_FLAGS)
45
46 # Programs in the target EEPROM memory using AVRDUDE
47 avrdude-ee: $(TARGET).eep $(MAKEFILE_LIST)
48 @echo $(MSG_AVRDUDE_CMD) Programming device \"$(MCU)\" EEPROM using \"$(AVRDUDE_PROGRAMMER)\" on port \"$(AVRDUDE_PORT)\"
49 avrdude $(BASE_AVRDUDE_FLAGS) -U eeprom:w:$< $(AVRDUDE_FLAGS)
50
51 # Phony build targets for this module
52 .PHONY: $(DMBS_BUILD_TARGETS)