]> cloudbase.mooo.com Git - z180-stamp.git/blame - mk/avr.rules.mk
Remove compiler warnings
[z180-stamp.git] / mk / avr.rules.mk
CommitLineData
8a500c7f
L
1
2
3CC = avr-gcc
4OBJCOPY = avr-objcopy
5OBJDUMP = avr-objdump
6SIZE = avr-size
7NM = avr-nm
8AVRDUDE = avrdude
9RM = rm -f
10COPY = cp
11
12# Define all object files.
13OBJ = $(SRC:.c=.o) $(ASRC:.S=.o)
14
15
16# Compiler flags to generate dependency files.
17GENDEPFLAGS = -MMD -MP -MF .dep/$(@F:%.o=%.d)
18
19
20# Combine all necessary flags and optional flags.
21# Add target processor to flags.
22ALL_CFLAGS = -mmcu=$(MCU) $(CFLAGS) $(GENDEPFLAGS)
23
24AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex
25AVRDUDE_BASIC = -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER)
26AVRDUDE_FLAGS = $(AVRDUDE_BASIC) $(AVRDUDE_NO_VERIFY) $(AVRDUDE_VERBOSE)
27
28# Be silent per default, but 'make V=1' will show all compiler calls.
29ifneq ($(V),1)
30Q := @
31NULL := 2>/dev/null
32else
33QP := \#
34endif
35
36.PHONY: elf hex lss sym size
37elf: $(TARGET).elf
38hex: $(TARGET).hex
39lss: $(TARGET).lss
40sym: $(TARGET).sym
41
42size: $(TARGET).elf
43 @$(QP)printf " SIZE $(TARGET).elf\n"
44 $(Q)$(SIZE) $(TARGET).elf
45
46# Program the device.
47.PHONY: flash fuses
48flash: $(TARGET).hex
49 $(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH)
50
51fuses:
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
90clean:
91 @$(QP)printf " CLEAN\n"
92 $(Q)$(RM) $(TARGET).elf $(TARGET).lss $(TARGET).map $(TARGET).sym \
93 $(OBJ) $(SRC:.c=.s) .dep/*
94
95distclean: clean
96 @$(QP)printf " DISTCLEAN\n"
97 $(Q)$(RM) $(TARGET).hex $(TARGET).tar.gz
98
99.PHONY: dist
100dist: 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/*)