summaryrefslogtreecommitdiff
path: root/n/avr/utils/Makefile
blob: 89e18f445eaa5f186d5efea379431d7ea5b8db7c (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
PRG = test_utils
OBJECTS = test_utils.o
DOC = utils.html
EXTRACTDOC = utils.h avrconfig.h
# atmega8, atmega8535, atmega128...
MCU_TARGET = atmega8
# -O2 : speed
# -Os : size
OPTIMIZE = -O2

DEFS =
LIBS =

# You should not have to change anything below here.

CC = avr-gcc

CFLAGS = -g -Wall $(OPTIMIZE) -mmcu=$(MCU_TARGET)
CPPFLAGS = $(DEFS)
LDFLAGS = -Wl,-Map,$(PRG).map

OBJCOPY = avr-objcopy
OBJDUMP = avr-objdump

all: elf lst hex

elf: $(PRG).elf
lst:  $(PRG).lst

$(PRG).elf: $(OBJECTS)
	$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LIBS)

%.lst: %.elf
	$(OBJDUMP) -h -S $< > $@

clean:
	rm -f *.o $(PRG).elf *.bak $(DOC) *.exd
	rm -f *.lst *.map $(EXTRA_CLEAN_FILES)
	rm -f $(PRG).hex $(PRG).bin $(PRG).srec $(PRG)_eeprom.hex $(PRG)_eeprom.bin $(PRG)_eeprom.srec

# Rules for building the doc.

doc: $(DOC)

%.html: %.txt %.exd
	aft $<

%.exd: $(EXTRACTDOC)
	test -n "$^" && extractdoc $^ > $@ || true

# Rules for building the .text rom images.

text: hex bin srec

hex: $(PRG).hex
bin: $(PRG).bin
srec: $(PRG).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: $(PRG)_eeprom.hex
ebin: $(PRG)_eeprom.bin
esrec: $(PRG)_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 $< $@