-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
62 lines (43 loc) · 1.4 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
TARGET=s0-counter
MCU=atmega328p
SOURCES=main.c uart.c fifo.c timer.c log.c proto.c i2c.c s0.c mem.c fram.c prefs.c
F_CPU=8000000
PROGRAMMER=stk500v2
PORT=-P/dev/ttyUSB0
BAUD=-B500kHz
CFLAGS=-flto -Os -Wall -Werror -std=c11 -fshort-enums -g2 -gdwarf -c -DF_CPU=$(F_CPU)UL -Wno-unused-function
LDFLAGS=-flto -Os -Wl,-Map,$(BINDIR)/$(TARGET).map -Wl,--section-start=.fram=0x860000
RM=rm
CC=avr-gcc
OBJCOPY=avr-objcopy
SIZE=avr-size
AVRDUDE=avrdude
SRCDIR=src
BINDIR=bin
DEPDIR=.d
OBJECTS=$(addprefix $(BINDIR)/, $(SOURCES:.c=.o))
DEPS=$(addprefix $(DEPDIR)/, $(SOURCES:.c=.d))
DEPFLAGS=-MT $@ -MMD -MP -MF $(DEPDIR)/$*.d
DOXYGEN=doxygen
DOCDIR=doc
.PHONY: all size program doc clean
all: $(BINDIR)/$(TARGET).hex $(BINDIR)/$(TARGET).eep size
$(BINDIR)/$(TARGET).hex: $(BINDIR)/$(TARGET).elf
$(OBJCOPY) -O ihex -j .data -j .text $< $@
$(BINDIR)/$(TARGET).eep: $(BINDIR)/$(TARGET).elf
$(OBJCOPY) -O ihex -j .eeprom --change-section-lma .eeprom=1 $< $@
$(BINDIR)/$(TARGET).elf: $(OBJECTS)
$(CC) $(LDFLAGS) -mmcu=$(MCU) $(OBJECTS) -o $@
$(BINDIR)/%.o: $(SRCDIR)/%.c
$(CC) -c $(CFLAGS) $(DEPFLAGS) -mmcu=$(MCU) -o $@ $<
size: $(BINDIR)/$(TARGET).elf
$(SIZE) --mcu=$(MCU) -C $<
program: $(BINDIR)/$(TARGET).hex
$(AVRDUDE) -p $(MCU) $(PORT) $(BAUD) -c $(PROGRAMMER) -U flash:w:$<
doc:
$(DOXYGEN) $(DOCDIR)/Doxyfile
clean:
$(RM) -rf $(BINDIR)/*
$(RM) -rf $(DEPDIR)/*
$(RM) -rf $(DOCDIR)/doxygen
-include $(DEPS)