-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
86 lines (63 loc) · 1.98 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
OBJ = main.o i2csw.o uart.o pll.o
# Default values
OUT ?= image
MCU_TARGET ?= atmega32
MCU_CC ?= avr-gcc
MCU_AS ?= avr-as
OPTIMIZE ?= -Os
WARNINGS ?= -Wall -Winline
DEFS ?= -DF_CPU=16000000
CFLAGS += -mmcu=$(MCU_TARGET) $(OPTIMIZE) $(WARNINGS) $(DEFS) -I.
ASFLAGS += -mmcu=avr5
LDFLAGS = -Wl,-Map,$(OUT).map
# External Tools
OBJCOPY ?= avr-objcopy
OBJDUMP ?= avr-objdump
FLASHCMD ?= avrdude -c usbasp -p $(MCU_TARGET) -U flash:w:image.hex
ERASECMD ?= avrdude -c usbasp -p $(MCU_TARGET) -e
#NAKKAFLASHCMD ?= ../../nakkaloader/host/flasher/project.exe
NAKKAFLASHCMD ?= ../../../src-atmel/rfm12/nakkaloader/host/flasher/nakkaflash
#############################################################################
# Rules
all: $(OUT).elf lst text eeprom
clean:
rm -rf $(OUT) *.o *.lst *.map *.hex *.bin *.srec
rm -rf *.srec $(OUT).elf
flash: $(OUT).hex
$(ERASECMD)
$(FLASHCMD)
funk: $(OUT).hex
$(NAKKAFLASHCMD) $(OUT).bin
#############################################################################
# Building Rules
$(OUT).elf: $(OBJ)
$(MCU_CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LIBS)
%.o: %.c
$(MCU_CC) $(CFLAGS) -c $< -o $@
%.o: %.S
$(MCU_AS) $(ASFLAGS) -o $@ $<
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 $< $@