-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
101 lines (79 loc) · 2.46 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
93
94
95
96
97
98
99
100
101
# Default values
OBJ = hw.o laborlicht.o main.o
OUT ?= image
MCU_TARGET ?= atmega8
MCU_CC ?= avr-gcc
OPTIMIZE ?= -Os
WARNINGS ?= -Wall
DEFS ?= -DF_CPU=16000000
CFLAGS += -MMD -g -std=c99 -mmcu=$(MCU_TARGET) $(OPTIMIZE) $(WARNINGS) $(DEFS)
ASFLAGS ?= -g $(DEFS)
LDFLAGS ?= -Wl,-Map,$(OUT).map
PROG ?= usbasp
PROG_DEV ?= # e.g. "/dev/ttyUSB0"
PROG_BAUD ?= # e.g. "19200"
# External Tools
OBJCOPY ?= avr-objcopy
OBJDUMP ?= avr-objdump
FLASHCMD ?= avrdude -c $(PROG) \
-p $(MCU_TARGET) \
$(if $(PROG_DEV),-P $(PROG_DEV)) \
$(if $(PROG_BAUD),-b $(PROG_BAUD)) \
-U flash:w:$(OUT).hex:i
LFUSE ?= 0x3f # on ATMega88: F7
HFUSE ?= 0xc3 # on ATMega88: D4
EFUSE ?= # on ATMega88: F9
FUSECMD ?= echo avrdude -c $(PROG) \
-p $(MCU_TARGET) -B 100 \
$(if $(PROG_DEV),-P $(PROG_DEV)) \
$(if $(PROG_BAUD),-b $(PROG_BAUD)) \
-U lfuse:w:$(strip $(LFUSE)):m \
-U hfuse:w:$(strip $(HFUSE)):m \
$(if $(EFUSE),-U efuse:w:$(strip $(EFUSE)):m)
#############################################################################
# Rules
all: $(OUT).elf lst text eeprom
clean:
rm -rf $(OUT) *.o *.d *.lst *.map $(OUT).hex $(OUT)_eeprom.hex *.bin *.srec
rm -rf *.srec $(OUT).elf
fuse:
$(FUSECMD)
flash: $(OUT).hex
$(FLASHCMD)
#############################################################################
# Building Rules
$(OUT).elf: $(OBJ)
$(MCU_CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LIBS)
%.o: %.c
$(MCU_CC) $(CFLAGS) -c $<
%.o: %.S
$(MCU_CC) -mmcu=$(MCU_TARGET) $(ASFLAGS) -c $<
lst: $(OUT).lst
%.lst: %.elf
$(OBJDUMP) -h -S $< > $@
# Rules for building the .text rom images
text: hex bin srec
hex: $(OUT).hex
bin: $(OUT).bin
srec: $(OUT).srec
%.hex: %.elf
$(OBJCOPY) -j .text -j .data -O ihex $< $@
%.srec: %.elf
$(OBJCOPY) -j .text -j .data -O srec $< $@
%.bin: %.elf
$(OBJCOPY) -j .text -j .data -O binary $< $@
# Rules for building the .eeprom rom images
eeprom: ehex ebin esrec
ehex: $(OUT)_eeprom.hex
ebin: $(OUT)_eeprom.bin
esrec: $(OUT)_eeprom.srec
%_eeprom.hex: %.elf
$(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O ihex $< $@
%_eeprom.srec: %.elf
$(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O srec $< $@
%_eeprom.bin: %.elf
$(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O binary $< $@
DEPS := $(wildcard *.d)
ifneq ($(DEPS),)
include $(DEPS)
endif