149cf5c14b270a514e5411e0e7a27e8a295d4fb9
[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 # -----------------------------------------------------------------------------
17 # DMBS AVRDUDE Programmer Buildsystem Makefile Module.
18 # -----------------------------------------------------------------------------
19 # DESCRIPTION:
20 # Provides a set of targets to re-program a device using the open source
21 # avr-dude utility.
22 # -----------------------------------------------------------------------------
23 # TARGETS:
24 #
25 # avrdude - Program target FLASH with application using
26 # avrdude
27 # avrdude-ee - Program target EEPROM with application data
28 # using avrdude
29 #
30 # MANDATORY PARAMETERS:
31 #
32 # MCU - Microcontroller device model name
33 # TARGET - Application name
34 #
35 # OPTIONAL PARAMETERS:
36 #
37 # AVRDUDE_PROGRAMMER - Name of programming hardware to use
38 # AVRDUDE_PORT - Name of communication port to use
39 # AVRDUDE_FLAGS - Flags to pass to avr-dude
40 # AVRDUDE_MEMORY - Memory space to program application into (e.g.
41 # "application" for an XMEGA DFU device)
42 #
43 # PROVIDED VARIABLES:
44 #
45 # (None)
46 #
47 # PROVIDED MACROS:
48 #
49 # (None)
50 #
51 # -----------------------------------------------------------------------------
52
53 SHELL = /bin/sh
54
55 ERROR_IF_UNSET ?= $(if $(filter undefined, $(origin $(strip $(1)))), $(error Makefile $(strip $(1)) value not set))
56 ERROR_IF_EMPTY ?= $(if $(strip $($(strip $(1)))), , $(error Makefile $(strip $(1)) option cannot be blank))
57 ERROR_IF_NONBOOL ?= $(if $(filter Y N, $($(strip $(1)))), , $(error Makefile $(strip $(1)) option must be Y or N))
58
59 # Default values of optionally user-supplied variables
60 AVRDUDE_PROGRAMMER ?= jtagicemkii
61 AVRDUDE_PORT ?= usb
62 AVRDUDE_FLAGS ?=
63 AVRDUDE_MEMORY ?= flash
64
65 # Sanity check user supplied values
66 $(foreach MANDATORY_VAR, $(DMBS_BUILD_MANDATORY_VARS), $(call ERROR_IF_UNSET, $(MANDATORY_VAR)))
67 $(call ERROR_IF_EMPTY, MCU)
68 $(call ERROR_IF_EMPTY, TARGET)
69 $(call ERROR_IF_EMPTY, AVRDUDE_PROGRAMMER)
70 $(call ERROR_IF_EMPTY, AVRDUDE_PORT)
71
72 # Output Messages
73 MSG_AVRDUDE_CMD := ' [AVRDUDE] :'
74
75 # Construct base avrdude command flags
76 BASE_AVRDUDE_FLAGS := -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER)
77
78 # Programs in the target FLASH memory using AVRDUDE
79 avrdude: $(TARGET).hex $(MAKEFILE_LIST)
80 @echo $(MSG_AVRDUDE_CMD) Programming device \"$(MCU)\" FLASH using \"$(AVRDUDE_PROGRAMMER)\" on port \"$(AVRDUDE_PORT)\"
81 avrdude $(BASE_AVRDUDE_FLAGS) -U $(AVRDUDE_MEMORY):w:$< $(AVRDUDE_FLAGS)
82
83 # Programs in the target EEPROM memory using AVRDUDE
84 avrdude-ee: $(TARGET).eep $(MAKEFILE_LIST)
85 @echo $(MSG_AVRDUDE_CMD) Programming device \"$(MCU)\" EEPROM using \"$(AVRDUDE_PROGRAMMER)\" on port \"$(AVRDUDE_PORT)\"
86 avrdude $(BASE_AVRDUDE_FLAGS) -U eeprom:w:$< $(AVRDUDE_FLAGS)
87
88 # Phony build targets for this module
89 .PHONY: $(DMBS_BUILD_TARGETS)