5c433d7dbc0cfa3774d41c12a08477ec5674e16b
[pub/USBasp.git] / LUFA / Build / DMBS / DMBS / atprogram.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 += ATPROGRAM
10 DMBS_BUILD_TARGETS += atprogram atprogram-ee
11 DMBS_BUILD_MANDATORY_VARS += MCU TARGET
12 DMBS_BUILD_OPTIONAL_VARS += ATPROGRAM_PROGRAMMER ATPROGRAM_INTERFACE ATPROGRAM_PORT
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 ATPROGRAM_PROGRAMMER ?= atmelice
24 ATPROGRAM_INTERFACE ?= jtag
25 ATPROGRAM_PORT ?=
26
27 # Sanity check user supplied values
28 $(foreach MANDATORY_VAR, $(DMBS_BUILD_MANDATORY_VARS), $(call ERROR_IF_UNSET, $(MANDATORY_VAR)))
29 $(call ERROR_IF_EMPTY, MCU)
30 $(call ERROR_IF_EMPTY, TARGET)
31 $(call ERROR_IF_EMPTY, ATPROGRAM_PROGRAMMER)
32 $(call ERROR_IF_EMPTY, ATPROGRAM_INTERFACE)
33
34 # Output Messages
35 MSG_ATPROGRAM_CMD := ' [ATPRGRM] :'
36
37 # Construct base atprogram command flags
38 BASE_ATPROGRAM_FLAGS := --tool $(ATPROGRAM_PROGRAMMER) --interface $(ATPROGRAM_INTERFACE) --device $(MCU)
39 ifneq ($(ATPROGRAM_PORT),)
40 BASE_ATPROGRAM_FLAGS += --port $(ATPROGRAM_PORT)
41 endif
42
43 # Construct the flags to use for the various memory spaces
44 ifeq ($(ARCH), AVR8)
45 ATPROGRAM_FLASH_FLAGS := --chiperase --flash
46 ATPROGRAM_EEPROM_FLAGS := --eeprom
47 else ifeq ($(ARCH), XMEGA)
48 ATPROGRAM_FLASH_FLAGS := --erase --flash
49 ATPROGRAM_EEPROM_FLAGS := --eeprom
50 else ifeq ($(ARCH), UC3)
51 ATPROGRAM_FLASH_FLAGS := --erase
52 ATPROGRAM_EEPROM_FLAGS := --eeprom
53 else
54 $(error Unsupported architecture "$(ARCH)")
55 endif
56
57 # Programs in the target FLASH memory using ATPROGRAM
58 atprogram: $(TARGET).elf $(MAKEFILE_LIST)
59 @echo $(MSG_ATPROGRAM_CMD) Programming device \"$(MCU)\" FLASH using \"$(ATPROGRAM_PROGRAMMER)\"
60 atprogram $(BASE_ATPROGRAM_FLAGS) program $(ATPROGRAM_FLASH_FLAGS) --file $<
61
62 # Programs in the target EEPROM memory using ATPROGRAM
63 atprogram-ee: $(TARGET).elf $(MAKEFILE_LIST)
64 @echo $(MSG_ATPROGRAM_CMD) Programming device \"$(MCU)\" EEPROM using \"$(ATPROGRAM_PROGRAMMER)\"
65 atprogram $(BASE_ATPROGRAM_FLAGS) program $(ATPROGRAM_EEPROM_FLAGS) --file $<
66
67 # Phony build targets for this module
68 .PHONY: $(DMBS_BUILD_TARGETS)