forked from WiseLord/oledfm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
78 lines (61 loc) · 1.7 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
# Output file name
TARG = oledfm
# MCU name and frequency
MCU = atmega328p
F_CPU = 16000000
# Source files
SRCS = main.c
SRCS += $(wildcard font*.c) icons.c
SRCS += ssd1306.c glcd.c
SRCS += screen.c
SRCS += i2c.c
SRCS += input.c
SRCS += tuner/tuner.c
SRCS += tuner/rda580x.c
#SRCS += tuner/si470x.c
SRCS += tuner/rds.c
DEFINES += -D_RDA580X -D_RDS
#DEFINES += -D_SI470X -D_RDS
# Build directory
BUILDDIR = build
# Compiler options
OPTIMIZE = -Os -mcall-prologues -fshort-enums -ffunction-sections -fdata-sections
DEBUG = -g -Wall -Werror
DEPS = -MMD -MP -MT $(BUILDDIR)/$(*F).o -MF $(BUILDDIR)/$(*D)/$(*F).d
CFLAGS = $(DEBUG) -lm $(OPTIMIZE) $(DEPS) -mmcu=$(MCU) -DF_CPU=$(F_CPU)
LDFLAGS = $(DEBUG) -mmcu=$(MCU) -Wl,-gc-sections -mrelax
# AVR toolchain and flasher
CC = avr-gcc
OBJCOPY = avr-objcopy
OBJDUMP = avr-objdump
# AVRDude parameters
AVRDUDE = avrdude
AD_MCU = -p $(MCU)
#AD_PROG = -c stk500v2
#AD_PORT = -P avrdoper
AD_CMD = $(AD_MCU) $(AD_PROG) $(AD_PORT) -V
# Build objects
OBJS = $(addprefix $(BUILDDIR)/, $(SRCS:.c=.o))
ELF = $(BUILDDIR)/$(TARG).elf
all: $(ELF) size
# Dependencies
-include $(OBJS:.o=.d)
$(ELF): $(OBJS)
@mkdir -p $(BUILDDIR) flash
$(CC) $(LDFLAGS) -o $(ELF) $(OBJS) -lm
$(OBJCOPY) -O ihex -R .eeprom -R .nwram $(ELF) flash/$(TARG).hex
$(OBJDUMP) -h -S $(ELF) > $(BUILDDIR)/$(TARG).lss
size:
@sh ./size.sh $(ELF)
$(BUILDDIR)/%.o: %.c
@mkdir -p $(dir $@)
$(CC) $(CFLAGS) $(DEFINES) -c -o $@ $<
.PHONY: clean
clean:
rm -rf $(BUILDDIR)
.PHONY: flash
flash: $(ELF)
$(AVRDUDE) $(AD_CMD) -U flash:w:flash/$(TARG).hex:i
.PHONY: fuse
fuse:
$(AVRDUDE) $(AD_CMD) -U lfuse:w:0xff:m -U hfuse:w:0xd1:m -U efuse:w:0xFF:m