-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
93 lines (70 loc) · 2.27 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
###############################################################################
# Makefile for the project DeDeadZone
###############################################################################
## General Flags
PROJECT = DeDeadZone
MCU = atmega8
F_CPU = 8000000
TARGET = $(PROJECT).elf
CC = avr-gcc
AVRDUDE = avrdude -p $(MCU)
## Options common to compile, link and assembly rules
COMMON = -mmcu=$(MCU)
## Compile options common for all C compilation units.
CFLAGS = $(COMMON)
CFLAGS += -Wall -gdwarf-2 -std=gnu99 -DF_CPU=$(F_CPU)UL -Os -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums
CFLAGS += -MD -MP -MT $(*F).o -MF dep/$(@F).d
## Assembly specific flags
ASMFLAGS = $(COMMON)
ASMFLAGS += $(CFLAGS)
ASMFLAGS += -x assembler-with-cpp -Wa,-gdwarf2
## Linker flags
LDFLAGS = $(COMMON)
LDFLAGS += -Wl,-Map=$(PROJECT).map
## Intel Hex file production flags
HEX_FLASH_FLAGS = -R .eeprom -R .fuse -R .lock -R .signature
HEX_EEPROM_FLAGS = -j .eeprom
HEX_EEPROM_FLAGS += --set-section-flags=.eeprom="alloc,load"
HEX_EEPROM_FLAGS += --change-section-lma .eeprom=0 --no-change-warnings
COMPILE = $(CC) $(INCLUDES) $(CFLAGS)
OBJECTS = main.o
## Build
all: $(TARGET) $(PROJECT).elf $(PROJECT).hex size
## Compile
.c.o:
$(COMPILE) -c $< -o $@
.S.o:
$(COMPILE) -x assembler-with-cpp -c $< -o $@
##Link
$(TARGET): $(OBJECTS)
$(CC) $(LDFLAGS) $(OBJECTS) $(LINKONLYOBJECTS) $(LIBDIRS) $(LIBS) -o $(TARGET)
%.hex: $(TARGET)
avr-objcopy -O ihex $(HEX_FLASH_FLAGS) $< $@
%.eep: $(TARGET)
-avr-objcopy $(HEX_EEPROM_FLAGS) -O ihex $< $@ || exit 0
%.lss: $(TARGET)
avr-objdump -h -S $< > $@
size: ${TARGET}
@echo
@avr-size -C --mcu=${MCU} ${TARGET}
## Clean target
.PHONY: clean
clean:
-rm -rf $(OBJECTS) $(PROJECT).elf dep $(PROJECT).hex $(PROJECT).eep $(PROJECT).lss $(PROJECT).map
flash: all
$(AVRDUDE) -U flash:w:$(PROJECT).hex:i
fuses:
ifeq ($(MCU),atmega168)
$(AVRDUDE) -U lfuse:w:0xc2:m -U hfuse:w:0xd4:m -U efuse:w:0xf9:m
endif
ifeq ($(MCU),atmega8)
$(AVRDUDE) -U lfuse:w:0x04:m -U hfuse:w:0xd1:m
endif
ifeq ($(MCU),atmega48)
$(AVRDUDE) -U lfuse:w:0xc2:m -U hfuse:w:0xd5:m -U efuse:w:0xff:m
endif
ifeq ($(MCU),atmega328)
$(AVRDUDE) -U lfuse:w:0xc2:m -U hfuse:w:0xd5:m -U efuse:w:0xff:m
endif
## Other dependencies
-include $(shell mkdir dep 2>/dev/null) $(wildcard dep/*)