]> cloudbase.mooo.com Git - z180-stamp.git/blob - mk/avr.rules.mk
155397cefc5da795a491becbf642159d67ff8075
[z180-stamp.git] / mk / avr.rules.mk
1
2
3 CC = avr-gcc
4 OBJCOPY = avr-objcopy
5 OBJDUMP = avr-objdump
6 SIZE = avr-size
7 NM = avr-nm
8 AVRDUDE = avrdude
9 RM = rm -f
10 COPY = cp
11
12 # Define all object files.
13 OBJ = $(SRC:.c=.o) $(ASRC:.S=.o)
14
15
16 # Compiler flags to generate dependency files.
17 GENDEPFLAGS = -MMD -MP -MF .dep/$(@F:%.o=%.d)
18
19
20 # Combine all necessary flags and optional flags.
21 # Add target processor to flags.
22 ALL_CFLAGS = -mmcu=$(MCU) $(CFLAGS) $(GENDEPFLAGS)
23
24 AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex
25 AVRDUDE_BASIC = -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER)
26 AVRDUDE_FLAGS = $(AVRDUDE_BASIC) $(AVRDUDE_NO_VERIFY) $(AVRDUDE_VERBOSE)
27
28 # Be silent per default, but 'make V=1' will show all compiler calls.
29 ifneq ($(V),1)
30 Q := @
31 NULL := 2>/dev/null
32 else
33 QP := \#
34 endif
35
36 .PHONY: elf hex lss sym size
37 elf: $(TARGET).elf
38 hex: $(TARGET).hex
39 lss: $(TARGET).lss
40 sym: $(TARGET).sym
41
42 size: $(TARGET).elf
43 @$(QP)printf " SIZE $(TARGET).elf\n"
44 $(Q)$(SIZE) $(TARGET).elf
45
46 # Program the device.
47 .PHONY: flash fuses
48 flash: $(TARGET).hex
49 $(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH)
50
51 fuses:
52 $(AVRDUDE) $(AVRDUDE_FLAGS) -u -U hfuse:w:$(HFUSE):m -U lfuse:w:$(LFUSE):m
53
54
55 .SUFFIXES: .elf .hex .eep .lss .sym
56
57 %.hex: %.elf
58 @$(QP)printf " OBJCOPY $(*).hex\n"
59 $(Q)$(OBJCOPY) -Oihex -R .eeprom $< $@
60
61
62 # Create extended listing file from ELF output file.
63 %.lss: %.elf
64 @$(QP)printf " OBJDUMP $@\n"
65 $(Q)$(OBJDUMP) -h -S $< > $@
66
67 # Create a symbol table from ELF output file.
68 %.sym: %.elf
69 @$(QP)printf " NM $@\n"
70 $(Q)$(NM) -n $< > $@
71
72
73
74 # Link: create ELF output file from object files.
75 .SECONDARY : $(TARGET).elf
76 .PRECIOUS : $(OBJ)
77 %.elf %.map: $(OBJ)
78 @$(QP)printf " LD $@\n"
79 $(Q)$(CC) $(ALL_CFLAGS) $^ --output $@ $(LDFLAGS)
80
81
82 # Compile: create object files from C source files.
83 %.o: %.c
84 @$(QP)printf " CC $<\n"
85 $(Q)$(CC) -c $(ALL_CFLAGS) $< -o $@
86
87
88 # Target: clean project.
89 .PHONY: clean distclean
90 clean:
91 @$(QP)printf " CLEAN\n"
92 $(Q)$(RM) $(TARGET).elf $(TARGET).lss $(TARGET).map $(TARGET).sym \
93 $(OBJ) $(SRC:.c=.s) .dep/*
94
95 distclean: clean
96 @$(QP)printf " DISTCLEAN\n"
97 $(Q)$(RM) $(TARGET).hex $(TARGET).tar.gz
98
99 .PHONY: dist
100 dist: build
101 tar cvfz $(TARGET).tar.gz \
102 $(SRC) \
103 $(TARGET).hex $(TARGET).eep
104
105 # Include the dependency files.
106 -include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*)