blob: 155397cefc5da795a491becbf642159d67ff8075 (
plain)
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
|
CC = avr-gcc
OBJCOPY = avr-objcopy
OBJDUMP = avr-objdump
SIZE = avr-size
NM = avr-nm
AVRDUDE = avrdude
RM = rm -f
COPY = cp
# Define all object files.
OBJ = $(SRC:.c=.o) $(ASRC:.S=.o)
# Compiler flags to generate dependency files.
GENDEPFLAGS = -MMD -MP -MF .dep/$(@F:%.o=%.d)
# Combine all necessary flags and optional flags.
# Add target processor to flags.
ALL_CFLAGS = -mmcu=$(MCU) $(CFLAGS) $(GENDEPFLAGS)
AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex
AVRDUDE_BASIC = -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER)
AVRDUDE_FLAGS = $(AVRDUDE_BASIC) $(AVRDUDE_NO_VERIFY) $(AVRDUDE_VERBOSE)
# Be silent per default, but 'make V=1' will show all compiler calls.
ifneq ($(V),1)
Q := @
NULL := 2>/dev/null
else
QP := \#
endif
.PHONY: elf hex lss sym size
elf: $(TARGET).elf
hex: $(TARGET).hex
lss: $(TARGET).lss
sym: $(TARGET).sym
size: $(TARGET).elf
@$(QP)printf " SIZE $(TARGET).elf\n"
$(Q)$(SIZE) $(TARGET).elf
# Program the device.
.PHONY: flash fuses
flash: $(TARGET).hex
$(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH)
fuses:
$(AVRDUDE) $(AVRDUDE_FLAGS) -u -U hfuse:w:$(HFUSE):m -U lfuse:w:$(LFUSE):m
.SUFFIXES: .elf .hex .eep .lss .sym
%.hex: %.elf
@$(QP)printf " OBJCOPY $(*).hex\n"
$(Q)$(OBJCOPY) -Oihex -R .eeprom $< $@
# Create extended listing file from ELF output file.
%.lss: %.elf
@$(QP)printf " OBJDUMP $@\n"
$(Q)$(OBJDUMP) -h -S $< > $@
# Create a symbol table from ELF output file.
%.sym: %.elf
@$(QP)printf " NM $@\n"
$(Q)$(NM) -n $< > $@
# Link: create ELF output file from object files.
.SECONDARY : $(TARGET).elf
.PRECIOUS : $(OBJ)
%.elf %.map: $(OBJ)
@$(QP)printf " LD $@\n"
$(Q)$(CC) $(ALL_CFLAGS) $^ --output $@ $(LDFLAGS)
# Compile: create object files from C source files.
%.o: %.c
@$(QP)printf " CC $<\n"
$(Q)$(CC) -c $(ALL_CFLAGS) $< -o $@
# Target: clean project.
.PHONY: clean distclean
clean:
@$(QP)printf " CLEAN\n"
$(Q)$(RM) $(TARGET).elf $(TARGET).lss $(TARGET).map $(TARGET).sym \
$(OBJ) $(SRC:.c=.s) .dep/*
distclean: clean
@$(QP)printf " DISTCLEAN\n"
$(Q)$(RM) $(TARGET).hex $(TARGET).tar.gz
.PHONY: dist
dist: build
tar cvfz $(TARGET).tar.gz \
$(SRC) \
$(TARGET).hex $(TARGET).eep
# Include the dependency files.
-include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*)
|