-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
executable file
·72 lines (50 loc) · 1.72 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
PORT ?= /dev/ttyACM0
TARGET=main
LIB=lib
DEVICE = attiny2313a
MCU = attiny2313a
AVRDUDE_DEVICE = attiny2313
PROGRAMMER = linuxspi
#PROGRAMMER = linuxspi2
PORT = /dev/spidev0.0
OBJ=$(TARGET).o
OPT=-Os -flto
CFLAGS=-g -Wall -mcall-prologues -mmcu=$(MCU) $(DEVICE_SPECIFIC_CFLAGS) $(OPT) -std=c99
CC=avr-gcc
LDFLAGS=-Wl,-gc-sections -Wl,-relax -flto
#-lpololu_$(DEVICE)
AVRDUDE=avrdude
#.PRECIOUS: %.elf
all:$(TARGET).hex memory-used
clean:
rm -f *.o *.hex *.obj *.hex *.elf *.i *.s *.eep
##
# Add an explicit target for firmware binaries that will be versioned
#
# regular builds with 'make' will not be tracked, to build a firmware file
# that is tracked by the VCS, run 'make dist'
# to flash this firmware, run 'make program_dist'
##
.PHONY: dist program_dist
dist: dist/$(TARGET).hex dist/$(TARGET).eep
program_dist:# dist/$(TARGET).hex dist/$(TARGET).eep
$(AVRDUDE) -p $(AVRDUDE_DEVICE) -c $(PROGRAMMER) -P $(PORT) -U flash:w:dist/$(TARGET).hex -U eeprom:w:dist/$(TARGET).eep -B 40
dist/%.eep: %.elf
avr-objcopy -j .eeprom --set-section-flags=.eeprom="alloc,load" --change-section-lma .eeprom=0 -O ihex $< $@
dist/%.hex: %.elf
avr-objcopy -O ihex -R .eeprom $< $@
%.eep: %.elf
avr-objcopy -j .eeprom --set-section-flags=.eeprom="alloc,load" --change-section-lma .eeprom=0 -O ihex $< $@
%.hex: %.elf
avr-objcopy -O ihex -R .eeprom $< $@
%.elf: $(OBJ)
avr-gcc $(CFLAGS) $(OBJ) --output $@ $(LDFLAGS)
%.obj: %.o
$(CC) $(CFLAGS) $< $(LDFLAGS) -o $@
#%.o: %.c
#$(CC) $(CFLAGS) $< -o $@
program: $(TARGET).hex $(TARGET).eep
$(AVRDUDE) -p $(AVRDUDE_DEVICE) -c $(PROGRAMMER) -P $(PORT) -U flash:w:$(TARGET).hex -U eeprom:w:$(TARGET).eep -B 40
memory-used:$(TARGET).elf
avr-size --mcu=$(MCU) -C $(TARGET).elf
# avr-nm -S $(OBJ)